Skip to content

Commit 06bca97

Browse files
committed
Merge branch 'ab/retire-scripted-add-p'
Finally retire the scripted "git add -p/-i" implementation and have everybody use the one reimplemented in C. * ab/retire-scripted-add-p: docs & comments: replace mentions of "git-add--interactive.perl" add API: remove run_add_interactive() wrapper function add: remove "add.interactive.useBuiltin" & Perl "git add--interactive"
2 parents c5f7b2a + 5a7d41d commit 06bca97

19 files changed

+50
-2023
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
/bin-wrappers/
1515
/git
1616
/git-add
17-
/git-add--interactive
1817
/git-am
1918
/git-annotate
2019
/git-apply

Documentation/config/add.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add.ignore-errors (deprecated)::
77
variables.
88

99
add.interactive.useBuiltin::
10-
Set to `false` to fall back to the original Perl implementation of
11-
the interactive version of linkgit:git-add[1] instead of the built-in
12-
version. Is `true` by default.
10+
Unused configuration variable. Used in Git versions v2.25.0 to
11+
v2.36.0 to enable the built-in version of linkgit:git-add[1]'s
12+
interactive mode, which then became the default in Git
13+
versions v2.37.0 to v2.39.0.

Documentation/git-add.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ status::
274274
------------
275275
staged unstaged path
276276
1: binary nothing foo.png
277-
2: +403/-35 +1/-1 git-add--interactive.perl
277+
2: +403/-35 +1/-1 add-interactive.c
278278
------------
279279
+
280280
It shows that foo.png has differences from HEAD (but that is
281281
binary so line count cannot be shown) and there is no
282282
difference between indexed copy and the working tree
283283
version (if the working tree version were also different,
284284
'binary' would have been shown in place of 'nothing'). The
285-
other file, git-add{litdd}interactive.perl, has 403 lines added
285+
other file, add-interactive.c, has 403 lines added
286286
and 35 lines deleted if you commit what is in the index, but
287287
working tree file has further modifications (one addition and
288288
one deletion).
@@ -303,7 +303,7 @@ like this:
303303
------------
304304
staged unstaged path
305305
1: binary nothing foo.png
306-
* 2: +403/-35 +1/-1 git-add--interactive.perl
306+
* 2: +403/-35 +1/-1 add-interactive.c
307307
------------
308308
+
309309
To remove selection, prefix the input with `-`

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Issues of note:
120120
for everyday use (e.g. "bisect", "request-pull").
121121

122122
- "Perl" version 5.8 or later is needed to use some of the
123-
features (e.g. preparing a partial commit using "git add -i/-p",
123+
features (e.g. sending patches using "git send-email",
124124
interacting with svn repositories with "git svn"). If you can
125125
live without these, use NO_PERL. Note that recent releases of
126126
Redhat/Fedora are reported to ship Perl binary package with some

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ SCRIPT_LIB += git-mergetool--lib
708708
SCRIPT_LIB += git-sh-i18n
709709
SCRIPT_LIB += git-sh-setup
710710

711-
SCRIPT_PERL += git-add--interactive.perl
712711
SCRIPT_PERL += git-archimport.perl
713712
SCRIPT_PERL += git-cvsexportcommit.perl
714713
SCRIPT_PERL += git-cvsimport.perl

builtin/add.c

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -238,68 +238,25 @@ static int refresh(int verbose, const struct pathspec *pathspec)
238238
return ret;
239239
}
240240

