diff options
Diffstat (limited to 'rerere.c')
-rw-r--r-- | rerere.c | 47 |
1 files changed, 24 insertions, 23 deletions
@@ -25,7 +25,7 @@ const char *rerere_path(const char *hex, const char *file) return git_path("rr-cache/%s/%s", hex, file); } -int has_rerere_resolution(const char *hex) +static int has_rerere_resolution(const char *hex) { struct stat st; return !stat(rerere_path(hex, "postimage"), &st); @@ -284,8 +284,10 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_) strbuf_release(sb); if (!io->input.len) return -1; - ep = strchrnul(io->input.buf, '\n'); - if (*ep == '\n') + ep = memchr(io->input.buf, '\n', io->input.len); + if (!ep) + ep = io->input.buf + io->input.len; + else if (*ep == '\n') ep++; len = ep - io->input.buf; strbuf_add(sb, io->input.buf, len); @@ -295,9 +297,9 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_) static int handle_cache(const char *path, unsigned char *sha1, const char *output) { - mmfile_t mmfile[3]; + mmfile_t mmfile[3] = {{NULL}}; mmbuffer_t result = {NULL, 0}; - struct cache_entry *ce; + const struct cache_entry *ce; int pos, len, i, hunk_no; struct rerere_io_mem io; int marker_size = ll_merge_marker_size(path); @@ -314,17 +316,16 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu for (i = 0; i < 3; i++) { enum object_type type; unsigned long size; + int j; - mmfile[i].size = 0; - mmfile[i].ptr = NULL; if (active_nr <= pos) break; ce = active_cache[pos++]; - if (ce_namelen(ce) != len || memcmp(ce->name, path, len) - || ce_stage(ce) != i + 1) - break; - mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size); - mmfile[i].size = size; + if (ce_namelen(ce) != len || memcmp(ce->name, path, len)) + continue; + j = ce_stage(ce) - 1; + mmfile[j].ptr = read_sha1_file(ce->sha1, &type, &size); + mmfile[j].size = size; } for (i = 0; i < 3; i++) { if (!mmfile[i].ptr && !mmfile[i].size) @@ -358,7 +359,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu static int check_one_conflict(int i, int *type) { - struct cache_entry *e = active_cache[i]; + const struct cache_entry *e = active_cache[i]; if (!ce_stage(e)) { *type = RESOLVED; @@ -373,8 +374,8 @@ static int check_one_conflict(int i, int *type) /* Only handle regular files with both stages #2 and #3 */ if (i + 1 < active_nr) { - struct cache_entry *e2 = active_cache[i]; - struct cache_entry *e3 = active_cache[i + 1]; + const struct cache_entry *e2 = active_cache[i]; + const struct cache_entry *e3 = active_cache[i + 1]; if (ce_stage(e2) == 2 && ce_stage(e3) == 3 && ce_same_name(e, e3) && @@ -397,7 +398,7 @@ static int find_conflict(struct string_list *conflict) for (i = 0; i < active_nr;) { int conflict_type; - struct cache_entry *e = active_cache[i]; + const struct cache_entry *e = active_cache[i]; i = check_one_conflict(i, &conflict_type); if (conflict_type == THREE_STAGED) string_list_insert(conflict, (const char *)e->name); @@ -413,7 +414,7 @@ int rerere_remaining(struct string_list *merge_rr) for (i = 0; i < active_nr;) { int conflict_type; - struct cache_entry *e = active_cache[i]; + const struct cache_entry *e = active_cache[i]; i = check_one_conflict(i, &conflict_type); if (conflict_type == PUNTED) string_list_insert(merge_rr, (const char *)e->name); @@ -544,13 +545,13 @@ static int do_plain_rerere(struct string_list *rr, int fd) if (has_rerere_resolution(name)) { if (!merge(name, path)) { - if (rerere_autoupdate) + const char *msg; + if (rerere_autoupdate) { string_list_insert(&update, path); - fprintf(stderr, - "%s '%s' using previous resolution.\n", - rerere_autoupdate - ? "Staged" : "Resolved", - path); + msg = "Staged '%s' using previous resolution.\n"; + } else + msg = "Resolved '%s' using previous resolution.\n"; + fprintf(stderr, msg, path); goto mark_resolved; } } |