diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-09-13 11:38:23 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-09-13 11:38:23 -0700 |
| commit | e0574c4fd1ee903409db010fcac7c1ab8f3891c9 (patch) | |
| tree | bc3b03084579acd80e8345651e5ce4ffc542debd | |
| parent | f322e9f51b5a2ca303a6691d0e2d1f3f754923ff (diff) | |
| parent | 2b43dd0eb5f3f035b9bd9d019ec405dd55ec15e1 (diff) | |
| download | git-e0574c4fd1ee903409db010fcac7c1ab8f3891c9.tar.xz | |
Merge branch 'rs/diff-no-index-cleanup'
"git diff --no-index A B" managed its the pathnames of its two
input files rather haphazardly, sometimes leaking them. The
command line argument processing has been straightened out to clean
it up.
* rs/diff-no-index-cleanup:
diff-no-index: simplify argv index calculation
diff-no-index: release prefixed filenames
diff-no-index: release strbuf on queue error
| -rw-r--r-- | diff-no-index.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/diff-no-index.c b/diff-no-index.c index 9a8b09346b..18edbdf4b5 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -243,7 +243,9 @@ int diff_no_index(struct rev_info *revs, int argc, const char **argv) { int i, no_index; + int ret = 1; const char *paths[2]; + char *to_free[ARRAY_SIZE(paths)] = { 0 }; struct strbuf replacement = STRBUF_INIT; const char *prefix = revs->prefix; struct option no_index_options[] = { @@ -265,7 +267,7 @@ int diff_no_index(struct rev_info *revs, } FREE_AND_NULL(options); for (i = 0; i < 2; i++) { - const char *p = argv[argc - 2 + i]; + const char *p = argv[i]; if (!strcmp(p, "-")) /* * stdin should be spelled as "-"; if you have @@ -273,7 +275,7 @@ int diff_no_index(struct rev_info *revs, */ p = file_from_standard_input; else if (prefix) - p = prefix_filename(prefix, p); + p = to_free[i] = prefix_filename(prefix, p); paths[i] = p; } @@ -295,16 +297,20 @@ int diff_no_index(struct rev_info *revs, revs->diffopt.flags.exit_with_status = 1; if (queue_diff(&revs->diffopt, paths[0], paths[1])) - return 1; + goto out; diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/"); diffcore_std(&revs->diffopt); diff_flush(&revs->diffopt); - strbuf_release(&replacement); - /* * The return code for --no-index imitates diff(1): * 0 = no changes, 1 = changes, else error */ - return diff_result_code(&revs->diffopt, 0); + ret = diff_result_code(&revs->diffopt, 0); + +out: + for (i = 0; i < ARRAY_SIZE(to_free); i++) + free(to_free[i]); + strbuf_release(&replacement); + return ret; } |
