Skip to content

Commit 1cf9952

Browse files
pcloudsgitster
authored andcommittedDec 1, 2014
ls-tree: remove path filtering logic in show_tree
ls-tree uses read_tree_recursive() which already does path filtering using pathspec. No need to filter one more time based on prefix only. "ls-tree ../somewhere" does not work because of this. write_name_quotedpfx() can now be retired because nobody else uses it. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a0b0b6 commit 1cf9952

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed
 

‎builtin/ls-tree.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
6565
const char *pathname, unsigned mode, int stage, void *context)
6666
{
6767
int retval = 0;
68+
int baselen;
6869
const char *type = blob_type;
6970

7071
if (S_ISGITLINK(mode)) {
@@ -89,11 +90,6 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
8990
else if (ls_options & LS_TREE_ONLY)
9091
return 0;
9192

92-
if (chomp_prefix &&
93-
(base->len < chomp_prefix ||
94-
memcmp(ls_tree_prefix, base->buf, chomp_prefix)))
95-
return 0;
96-
9793
if (!(ls_options & LS_NAME_ONLY)) {
9894
if (ls_options & LS_SHOW_SIZE) {
9995
char size_text[24];
@@ -113,8 +109,12 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
113109
printf("%06o %s %s\t", mode, type,
114110
find_unique_abbrev(sha1, abbrev));
115111
}
116-
write_name_quotedpfx(base->buf + chomp_prefix, base->len - chomp_prefix,
117-
pathname, stdout, line_termination);
112+
baselen = base->len;
113+
strbuf_addstr(base, pathname);
114+
write_name_quoted_relative(base->buf,
115+
chomp_prefix ? ls_tree_prefix : NULL,
116+
stdout, line_termination);
117+
strbuf_setlen(base, baselen);
118118
return retval;
119119
}
120120

‎quote.c

-21
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,6 @@ void write_name_quoted(const char *name, FILE *fp, int terminator)
274274
fputc(terminator, fp);
275275
}
276276

277-
void write_name_quotedpfx(const char *pfx, size_t pfxlen,
278-
const char *name, FILE *fp, int terminator)
279-
{
280-
int needquote = 0;
281-
282-
if (terminator) {
283-
needquote = next_quote_pos(pfx, pfxlen) < pfxlen
284-
|| name[next_quote_pos(name, -1)];
285-
}
286-
if (needquote) {
287-
fputc('"', fp);
288-
quote_c_style_counted(pfx, pfxlen, NULL, fp, 1);
289-
quote_c_style(name, NULL, fp, 1);
290-
fputc('"', fp);
291-
} else {
292-
fwrite(pfx, pfxlen, 1, fp);
293-
fputs(name, fp);
294-
}
295-
fputc(terminator, fp);
296-
}
297-
298277
void write_name_quoted_relative(const char *name, const char *prefix,
299278
FILE *fp, int terminator)
300279
{

‎quote.h

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq
5656
extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
5757

5858
extern void write_name_quoted(const char *name, FILE *, int terminator);
59-
extern void write_name_quotedpfx(const char *pfx, size_t pfxlen,
60-
const char *name, FILE *, int terminator);
6159
extern void write_name_quoted_relative(const char *name, const char *prefix,
6260
FILE *fp, int terminator);
6361

‎t/t3102-ls-tree-wildcards.sh

+8
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ EOF
1919
test_cmp expected actual
2020
'
2121

22+
test_expect_success 'ls-tree outside prefix' '
23+
cat >expected <<EOF &&
24+
100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ../a[a]/three
25+
EOF
26+
( cd aa && git ls-tree -r HEAD "../a[a]"; ) >actual &&
27+
test_cmp expected actual
28+
'
29+
2230
test_done

0 commit comments

Comments
 (0)
Please sign in to comment.