Skip to content

Commit 7c67d2a

Browse files
jltoblergitster
authored andcommitted
diff: return diff_filepair from diff queue helpers
The `diff_addremove()` and `diff_change()` functions set up and queue diffs, but do not return the `diff_filepair` added to the queue. In a subsequent commit, modifications to `diff_filepair` need to occur in certain cases after being queued. Since the existing `diff_addremove()` and `diff_change()` are also used for callbacks in `diff_options` as types `add_remove_fn_t` and `change_fn_t`, modifying the existing function signatures requires further changes. The diff options for pruning use `file_add_remove()` and `file_change()` where file pairs do not even get queued. Thus, separate functions are implemented instead. Split out the queuing operations into `diff_queue_addremove()` and `diff_queue_change()` which also return a handle to the queued `diff_filepair`. Both `diff_addremove()` and `diff_change()` are reimplemented as thin wrappers around the new functions. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08bdfd4 commit 7c67d2a

File tree

2 files changed

+75
-20
lines changed

2 files changed

+75
-20
lines changed

diff.c

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7161,16 +7161,19 @@ void compute_diffstat(struct diff_options *options,
71617161
options->found_changes = !!diffstat->nr;
71627162
}
71637163

7164-
void diff_addremove(struct diff_options *options,
7165-
int addremove, unsigned mode,
7166-
const struct object_id *oid,
7167-
int oid_valid,
7168-
const char *concatpath, unsigned dirty_submodule)
7164+
struct diff_filepair *diff_queue_addremove(struct diff_queue_struct *queue,
7165+
struct diff_options *options,
7166+
int addremove, unsigned mode,
7167+
const struct object_id *oid,
7168+
int oid_valid,
7169+
const char *concatpath,
7170+
unsigned dirty_submodule)
71697171
{
71707172
struct diff_filespec *one, *two;
7173+
struct diff_filepair *pair;
71717174

71727175
if (S_ISGITLINK(mode) && is_submodule_ignored(concatpath, options))
7173-
return;
7176+
return NULL;
71747177

71757178
/* This may look odd, but it is a preparation for
71767179
* feeding "there are unchanged files which should
@@ -7190,7 +7193,7 @@ void diff_addremove(struct diff_options *options,
71907193

71917194
if (options->prefix &&
71927195
strncmp(concatpath, options->prefix, options->prefix_length))
7193-
return;
7196+
return NULL;
71947197

71957198
one = alloc_filespec(concatpath);
71967199
two = alloc_filespec(concatpath);
@@ -7202,25 +7205,29 @@ void diff_addremove(struct diff_options *options,
72027205
two->dirty_submodule = dirty_submodule;
72037206
}
72047207

7205-
diff_queue(&diff_queued_diff, one, two);
7208+
pair = diff_queue(queue, one, two);
72067209
if (!options->flags.diff_from_contents)
72077210
options->flags.has_changes = 1;
7211+
7212+
return pair;
72087213
}
72097214

7210-
void diff_change(struct diff_options *options,
7211-
unsigned old_mode, unsigned new_mode,
7212-
const struct object_id *old_oid,
7213-
const struct object_id *new_oid,
7214-
int old_oid_valid, int new_oid_valid,
7215-
const char *concatpath,
7216-
unsigned old_dirty_submodule, unsigned new_dirty_submodule)
7215+
struct diff_filepair *diff_queue_change(struct diff_queue_struct *queue,
7216+
struct diff_options *options,
7217+
unsigned old_mode, unsigned new_mode,
7218+
const struct object_id *old_oid,
7219+
const struct object_id *new_oid,
7220+
int old_oid_valid, int new_oid_valid,
7221+
const char *concatpath,
7222+
unsigned old_dirty_submodule,
7223+
unsigned new_dirty_submodule)
72177224
{
72187225
struct diff_filespec *one, *two;
72197226
struct diff_filepair *p;
72207227

72217228
if (S_ISGITLINK(old_mode) && S_ISGITLINK(new_mode) &&
72227229
is_submodule_ignored(concatpath, options))
7223-
return;
7230+
return NULL;
72247231

72257232
if (options->flags.reverse_diff) {
72267233
SWAP(old_mode, new_mode);
@@ -7231,27 +7238,50 @@ void diff_change(struct diff_options *options,
72317238

72327239
if (options->prefix &&
72337240
strncmp(concatpath, options->prefix, options->prefix_length))
7234-
return;
7241+
return NULL;
72357242

72367243
one = alloc_filespec(concatpath);
72377244
two = alloc_filespec(concatpath);
72387245
fill_filespec(one, old_oid, old_oid_valid, old_mode);
72397246
fill_filespec(two, new_oid, new_oid_valid, new_mode);
72407247
one->dirty_submodule = old_dirty_submodule;
72417248
two->dirty_submodule = new_dirty_submodule;
7242-
p = diff_queue(&diff_queued_diff, one, two);
7249+
p = diff_queue(queue, one, two);
72437250

72447251
if (options->flags.diff_from_contents)
7245-
return;
7252+
return p;
72467253

72477254
if (options->flags.quick && options->skip_stat_unmatch &&
72487255
!diff_filespec_check_stat_unmatch(options->repo, p)) {
72497256
diff_free_filespec_data(p->one);
72507257
diff_free_filespec_data(p->two);
7251-
return;
7258+
return p;
72527259
}
72537260

72547261
options->flags.has_changes = 1;
7262+
7263+
return p;
7264+
}
7265+
7266+
void diff_addremove(struct diff_options *options, int addremove, unsigned mode,
7267+
const struct object_id *oid, int oid_valid,
7268+
const char *concatpath, unsigned dirty_submodule)
7269+
{
7270+
diff_queue_addremove(&diff_queued_diff, options, addremove, mode, oid,
7271+
oid_valid, concatpath, dirty_submodule);
7272+
}
7273+
7274+
void diff_change(struct diff_options *options,
7275+
unsigned old_mode, unsigned new_mode,
7276+
const struct object_id *old_oid,
7277+
const struct object_id *new_oid,
7278+
int old_oid_valid, int new_oid_valid,
7279+
const char *concatpath,
7280+
unsigned old_dirty_submodule, unsigned new_dirty_submodule)
7281+
{
7282+
diff_queue_change(&diff_queued_diff, options, old_mode, new_mode,
7283+
old_oid, new_oid, old_oid_valid, new_oid_valid,
7284+
concatpath, old_dirty_submodule, new_dirty_submodule);
72557285
}
72567286

72577287
struct diff_filepair *diff_unmerge(struct diff_options *options, const char *path)

diff.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,31 @@ void diff_set_default_prefix(struct diff_options *options);
508508

509509
int diff_can_quit_early(struct diff_options *);
510510

511+
/*
512+
* Stages changes in the provided diff queue for file additions and deletions.
513+
* If a file pair gets queued, it is returned.
514+
*/
515+
struct diff_filepair *diff_queue_addremove(struct diff_queue_struct *queue,
516+
struct diff_options *,
517+
int addremove, unsigned mode,
518+
const struct object_id *oid,
519+
int oid_valid, const char *fullpath,
520+
unsigned dirty_submodule);
521+
522+
/*
523+
* Stages changes in the provided diff queue for file modifications.
524+
* If a file pair gets queued, it is returned.
525+
*/
526+
struct diff_filepair *diff_queue_change(struct diff_queue_struct *queue,
527+
struct diff_options *,
528+
unsigned mode1, unsigned mode2,
529+
const struct object_id *old_oid,
530+
const struct object_id *new_oid,
531+
int old_oid_valid, int new_oid_valid,
532+
const char *fullpath,
533+
unsigned dirty_submodule1,
534+
unsigned dirty_submodule2);
535+
511536
void diff_addremove(struct diff_options *,
512537
int addremove,
513538
unsigned mode,

0 commit comments

Comments
 (0)