|
9 | 9 | #include <fnmatch.h> |
10 | 10 | #include "cache.h" |
11 | 11 | #include "quote.h" |
| 12 | +#include "blob.h" |
12 | 13 |
|
13 | 14 | // --check turns on checking that the working tree matches the |
14 | 15 | // files that are being modified, but doesn't apply the patch |
@@ -924,8 +925,7 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc |
924 | 925 | struct fragment *fragment; |
925 | 926 | int len; |
926 | 927 |
|
927 | | - fragment = xmalloc(sizeof(*fragment)); |
928 | | - memset(fragment, 0, sizeof(*fragment)); |
| 928 | + fragment = xcalloc(1, sizeof(*fragment)); |
929 | 929 | len = parse_fragment(line, size, patch, fragment); |
930 | 930 | if (len <= 0) |
931 | 931 | die("corrupt patch at line %d", linenr); |
@@ -1296,7 +1296,7 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch) |
1296 | 1296 | * applies to. |
1297 | 1297 | */ |
1298 | 1298 | write_sha1_file_prepare(desc->buffer, desc->size, |
1299 | | - "blob", sha1, hdr, &hdrlen); |
| 1299 | + blob_type, sha1, hdr, &hdrlen); |
1300 | 1300 | if (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix)) |
1301 | 1301 | return error("the patch applies to '%s' (%s), " |
1302 | 1302 | "which does not match the " |
@@ -1651,15 +1651,14 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned |
1651 | 1651 | if (!write_index) |
1652 | 1652 | return; |
1653 | 1653 |
|
1654 | | - ce = xmalloc(ce_size); |
1655 | | - memset(ce, 0, ce_size); |
| 1654 | + ce = xcalloc(1, ce_size); |
1656 | 1655 | memcpy(ce->name, path, namelen); |
1657 | 1656 | ce->ce_mode = create_ce_mode(mode); |
1658 | 1657 | ce->ce_flags = htons(namelen); |
1659 | 1658 | if (lstat(path, &st) < 0) |
1660 | 1659 | die("unable to stat newly created file %s", path); |
1661 | 1660 | fill_stat_cache_info(ce, &st); |
1662 | | - if (write_sha1_file(buf, size, "blob", ce->sha1) < 0) |
| 1661 | + if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0) |
1663 | 1662 | die("unable to create backing store for newly created file %s", path); |
1664 | 1663 | if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) |
1665 | 1664 | die("unable to add cache entry for %s", path); |
@@ -1808,8 +1807,7 @@ static int apply_patch(int fd, const char *filename) |
1808 | 1807 | struct patch *patch; |
1809 | 1808 | int nr; |
1810 | 1809 |
|
1811 | | - patch = xmalloc(sizeof(*patch)); |
1812 | | - memset(patch, 0, sizeof(*patch)); |
| 1810 | + patch = xcalloc(1, sizeof(*patch)); |
1813 | 1811 | nr = parse_chunk(buffer + offset, size, patch); |
1814 | 1812 | if (nr < 0) |
1815 | 1813 | break; |
|
0 commit comments