Skip to content

Commit 8e27c90

Browse files
committed
squash! built-in add -i: allow filtering the modified files list
built-in add -i: allow filtering the modified files list In the `update` command of `git add -i`, we are primarily interested in the list of modified files that have worktree (i.e. unstaged) changes. At the same time, we need to determine _also_ the staged changes, to be able to produce the full added/deleted information. The Perl script version of `git add -i` has a parameter of the `list_modified()` function for that matter. In C, we can be a lot more precise, using an `enum`. The C implementation of the filter also has an easier time to avoid unnecessary work, simply by using an adaptive order of the `diff-index` and `diff-files` phases, and then skipping files in the second phase when they have not been seen in the first phase. Seeing as we change the meaning of the `phase` field, we rename it to `mode` to reflect that the order depends on the exact invocation of the `git add -i` command. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8715ee2 commit 8e27c90

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

add-interactive.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static int pathname_entry_cmp(const void *unused_cmp_data,
427427
}
428428

429429
struct collection_status {
430-
enum { FROM_WORKTREE = 0, FROM_INDEX = 1 } phase;
430+
enum { FROM_WORKTREE = 0, FROM_INDEX = 1 } mode;
431431

432432
const char *reference;
433433

@@ -473,7 +473,7 @@ static void collect_changes_cb(struct diff_queue_struct *q,
473473
}
474474

475475
file_item = entry->item;
476-
adddel = s->phase == FROM_INDEX ?
476+
adddel = s->mode == FROM_INDEX ?
477477
&file_item->index : &file_item->worktree;
478478
other_adddel = s->phase == FROM_INDEX ?
479479
&file_item->worktree : &file_item->index;
@@ -526,9 +526,9 @@ static int get_modified_files(struct repository *r,
526526
struct setup_revision_opt opt = { 0 };
527527

528528
if (filter == INDEX_ONLY)
529-
s.phase = i ? FROM_WORKTREE : FROM_INDEX;
529+
s.mode = (i == 0) ? FROM_INDEX : FROM_WORKTREE;
530530
else
531-
s.phase = i ? FROM_INDEX : FROM_WORKTREE;
531+
s.mode = (i == 0) ? FROM_WORKTREE : FROM_INDEX;
532532
s.skip_unseen = filter && i;
533533

534534
opt.def = is_initial ?
@@ -544,7 +544,7 @@ static int get_modified_files(struct repository *r,
544544
if (ps)
545545
copy_pathspec(&rev.prune_data, ps);
546546

547-
if (s.phase == FROM_INDEX)
547+
if (s.mode == FROM_INDEX)
548548
run_diff_index(&rev, 1);
549549
else {
550550
rev.diffopt.flags.ignore_dirty_submodules = 1;

0 commit comments

Comments
 (0)