X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=diff.c;h=3dc0ca0a0334b2ed5492d67d759c4bffad5cd404;hb=b5cf3c8b7767e5f2c8b0df718ef91ccfc36c61fe;hp=527cbf04adf86fe6fc4c449971ac177d63736330;hpb=706df00d6864201bdb90a2f3b26443a65ae538ff;p=git.git diff --git a/diff.c b/diff.c index 527cbf04..3dc0ca0a 100644 --- a/diff.c +++ b/diff.c @@ -32,10 +32,10 @@ static const char *external_diff(void) * * GIT_DIFF_OPTS="-c"; */ - external_diff_cmd = gitenv("GIT_EXTERNAL_DIFF"); + external_diff_cmd = getenv("GIT_EXTERNAL_DIFF"); /* In case external diff fails... */ - env_diff_opts = gitenv("GIT_DIFF_OPTS"); + env_diff_opts = getenv("GIT_DIFF_OPTS"); if (env_diff_opts) diff_opts = env_diff_opts; done_preparing = 1; @@ -214,14 +214,10 @@ struct diff_filespec *alloc_filespec(const char *path) { int namelen = strlen(path); struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1); + + memset(spec, 0, sizeof(*spec)); spec->path = (char *)(spec + 1); - strcpy(spec->path, path); - spec->should_free = spec->should_munmap = 0; - spec->xfrm_flags = 0; - spec->size = 0; - spec->data = NULL; - spec->mode = 0; - memset(spec->sha1, 0, 20); + memcpy(spec->path, path, namelen+1); return spec; } @@ -406,13 +402,14 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) return 0; } -void diff_free_filespec(struct diff_filespec *s) +void diff_free_filespec_data(struct diff_filespec *s) { if (s->should_free) free(s->data); else if (s->should_munmap) munmap(s->data, s->size); - free(s); + s->should_free = s->should_munmap = 0; + s->data = NULL; } static void prep_temp_blob(struct diff_tempfile *temp, @@ -765,14 +762,17 @@ struct diff_filepair *diff_queue(struct diff_queue_struct *queue, dp->status = 0; dp->source_stays = 0; dp->broken_pair = 0; - diff_q(queue, dp); + if (queue) + diff_q(queue, dp); return dp; } void diff_free_filepair(struct diff_filepair *p) { - diff_free_filespec(p->one); - diff_free_filespec(p->two); + diff_free_filespec_data(p->one); + diff_free_filespec_data(p->two); + free(p->one); + free(p->two); free(p); } @@ -955,7 +955,9 @@ static void diff_resolve_rename_copy(void) } /* See if there is some other filepair that * copies from the same source as us. If so - * we are a copy. Otherwise we are a rename. + * we are a copy. Otherwise we are either a + * copy if the path stays, or a rename if it + * does not, but we already handled "stays" case. */ for (j = i + 1; j < q->nr; j++) { pp = q->queue[j]; @@ -1150,29 +1152,6 @@ void diff_addremove(int addremove, unsigned mode, diff_queue(&diff_queued_diff, one, two); } -void diff_helper_input(unsigned old_mode, - unsigned new_mode, - const unsigned char *old_sha1, - const unsigned char *new_sha1, - const char *old_path, - int status, - int score, - const char *new_path) -{ - struct diff_filespec *one, *two; - struct diff_filepair *dp; - - one = alloc_filespec(old_path); - two = alloc_filespec(new_path); - if (old_mode) - fill_filespec(one, old_sha1, old_mode); - if (new_mode) - fill_filespec(two, new_sha1, new_mode); - dp = diff_queue(&diff_queued_diff, one, two); - dp->score = score * MAX_SCORE / 100; - dp->status = status; -} - void diff_change(unsigned old_mode, unsigned new_mode, const unsigned char *old_sha1, const unsigned char *new_sha1,