Git fork

pathspec: add flag to indicate operation without repository

A following change will add support for pathspecs to the git diff
--no-index command. This mode of git diff does not load any repository.

Add a new PATHSPEC_NO_REPOSITORY flag indicating that we're parsing
pathspecs without a repository.

Both PATHSPEC_ATTR and PATHSPEC_FROMTOP require a repository to
function. Thus, verify that both of these are set in magic_mask to
ensure they won't be accepted when PATHSPEC_NO_REPOSITORY is set.

Check PATHSPEC_NO_REPOSITORY when warning about paths outside the
directory tree. When the flag is set, do not look for a git repository
when generating the warning message.

Finally, add a BUG in match_pathspec_item if the istate is NULL but the
pathspec has PATHSPEC_ATTR set. Callers which support PATHSPEC_ATTR
should always pass a valid istate, and callers which don't pass a valid
istate should have set PATHSPEC_ATTR in the magic_mask field to disable
support for attribute-based pathspecs.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jacob Keller and committed by
Junio C Hamano
00466c16 6e4fb001

+16 -4
+6 -3
dir.c
··· 397 397 strncmp(item->match, name - prefix, item->prefix)) 398 398 return 0; 399 399 400 - if (item->attr_match_nr && 401 - !match_pathspec_attrs(istate, name - prefix, namelen + prefix, item)) 402 - return 0; 400 + if (item->attr_match_nr) { 401 + if (!istate) 402 + BUG("magic PATHSPEC_ATTR requires an index"); 403 + if (!match_pathspec_attrs(istate, name - prefix, namelen + prefix, item)) 404 + return 0; 405 + } 403 406 404 407 /* If the match was just the prefix, we matched */ 405 408 if (!*match)
+5 -1
pathspec.c
··· 492 492 if (!match) { 493 493 const char *hint_path; 494 494 495 - if (!have_git_dir()) 495 + if ((flags & PATHSPEC_NO_REPOSITORY) || !have_git_dir()) 496 496 die(_("'%s' is outside the directory tree"), 497 497 copyfrom); 498 498 hint_path = repo_get_work_tree(the_repository); ··· 613 613 if ((flags & PATHSPEC_PREFER_CWD) && 614 614 (flags & PATHSPEC_PREFER_FULL)) 615 615 BUG("PATHSPEC_PREFER_CWD and PATHSPEC_PREFER_FULL are incompatible"); 616 + 617 + if ((flags & PATHSPEC_NO_REPOSITORY) && 618 + (~magic_mask & (PATHSPEC_ATTR | PATHSPEC_FROMTOP))) 619 + BUG("PATHSPEC_NO_REPOSITORY is incompatible with PATHSPEC_ATTR and PATHSPEC_FROMTOP"); 616 620 617 621 /* No arguments with prefix -> prefix pathspec */ 618 622 if (!entry) {
+5
pathspec.h
··· 76 76 * allowed, then it will automatically set for every pathspec. 77 77 */ 78 78 #define PATHSPEC_LITERAL_PATH (1<<6) 79 + /* 80 + * For git diff --no-index, indicate that we are operating without 81 + * a repository or index. 82 + */ 83 + #define PATHSPEC_NO_REPOSITORY (1<<7) 79 84 80 85 /** 81 86 * Given command line arguments and a prefix, convert the input to