Skip to content

Commit

Permalink
Add a macro DIFF_QUEUE_CLEAR.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
byang authored and gitster committed May 7, 2010
1 parent 3bf7886 commit 9ca5df9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
13 changes: 5 additions & 8 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,7 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
void diff_setup(struct diff_options *options)
{
memset(options, 0, sizeof(*options));
memset(&diff_queued_diff, 0, sizeof(diff_queued_diff));

options->file = stdout;

Expand Down Expand Up @@ -3457,8 +3458,7 @@ int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1)
diff_free_filepair(q->queue[i]);

free(q->queue);
q->queue = NULL;
q->nr = q->alloc = 0;
DIFF_QUEUE_CLEAR(q);

return result;
}
Expand Down Expand Up @@ -3586,8 +3586,7 @@ void diff_flush(struct diff_options *options)
diff_free_filepair(q->queue[i]);
free_queue:
free(q->queue);
q->queue = NULL;
q->nr = q->alloc = 0;
DIFF_QUEUE_CLEAR(q);
if (options->close_file)
fclose(options->file);

Expand All @@ -3609,8 +3608,7 @@ static void diffcore_apply_filter(const char *filter)
int i;
struct diff_queue_struct *q = &diff_queued_diff;
struct diff_queue_struct outq;
outq.queue = NULL;
outq.nr = outq.alloc = 0;
DIFF_QUEUE_CLEAR(&outq);

if (!filter)
return;
Expand Down Expand Up @@ -3678,8 +3676,7 @@ static void diffcore_skip_stat_unmatch(struct diff_options *diffopt)
int i;
struct diff_queue_struct *q = &diff_queued_diff;
struct diff_queue_struct outq;
outq.queue = NULL;
outq.nr = outq.alloc = 0;
DIFF_QUEUE_CLEAR(&outq);

for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
Expand Down
6 changes: 2 additions & 4 deletions diffcore-break.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ void diffcore_break(int break_score)
if (!merge_score)
merge_score = DEFAULT_MERGE_SCORE;

outq.nr = outq.alloc = 0;
outq.queue = NULL;
DIFF_QUEUE_CLEAR(&outq);

for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
Expand Down Expand Up @@ -256,8 +255,7 @@ void diffcore_merge_broken(void)
struct diff_queue_struct outq;
int i, j;

outq.nr = outq.alloc = 0;
outq.queue = NULL;
DIFF_QUEUE_CLEAR(&outq);

for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
Expand Down
3 changes: 1 addition & 2 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ void diffcore_pickaxe(const char *needle, int opts)
int i, has_changes;
regex_t regex, *regexp = NULL;
struct diff_queue_struct outq;
outq.queue = NULL;
outq.nr = outq.alloc = 0;
DIFF_QUEUE_CLEAR(&outq);

if (opts & DIFF_PICKAXE_REGEX) {
int err;
Expand Down
3 changes: 1 addition & 2 deletions diffcore-rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,7 @@ void diffcore_rename(struct diff_options *options)
/* At this point, we have found some renames and copies and they
* are recorded in rename_dst. The original list is still in *q.
*/
outq.queue = NULL;
outq.nr = outq.alloc = 0;
DIFF_QUEUE_CLEAR(&outq);
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
struct diff_filepair *pair_to_free = NULL;
Expand Down
5 changes: 5 additions & 0 deletions diffcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ struct diff_queue_struct {
int alloc;
int nr;
};
#define DIFF_QUEUE_CLEAR(q) \
do { \
(q)->queue = NULL; \
(q)->nr = (q)->alloc = 0; \
} while(0);

extern struct diff_queue_struct diff_queued_diff;
extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
Expand Down

0 comments on commit 9ca5df9

Please sign in to comment.