241-
int run_add_interactive(const char *revision, const char *patch_mode,
242-
const struct pathspec *pathspec)
243-
{
244-
int i;
245-
struct child_process cmd = CHILD_PROCESS_INIT;
246-
int use_builtin_add_i =
247-
git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
248-
249-
if (use_builtin_add_i < 0 &&
250-
git_config_get_bool("add.interactive.usebuiltin",
251-
&use_builtin_add_i))
252-
use_builtin_add_i = 1;
253-
254-
if (use_builtin_add_i != 0) {
255-
enum add_p_mode mode;
256-
257-
if (!patch_mode)
258-
return !!run_add_i(the_repository, pathspec);
259-
260-
if (!strcmp(patch_mode, "--patch"))
261-
mode = ADD_P_ADD;
262-
else if (!strcmp(patch_mode, "--patch=stash"))
263-
mode = ADD_P_STASH;
264-
else if (!strcmp(patch_mode, "--patch=reset"))
265-
mode = ADD_P_RESET;
266-
else if (!strcmp(patch_mode, "--patch=checkout"))
267-
mode = ADD_P_CHECKOUT;
268-
else if (!strcmp(patch_mode, "--patch=worktree"))
269-
mode = ADD_P_WORKTREE;
270-
else
271-
die("'%s' not supported", patch_mode);
272-
273-
return !!run_add_p(the_repository, mode, revision, pathspec);
274-
}
275-
276-
strvec_push(&cmd.args, "add--interactive");
277-
if (patch_mode)
278-
strvec_push(&cmd.args, patch_mode);
279-
if (revision)
280-
strvec_push(&cmd.args, revision);
281-
strvec_push(&cmd.args, "--");
282-
for (i = 0; i < pathspec->nr; i++)
283-
/* pass original pathspec, to be re-parsed */
284-
strvec_push(&cmd.args, pathspec->items[i].original);
285-
286-
cmd.git_cmd = 1;
287-
return run_command(&cmd);
288-
}
289-
290241
int interactive_add(const char **argv, const char *prefix, int patch)
291242
{
292243
struct pathspec pathspec;
244+
int unused;
245+
246+
if (!git_config_get_bool("add.interactive.usebuiltin", &unused))
247+
warning(_("the add.interactive.useBuiltin setting has been removed!\n"
248+
"See its entry in 'git help config' for details."));
293249

294250
parse_pathspec(&pathspec, 0,
295251
PATHSPEC_PREFER_FULL |
296252
PATHSPEC_SYMLINK_LEADING_PATH |
297253
PATHSPEC_PREFIX_ORIGIN,
298254
prefix, argv);
299255

300-
return run_add_interactive(NULL,
301-
patch ? "--patch" : NULL,
302-
&pathspec);
256+
if (patch)
257+
return !!run_add_p(the_repository, ADD_P_ADD, NULL, &pathspec);
258+
else
259+
return !!run_add_i(the_repository, &pathspec);
303260
}
304261

305262
static int edit_patch(int argc, const char **argv, const char *prefix)

builtin/checkout.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "xdiff-interface.h"
3030
#include "entry.h"
3131
#include "parallel-checkout.h"
32+
#include "add-interactive.h"
3233

3334
static const char * const checkout_usage[] = {
3435
N_("git checkout [<options>] <branch>"),
@@ -499,7 +500,7 @@ static int checkout_paths(const struct checkout_opts *opts,
499500
"--merge", "--conflict", "--staged");
500501

501502
if (opts->patch_mode) {
502-
const char *patch_mode;
503+
enum add_p_mode patch_mode;
503504
const char *rev = new_branch_info->name;
504505
char rev_oid[GIT_MAX_HEXSZ + 1];
505506

@@ -517,15 +518,16 @@ static int checkout_paths(const struct checkout_opts *opts,
517518
rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
518519

519520
if (opts->checkout_index && opts->checkout_worktree)
520-
patch_mode = "--patch=checkout";
521+
patch_mode = ADD_P_CHECKOUT;
521522
else if (opts->checkout_index && !opts->checkout_worktree)
522-
patch_mode = "--patch=reset";
523+
patch_mode = ADD_P_RESET;
523524
else if (!opts->checkout_index && opts->checkout_worktree)
524-
patch_mode = "--patch=worktree";
525+
patch_mode = ADD_P_WORKTREE;
525526
else
526527
BUG("either flag must have been set, worktree=%d, index=%d",
527528
opts->checkout_worktree, opts->checkout_index);
528-
return run_add_interactive(rev, patch_mode, &opts->pathspec);
529+
return !!run_add_p(the_repository, patch_mode, rev,
530+
&opts->pathspec);
529531
}
530532

531533
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);

builtin/clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ static int parse_choice(struct menu_stuff *menu_stuff,
560560

561561
/*
562562
* Implement a git-add-interactive compatible UI, which is borrowed
563-
* from git-add--interactive.perl.
563+
* from add-interactive.c.
564564
*
565565
* Return value:
566566
*

builtin/reset.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "submodule.h"
2727
#include "submodule-config.h"
2828
#include "dir.h"
29+
#include "add-interactive.h"
2930

3031
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
3132

@@ -390,7 +391,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
390391
if (reset_type != NONE)
391392
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
392393
trace2_cmd_mode("patch-interactive");
393-
return run_add_interactive(rev, "--patch=reset", &pathspec);
394+
return !!run_add_p(the_repository, ADD_P_RESET, rev,
395+
&pathspec);
394396
}
395397

396398
/* git reset tree [--] paths... can be used to

builtin/stash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "diffcore.h"
1919
#include "exec-cmd.h"
2020
#include "reflog.h"
21+
#include "add-interactive.h"
2122

2223
#define INCLUDE_ALL_FILES 2
2324

@@ -1229,7 +1230,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
12291230
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
12301231
setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
12311232

1232-
ret = run_add_interactive(NULL, "--patch=stash", ps);
1233+
ret = !!run_add_p(the_repository, ADD_P_STASH, NULL, ps);
12331234

12341235
the_repository->index_file = old_repo_index_file;
12351236
if (old_index_env && *old_index_env)

0 commit comments

Comments
 (0)