summaryrefslogtreecommitdiff
path: root/pathspec.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-07-14 15:35:35 +0700
committerJunio C Hamano <gitster@pobox.com>2013-07-15 10:56:07 -0700
commitdad2586a6b30da902d5f1979221eccc474425a7a (patch)
tree932d43dbd1cb9a3ca682a3a1df79770c1b4277ac /pathspec.c
parent8745024422d4b38d8bf93d342b7b173f57cbceaa (diff)
downloadgit-dad2586a6b30da902d5f1979221eccc474425a7a.tar.gz
parse_pathspec: support prefixing original patterns
This makes 'original' suitable for passing to an external command because all pathspec magic is left in place, provided that the external command understands pathspec. The prefixing is needed because we usually launch a subcommand at worktree's top directory and the subcommand can no longer calculate the prefix itself. This slightly affects the original purpose of 'original' (i.e. reporting). We should report without prefixing. So only turn this flag on when you know you are about to pass the result straight away to an external command. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pathspec.c')
-rw-r--r--pathspec.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/pathspec.c b/pathspec.c
index e2a4f910f9..ba6408a74c 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -203,7 +203,17 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
else
match = prefix_path(prefix, prefixlen, copyfrom);
*raw = item->match = match;
- item->original = elt;
+ /*
+ * Prefix the pathspec (keep all magic) and assign to
+ * original. Useful for passing to another command.
+ */
+ if (flags & PATHSPEC_PREFIX_ORIGIN) {
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_add(&sb, elt, copyfrom - elt);
+ strbuf_addstr(&sb, match);
+ item->original = strbuf_detach(&sb, NULL);
+ } else
+ item->original = elt;
item->len = strlen(item->match);
if ((flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) &&