]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff.c: use diff_free_queue()
authorSZEDER Gábor <szeder.dev@gmail.com>
Wed, 2 Nov 2022 22:01:42 +0000 (23:01 +0100)
committerTaylor Blau <me@ttaylorr.com>
Thu, 3 Nov 2022 00:16:34 +0000 (20:16 -0400)
Use diff_free_queue() instead of open-coding it.  This shortens the
code and make it less repetitive.

Note that the second hunk in diff_flush() is interesting, because the
'free_queue' label separates the loop freeing the queue's filepairs
from free()-ing the queue's internal array.  This is somewhat
suspicious, but it was not an issue before: there is only one place
from where we jump to this label with a goto, and that is protected by
an 'if (!q->nr && ...)' condition, i.e. we only skipped the loop
freeing the filepairs when there were no filepairs in the queue to
begin with.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
diff.c

diff --git a/diff.c b/diff.c
index ef94175163d19b467856430e266bca9db42dfcdc..03e6ffb5e4eceb7ee98787381afcf33e5eae1482 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -6337,13 +6337,9 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
 int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
 {
        struct diff_queue_struct *q = &diff_queued_diff;
-       int i;
        int result = diff_get_patch_id(options, oid, diff_header_only);
 
-       for (i = 0; i < q->nr; i++)
-               diff_free_filepair(q->queue[i]);
-
-       free(q->queue);
+       diff_free_queue(q);
        DIFF_QUEUE_CLEAR(q);
 
        return result;
@@ -6612,10 +6608,8 @@ void diff_flush(struct diff_options *options)
        if (output_format & DIFF_FORMAT_CALLBACK)
                options->format_callback(q, options, options->format_callback_data);
 
-       for (i = 0; i < q->nr; i++)
-               diff_free_filepair(q->queue[i]);
 free_queue:
-       free(q->queue);
+       diff_free_queue(q);
        DIFF_QUEUE_CLEAR(q);
        diff_free(options);