Skip to content

Commit 6af1f01

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] Rewrite ls-tree to behave more like "/bin/ls -a"
This is a complete rewrite of ls-tree to make it behave more like what "/bin/ls -a" does in the current working directory. Namely, the changes are: - Unlike the old ls-tree behaviour that used paths arguments to restrict output (not that it worked as intended---as pointed out in the mailing list discussion, it was quite incoherent), this rewrite uses paths arguments to specify what to show. - Without arguments, it implicitly uses the root level as its sole argument ("/bin/ls -a" behaves as if "." is given without argument). - Without -r (recursive) flag, it shows the named blob (either file or symlink), or the named tree and its immediate children. - With -r flag, it shows the named path, and recursively descends into it if it is a tree. - With -d flag, it shows the named path and does not show its children even if the path is a tree, nor descends into it recursively. This is still request-for-comments patch. There is no mailing list consensus that this proposed new behaviour is a good one. The patch to t/t3100-ls-tree-restrict.sh illustrates user-visible behaviour changes. Namely: * "git-ls-tree $tree path1 path0" lists path1 first and then path0. It used to use paths as an output restrictor and showed output in cache entry order (i.e. path0 first and then path1) regardless of the order of paths arguments. * "git-ls-tree $tree path2" lists path2 and its immediate children but having explicit paths argument does not imply recursive behaviour anymore, hence paths/baz is shown but not paths/baz/b. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 2bc2564 commit 6af1f01

File tree

5 files changed

+195
-156
lines changed

5 files changed

+195
-156
lines changed

Documentation/git-ls-tree.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,46 @@ v0.1, May 2005
44

55
NAME
66
----
7-
git-ls-tree - Displays a tree object in human readable form
7+
git-ls-tree - Lists the contents of a tree object.
88

99

1010
SYNOPSIS
1111
--------
12-
'git-ls-tree' [-r] [-z] <tree-ish> [paths...]
12+
'git-ls-tree' [-d] [-r] [-z] <tree-ish> [paths...]
1313

1414
DESCRIPTION
1515
-----------
16-
Converts the tree object to a human readable (and script processable)
17-
form.
16+
Lists the contents of a tree object, like what "/bin/ls -a" does
17+
in the current working directory.
1818

1919
OPTIONS
2020
-------
2121
<tree-ish>::
2222
Id of a tree.
2323

24+
-d::
25+
show only the named tree entry itself, not its children
26+
2427
-r::
2528
recurse into sub-trees
2629

2730
-z::
2831
\0 line termination on output
2932

3033
paths::
31-
Optionally, restrict the output of git-ls-tree to specific
32-
paths. Directories will only list their tree blob ids.
33-
Implies -r.
34+
When paths are given, shows them. Otherwise implicitly
35+
uses the root level of the tree as the sole path argument.
36+
3437

3538
Output Format
3639
-------------
37-
<mode>\t <type>\t <object>\t <file>
40+
<mode> SP <type> SP <object> TAB <file>
3841

3942

4043
Author
4144
------
4245
Written by Linus Torvalds <torvalds@osdl.org>
46+
Completely rewritten from scratch by Junio C Hamano <junkio@cox.net>
4347

4448
Documentation
4549
--------------

0 commit comments

Comments
 (0)