MCPcopy Create free account
hub / github.com/git/git / parse_args

Function parse_args

builtin/reset.c:247–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245}
246
247static void parse_args(struct pathspec *pathspec,
248 const char **argv, const char *prefix,
249 int patch_mode,
250 const char **rev_ret)
251{
252 const char *rev = "HEAD";
253 struct object_id unused;
254 /*
255 * Possible arguments are:
256 *
257 * git reset [-opts] [<rev>]
258 * git reset [-opts] <tree> [<paths>...]
259 * git reset [-opts] <tree> -- [<paths>...]
260 * git reset [-opts] -- [<paths>...]
261 * git reset [-opts] <paths>...
262 *
263 * At this point, argv points immediately after [-opts].
264 */
265
266 if (argv[0]) {
267 if (!strcmp(argv[0], "--")) {
268 argv++; /* reset to HEAD, possibly with paths */
269 } else if (argv[1] && !strcmp(argv[1], "--")) {
270 rev = argv[0];
271 argv += 2;
272 }
273 /*
274 * Otherwise, argv[0] could be either <rev> or <paths> and
275 * has to be unambiguous. If there is a single argument, it
276 * can not be a tree
277 */
278 else if ((!argv[1] && !repo_get_oid_committish(the_repository, argv[0], &unused)) ||
279 (argv[1] && !repo_get_oid_treeish(the_repository, argv[0], &unused))) {
280 /*
281 * Ok, argv[0] looks like a commit/tree; it should not
282 * be a filename.
283 */
284 verify_non_filename(the_repository, prefix, argv[0]);
285 rev = *argv++;
286 } else {
287 /* Otherwise we treat this as a filename */
288 verify_filename(the_repository, prefix, argv[0], 1);
289 }
290 }
291
292 /* treat '@' as a shortcut for 'HEAD' */
293 *rev_ret = !strcmp("@", rev) ? "HEAD" : rev;
294
295 parse_pathspec(pathspec, 0,
296 PATHSPEC_PREFER_FULL |
297 (patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
298 prefix, argv);
299}
300
301static int reset_refs(const char *rev, const struct object_id *oid)
302{

Callers 1

cmd_resetFunction · 0.85

Calls 5

repo_get_oid_committishFunction · 0.85
repo_get_oid_treeishFunction · 0.85
verify_non_filenameFunction · 0.85
verify_filenameFunction · 0.85
parse_pathspecFunction · 0.85

Tested by

no test coverage detected