Skip to content

Commit bb49920

Browse files
committed
Merge branch 'tl/ls-tree-oid-only' into seen
"git ls-tree" learns "--oid-only" option, similar to "--name-only", and more generalized "--format" option. source: <[email protected]> * tl/ls-tree-oid-only: cocci: allow padding with `strbuf_addf()` ls-tree.c: introduce "--format" option ls-tree.c: introduce struct "show_tree_data" ls-tree.c: support --object-only option for "git-ls-tree" ls-tree: optimize naming and handling of "return" in show_tree() ls-tree: use "size_t", not "int" for "struct strbuf"'s "len" ls-tree: use "enum object_type", not {blob,tree,commit}_type ls-tree: add missing braces to "else" arms ls-tree: remove commented-out code
2 parents 08a0108 + 2b83e5f commit bb49920

File tree

5 files changed

+427
-68
lines changed

5 files changed

+427
-68
lines changed

Documentation/git-ls-tree.txt

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git ls-tree' [-d] [-r] [-t] [-l] [-z]
13-
[--name-only] [--name-status] [--full-name] [--full-tree] [--abbrev[=<n>]]
14-
<tree-ish> [<path>...]
15-
13+
[--name-only] [--name-status] [--object-only]
14+
[--full-name] [--full-tree] [--abbrev[=<n>]]
15+
[--format=<format>] <tree-ish> [<path>...]
1616
DESCRIPTION
1717
-----------
1818
Lists the contents of a given tree object, like what "/bin/ls -a" does
@@ -59,6 +59,11 @@ OPTIONS
5959
--name-only::
6060
--name-status::
6161
List only filenames (instead of the "long" output), one per line.
62+
Cannot be combined with `--object-only`.
63+
64+
--object-only::
65+
List only names of the objects, one per line. Cannot be combined
66+
with `--name-only` or `--name-status`.
6267

6368
--abbrev[=<n>]::
6469
Instead of showing the full 40-byte hexadecimal object
@@ -74,6 +79,16 @@ OPTIONS
7479
Do not limit the listing to the current working directory.
7580
Implies --full-name.
7681

82+
--format=<format>::
83+
A string that interpolates `%(fieldname)` from the result
84+
being shown. It also interpolates `%%` to `%`, and
85+
`%xx` where `xx`are hex digits interpolates to character
86+
with hex code `xx`; for example `%00` interpolates to
87+
`\0` (NUL), `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
88+
When specified, `--format` cannot be combined with other
89+
format-altering options, including `--long`, `--name-only`
90+
and `--object-only`.
91+
7792
[<path>...]::
7893
When paths are given, show them (note that this isn't really raw
7994
pathnames, but rather a list of patterns to match). Otherwise
@@ -82,6 +97,9 @@ OPTIONS
8297

8398
Output Format
8499
-------------
100+
101+
Default format:
102+
85103
<mode> SP <type> SP <object> TAB <file>
86104

87105
This output format is compatible with what `--index-info --stdin` of
@@ -100,6 +118,37 @@ quoted as explained for the configuration variable `core.quotePath`
100118
(see linkgit:git-config[1]). Using `-z` the filename is output
101119
verbatim and the line is terminated by a NUL byte.
102120

121+
Customized format:
122+
123+
It's support to print customized format by `%(fieldname)` with `--format` option.
124+
For example, if you want to only print the <object> and <file> fields with a
125+
JSON style, executing with a specific "--format" like
126+
127+
git ls-tree --format='{"object":"%(object)", "file":"%(file)"}' <tree-ish>
128+
129+
The output format changes to:
130+
131+
{"object":"<object>", "file":"<file>"}
132+
133+
FIELD NAMES
134+
-----------
135+
136+
Various values from structured fields can be used to interpolate
137+
into the resulting output. For each outputing line, the following
138+
names can be used:
139+
140+
mode::
141+
The mode of the object.
142+
type::
143+
The type of the object (`blob` or `tree`).
144+
object::
145+
The name of the object.
146+
size[:padded]::
147+
The size of the object ("-" if it's a tree).
148+
It also supports a padded format of size with "%(size:padded)".
149+
file::
150+
The filename of the object.
151+
103152
GIT
104153
---
105154
Part of the linkgit:git[1] suite

0 commit comments

Comments
 (0)