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>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
480ca6449ed0981311b8aef2fbaa89d024b881ee
4 files changed
+19
-26
builtin/add.c
+10
-16
@@ -244,16 +244,12 @@ static void refresh(int verbose, const char **pathspec)
244
}
245
246
int run_add_interactive(const char *revision, const char *patch_mode,
247
- const char **pathspec)
247
+ const struct pathspec *pathspec)
248
{
249
- int status, ac, pc = 0;
249
+ int status, ac, i;
250
const char **args;
251
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));
253
ac = 0;
254
args[ac++] = "add--interactive";
255
if (patch_mode)
@@ -261,11 +257,9 @@ int run_add_interactive(const char *revision, const char *patch_mode,
257
if (revision)
258
args[ac++] = revision;
259
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;
263
264
status = run_command_v_opt(args, RUN_GIT_CMD);
265
free(args);
@@ -280,17 +274,17 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
274
* git-add--interactive itself does not parse pathspec. It
275
* simply passes the pathspec to other builtin commands. Let's
276
* 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.
278
*/
279
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
280
PATHSPEC_PREFER_FULL |
288
- PATHSPEC_SYMLINK_LEADING_PATH,
281
+ PATHSPEC_SYMLINK_LEADING_PATH |
282
+ PATHSPEC_PREFIX_ORIGIN,
283
prefix, argv);
284
285
return run_add_interactive(NULL,
286
patch ? "--patch" : NULL,
293
- pathspec.raw);
287
+ &pathspec);
288
}
289
290
static int edit_patch(int argc, const char **argv, const char *prefix)
builtin/checkout.c
+4
-5
@@ -257,7 +257,7 @@ static int checkout_paths(const struct checkout_opts *opts,
257
258
if (opts->patch_mode)
259
return run_add_interactive(revision, "--patch=checkout",
260
- opts->pathspec.raw);
260
+ &opts->pathspec);
261
262
lock_file = xcalloc(1, sizeof(struct lock_file));
263
@@ -1159,10 +1159,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1159
* cannot handle. Magic mask is pretty safe to be
1160
* lifted for new magic when opts.patch_mode == 0.
1161
*/
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);
1165
1166
if (!opts.pathspec.nr)
1167
die(_("invalid path specification"));
builtin/reset.c
+4
-4
@@ -219,9 +219,9 @@ static void parse_args(struct pathspec *pathspec,
219
}
220
}
221
*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),
225
prefix, argv);
226
}
227
@@ -299,7 +299,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
299
if (patch_mode) {
300
if (reset_type != NONE)
301
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);
303
}
304
305
/* git reset tree [--] paths... can be used to
commit.h
+1
-1
@@ -194,7 +194,7 @@ int in_merge_bases_many(struct commit *, int, struct commit **);
194
195
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
196
extern int run_add_interactive(const char *revision, const char *patch_mode,
197
- const char **pathspec);
197
+ const struct pathspec *pathspec);
198
199
static inline int single_parent(struct commit *commit)
200
{