Skip to content

Commit 480ca64

Browse files
pcloudsgitster
authored andcommitted
convert run_add_interactive to use struct pathspec
This passes the pathspec, more or less unmodified, to git-add--interactive. The command itself does not process pathspec. It simply passes the pathspec to other builtin commands. So if all those commands support pathspec, we're good. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5ab2a2d commit 480ca64

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

builtin/add.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,28 +244,22 @@ static void refresh(int verbose, const char **pathspec)
244244
}
245245

246246
int run_add_interactive(const char *revision, const char *patch_mode,
247-
const char **pathspec)
247+
const struct pathspec *pathspec)
248248
{
249-
int status, ac, pc = 0;
249+
int status, ac, i;
250250
const char **args;
251251

252-
if (pathspec)
253-
while (pathspec[pc])
254-
pc++;
255-
256-
args = xcalloc(sizeof(const char *), (pc + 5));
252+
args = xcalloc(sizeof(const char *), (pathspec->nr + 6));
257253
ac = 0;
258254
args[ac++] = "add--interactive";
259255
if (patch_mode)
260256
args[ac++] = patch_mode;
261257
if (revision)
262258
args[ac++] = revision;
263259
args[ac++] = "--";
264-
if (pc) {
265-
memcpy(&(args[ac]), pathspec, sizeof(const char *) * pc);
266-
ac += pc;
267-
}
268-
args[ac] = NULL;
260+
for (i = 0; i < pathspec->nr; i++)
261+
/* pass original pathspec, to be re-parsed */
262+
args[ac++] = pathspec->items[i].original;
269263

270264
status = run_command_v_opt(args, RUN_GIT_CMD);
271265
free(args);
@@ -280,17 +274,17 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
280274
* git-add--interactive itself does not parse pathspec. It
281275
* simply passes the pathspec to other builtin commands. Let's
282276
* hope all of them support all magic, or we'll need to limit
283-
* the magic here. There is still a problem with prefix. But
284-
* that'll be worked on later on.
277+
* the magic here.
285278
*/
286279
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
287280
PATHSPEC_PREFER_FULL |
288-
PATHSPEC_SYMLINK_LEADING_PATH,
281+
PATHSPEC_SYMLINK_LEADING_PATH |
282+
PATHSPEC_PREFIX_ORIGIN,
289283
prefix, argv);
290284

291285
return run_add_interactive(NULL,
292286
patch ? "--patch" : NULL,
293-
pathspec.raw);
287+
&pathspec);
294288
}
295289

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

builtin/checkout.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int checkout_paths(const struct checkout_opts *opts,
257257

258258
if (opts->patch_mode)
259259
return run_add_interactive(revision, "--patch=checkout",
260-
opts->pathspec.raw);
260+
&opts->pathspec);
261261

262262
lock_file = xcalloc(1, sizeof(struct lock_file));
263263

@@ -1159,10 +1159,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11591159
* cannot handle. Magic mask is pretty safe to be
11601160
* lifted for new magic when opts.patch_mode == 0.
11611161
*/
1162-
parse_pathspec(&opts.pathspec,
1163-
opts.patch_mode == 0 ? 0 :
1164-
(PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP),
1165-
0, prefix, argv);
1162+
parse_pathspec(&opts.pathspec, 0,
1163+
opts.patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
1164+
prefix, argv);
11661165

11671166
if (!opts.pathspec.nr)
11681167
die(_("invalid path specification"));

builtin/reset.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ static void parse_args(struct pathspec *pathspec,
219219
}
220220
}
221221
*rev_ret = rev;
222-
parse_pathspec(pathspec,
223-
patch_mode ? PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP : 0,
224-
PATHSPEC_PREFER_FULL,
222+
parse_pathspec(pathspec, 0,
223+
PATHSPEC_PREFER_FULL |
224+
(patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
225225
prefix, argv);
226226
}
227227

@@ -299,7 +299,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
299299
if (patch_mode) {
300300
if (reset_type != NONE)
301301
die(_("--patch is incompatible with --{hard,mixed,soft}"));
302-
return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", pathspec.raw);
302+
return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", &pathspec);
303303
}
304304

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

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int in_merge_bases_many(struct commit *, int, struct commit **);
194194

195195
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
196196
extern int run_add_interactive(const char *revision, const char *patch_mode,
197-
const char **pathspec);
197+
const struct pathspec *pathspec);
198198

199199
static inline int single_parent(struct commit *commit)
200200
{

0 commit comments

Comments
 (0)