Add a macro DIFF_QUEUE_CLEAR.
Refactor the diff_queue_struct code, this macro help to reset the structure. Signed-off-by: Bo Yang <struggleyb.nku@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Bo Yang committed
May 6, 2010 at 21:52 UTC
9ca5df90615aa3c6b60e1bc8f03db6cae98e816c
5 files changed
+14
-16
diff.c
+5
-8
@@ -2540,6 +2540,7 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
2540
void diff_setup(struct diff_options *options)
2541
{
2542
memset(options, 0, sizeof(*options));
2543
+ memset(&diff_queued_diff, 0, sizeof(diff_queued_diff));
2544
2545
options->file = stdout;
2546
@@ -3457,8 +3458,7 @@ int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
3458
diff_free_filepair(q->queue[i]);
3459
3460
free(q->queue);
3460
- q->queue = NULL;
3461
- q->nr = q->alloc = 0;
3461
+ DIFF_QUEUE_CLEAR(q);
3462
3463
return result;
3464
}
@@ -3586,8 +3586,7 @@ void diff_flush(struct diff_options *options)
3586
diff_free_filepair(q->queue[i]);
3587
free_queue:
3588
free(q->queue);
3589
- q->queue = NULL;
3590
- q->nr = q->alloc = 0;
3589
+ DIFF_QUEUE_CLEAR(q);
3590
if (options->close_file)
3591
fclose(options->file);
3592
@@ -3609,8 +3608,7 @@ static void diffcore_apply_filter(const char *filter)
3608
int i;
3609
struct diff_queue_struct *q = &diff_queued_diff;
3610
struct diff_queue_struct outq;
3612
- outq.queue = NULL;
3613
- outq.nr = outq.alloc = 0;
3611
+ DIFF_QUEUE_CLEAR(&outq);
3612
3613
if (!filter)
3614
return;
@@ -3678,8 +3676,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
3676
int i;
3677
struct diff_queue_struct *q = &diff_queued_diff;
3678
struct diff_queue_struct outq;
3681
- outq.queue = NULL;
3682
- outq.nr = outq.alloc = 0;
3679
+ DIFF_QUEUE_CLEAR(&outq);
3680
3681
for (i = 0; i < q->nr; i++) {
3682
struct diff_filepair *p = q->queue[i];
diffcore-break.c
+2
-4
@@ -162,8 +162,7 @@ void diffcore_break(int break_score)
162
if (!merge_score)
163
merge_score = DEFAULT_MERGE_SCORE;
164
165
- outq.nr = outq.alloc = 0;
166
- outq.queue = NULL;
165
+ DIFF_QUEUE_CLEAR(&outq);
166
167
for (i = 0; i < q->nr; i++) {
168
struct diff_filepair *p = q->queue[i];
@@ -256,8 +255,7 @@ void diffcore_merge_broken(void)
255
struct diff_queue_struct outq;
256
int i, j;
257
259
- outq.nr = outq.alloc = 0;
260
- outq.queue = NULL;
258
+ DIFF_QUEUE_CLEAR(&outq);
259
260
for (i = 0; i < q->nr; i++) {
261
struct diff_filepair *p = q->queue[i];
diffcore-pickaxe.c
+1
-2
@@ -55,8 +55,7 @@ void diffcore_pickaxe(const char *needle, int opts)
55
int i, has_changes;
56
regex_t regex, *regexp = NULL;
57
struct diff_queue_struct outq;
58
- outq.queue = NULL;
59
- outq.nr = outq.alloc = 0;
58
+ DIFF_QUEUE_CLEAR(&outq);
59
60
if (opts & DIFF_PICKAXE_REGEX) {
61
int err;
diffcore-rename.c
+1
-2
@@ -569,8 +569,7 @@ void diffcore_rename(struct diff_options *options)
569
/* At this point, we have found some renames and copies and they
570
* are recorded in rename_dst. The original list is still in *q.
571
*/
572
- outq.queue = NULL;
573
- outq.nr = outq.alloc = 0;
572
+ DIFF_QUEUE_CLEAR(&outq);
573
for (i = 0; i < q->nr; i++) {
574
struct diff_filepair *p = q->queue[i];
575
struct diff_filepair *pair_to_free = NULL;
diffcore.h
+5
@@ -92,6 +92,11 @@ struct diff_queue_struct {
92
int alloc;
93
int nr;
94
};
95
+#define DIFF_QUEUE_CLEAR(q) \
96
+ do { \
97
+ (q)->queue = NULL; \
98
+ (q)->nr = (q)->alloc = 0; \
99
+ } while(0);
100
101
extern struct diff_queue_struct diff_queued_diff;
102
extern struct diff_filepair *diff_queue(struct diff_queue_struct *,