reset: convert to use parse_pathspec
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
f8144c9fcff09597670ac7bf69d5cde4af5f206c
1 file changed
+16
-10
builtin/reset.c
+16
-10
@@ -174,7 +174,10 @@ static void die_if_unmerged_cache(int reset_type)
174
175
}
176
177
-static const char **parse_args(const char **argv, const char *prefix, const char **rev_ret)
177
+static void parse_args(struct pathspec *pathspec,
178
+ const char **argv, const char *prefix,
179
+ int patch_mode,
180
+ const char **rev_ret)
181
{
182
const char *rev = "HEAD";
183
unsigned char unused[20];
@@ -216,7 +219,10 @@ static const char **parse_args(const char **argv, const char *prefix, const char
219
}
220
}
221
*rev_ret = rev;
219
- return argv[0] ? get_pathspec(prefix, argv) : NULL;
222
+ parse_pathspec(pathspec,
223
+ patch_mode ? PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP : 0,
224
+ PATHSPEC_PREFER_FULL,
225
+ prefix, argv);
226
}
227
228
static int update_refs(const char *rev, const unsigned char *sha1)
@@ -246,7 +252,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
252
int patch_mode = 0, unborn;
253
const char *rev;
254
unsigned char sha1[20];
249
- const char **pathspec = NULL;
255
+ struct pathspec pathspec;
256
const struct option options[] = {
257
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
258
OPT_SET_INT(0, "mixed", &reset_type,
@@ -266,13 +272,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
272
273
argc = parse_options(argc, argv, prefix, options, git_reset_usage,
274
PARSE_OPT_KEEP_DASHDASH);
269
- pathspec = parse_args(argv, prefix, &rev);
275
+ parse_args(&pathspec, argv, prefix, patch_mode, &rev);
276
277
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", sha1);
278
if (unborn) {
279
/* reset on unborn branch: treat as reset to empty tree */
280
hashcpy(sha1, EMPTY_TREE_SHA1_BIN);
275
- } else if (!pathspec) {
281
+ } else if (!pathspec.nr) {
282
struct commit *commit;
283
if (get_sha1_committish(rev, sha1))
284
die(_("Failed to resolve '%s' as a valid revision."), rev);
@@ -293,13 +299,13 @@ 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}"));
296
- return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", pathspec);
302
+ return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", pathspec.raw);
303
}
304
305
/* git reset tree [--] paths... can be used to
306
* load chosen paths from the tree into the index without
307
* affecting the working tree nor HEAD. */
302
- if (pathspec) {
308
+ if (pathspec.nr) {
309
if (reset_type == MIXED)
310
warning(_("--mixed with paths is deprecated; use 'git reset -- <paths>' instead."));
311
else if (reset_type != NONE)
@@ -326,7 +332,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
332
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
333
int newfd = hold_locked_index(lock, 1);
334
if (reset_type == MIXED) {
329
- if (read_from_tree(pathspec, sha1))
335
+ if (read_from_tree(pathspec.raw, sha1))
336
return 1;
337
} else {
338
int err = reset_index(sha1, reset_type, quiet);
@@ -347,7 +353,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
353
die(_("Could not write new index file."));
354
}
355
350
- if (!pathspec && !unborn) {
356
+ if (!pathspec.nr && !unborn) {
357
/* Any resets without paths update HEAD to the head being
358
* switched to, saving the previous head in ORIG_HEAD before. */
359
update_ref_status = update_refs(rev, sha1);
@@ -355,7 +361,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
361
if (reset_type == HARD && !update_ref_status && !quiet)
362
print_new_head_line(lookup_commit_reference(sha1));
363
}
358
- if (!pathspec)
364
+ if (!pathspec.nr)
365
remove_branch_state();
366
367
return update_ref_status;