* Re: [RFC PATCH 0/7] ls-tree --format
@ 2021-12-23 9:50 Teng Long
0 siblings, 0 replies; 2+ messages in thread
From: Teng Long @ 2021-12-23 9:50 UTC (permalink / raw)
To: avarab; +Cc: dyroneteng, git, gitster
> FWIW here's the changes I had locally & cleaned up now that did the
> alternate --format approach.
Oh, sorry for the late reply, thanks for your advice.
Base on this reply and the RFC patch, I need to read over them first
and make sure I'm clear about what you mean.
After that, I will reply again if there exist any doubts from me.
By the way, If I want to base one on your RFC code, how can I download the patch
and do I need to add some information on the commit message?
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v6 0/1] support `--object-only` option for "git-ls-tree"
@ 2021-12-17 6:57 Teng Long
2021-12-17 13:30 ` [RFC PATCH 0/7] ls-tree --format Ævar Arnfjörð Bjarmason
0 siblings, 1 reply; 2+ messages in thread
From: Teng Long @ 2021-12-17 6:57 UTC (permalink / raw)
To: dyroneteng; +Cc: avarab, congdanhqx, git, gitster, peff
Diffs from patch v5:
* Let "write_name_quoted_relative" support two terminations, they are
"CQ_NO_TERMINATOR_C_QUOTED" and "CQ_NO_TERMINATOR_AS_IS" (They are
used to let the function write "name" at a 'c_quoted' way or just
'as-is', but without print a terminator).
* Rename "follow" to "interspace" (Representing whether any further
output needs an inter-field space).
* Nits fixed.
Many thanks to Junio and Ævar for your help and patient explanation.
I noticed Ævar suggest the solution with using `--format`, but in
this patch, the current approach continues. If this part of code needs
to be improved or we want to support "--format" in "ls-tree" in the
future, I'm more than glad to continue to contribute.
Thanks.
Teng Long (1):
ls-tree.c: support `--object-only` option for "git-ls-tree"
Documentation/git-ls-tree.txt | 7 +-
builtin/ls-tree.c | 131 ++++++++++++++++++++++++----------
quote.c | 8 +--
quote.h | 19 +++++
t/t3103-ls-tree-misc.sh | 8 +++
t/t3104-ls-tree-oid.sh | 51 +++++++++++++
6 files changed, 183 insertions(+), 41 deletions(-)
create mode 100755 t/t3104-ls-tree-oid.sh
Range-diff against v5:
1: 38d55a878c ! 1: 2e449d1c79 ls-tree.c: support `--object-only` option for "git-ls-tree"
@@ builtin/ls-tree.c
-#define LS_SHOW_TREES 4
-#define LS_NAME_ONLY 8
-#define LS_SHOW_SIZE 16
-+#define LS_TREE_ONLY 1 << 1
-+#define LS_SHOW_TREES 1 << 2
-+#define LS_NAME_ONLY 1 << 3
-+#define LS_SHOW_SIZE 1 << 4
-+#define LS_OBJECT_ONLY 1 << 5
++#define LS_TREE_ONLY (1 << 1)
++#define LS_SHOW_TREES (1 << 2)
++#define LS_NAME_ONLY (1 << 3)
++#define LS_SHOW_SIZE (1 << 4)
++#define LS_OBJECT_ONLY (1 << 5)
static int abbrev;
static int ls_options;
static struct pathspec pathspec;
static int chomp_prefix;
static const char *ls_tree_prefix;
-+static unsigned int shown_bits = 0;
-+#define SHOW_DEFAULT 29 /* 11101 size is not shown to output by default */
-+#define SHOW_MODE 1 << 4
-+#define SHOW_TYPE 1 << 3
-+#define SHOW_OBJECT_NAME 1 << 2
-+#define SHOW_SIZE 1 << 1
++static unsigned int shown_bits;
+#define SHOW_FILE_NAME 1
++#define SHOW_SIZE (1 << 1)
++#define SHOW_OBJECT_NAME (1 << 2)
++#define SHOW_TYPE (1 << 3)
++#define SHOW_MODE (1 << 4)
++#define SHOW_DEFAULT 29 /* 11101 size is not shown to output by default */
static const char * const ls_tree_usage[] = {
N_("git ls-tree [<options>] <tree-ish> [<path>...]"),
@@ builtin/ls-tree.c
+ MODE_UNSPECIFIED = 0,
+ MODE_NAME_ONLY,
+ MODE_OBJECT_ONLY,
-+ MODE_LONG
++ MODE_LONG,
+};
+
+static int cmdmode = MODE_UNSPECIFIED;
@@ builtin/ls-tree.c: static int show_tree(const struct object_id *oid, struct strb
{
int retval = 0;
int baselen;
-+ int follow = 0;
++ int interspace = 0;
const char *type = blob_type;
if (S_ISGITLINK(mode)) {
@@ builtin/ls-tree.c: static int show_tree(const struct object_id *oid, struct strb
- find_unique_abbrev(oid, abbrev),
- size_text);
+ if (shown_bits & SHOW_MODE) {
-+ printf("%06o",mode);
-+ follow = 1;
++ printf("%06o", mode);
++ interspace = 1;
+ }
+ if (shown_bits & SHOW_TYPE) {
-+ printf("%s%s", follow == 1 ? " " : "", type);
-+ follow = 1;
++ printf("%s%s", interspace ? " " : "", type);
++ interspace = 1;
+ }
+ if (shown_bits & SHOW_OBJECT_NAME) {
-+ printf("%s%s", follow == 1 ? " " : "",
++ printf("%s%s", interspace ? " " : "",
+ find_unique_abbrev(oid, abbrev));
+ if (!(shown_bits ^ SHOW_OBJECT_NAME))
-+ printf("%c", line_termination);
-+ follow = 1;
++ goto LINE_FINISH;
++ interspace = 1;
+ }
+ if (shown_bits & SHOW_SIZE) {
+ char size_text[24];
@@ builtin/ls-tree.c: static int show_tree(const struct object_id *oid, struct strb
- printf("%06o %s %s\t", mode, type,
- find_unique_abbrev(oid, abbrev));
+ xsnprintf(size_text, sizeof(size_text), "-");
-+ printf("%s%7s", follow == 1 ? " " : "", size_text);
-+ follow = 1;
++ printf("%s%7s", interspace ? " " : "", size_text);
++ interspace = 1;
+ }
+ if (shown_bits & SHOW_FILE_NAME) {
-+ if (follow)
++ if (interspace)
+ printf("\t");
+ baselen = base->len;
+ strbuf_addstr(base, pathname);
+ write_name_quoted_relative(base->buf,
+ chomp_prefix ? ls_tree_prefix : NULL,
-+ stdout, line_termination);
++ stdout,
++ line_termination
++ ? CQ_NO_TERMINATOR_C_QUOTED
++ : CQ_NO_TERMINATOR_AS_IS);
+ strbuf_setlen(base, baselen);
}
- baselen = base->len;
@@ builtin/ls-tree.c: static int show_tree(const struct object_id *oid, struct strb
- chomp_prefix ? ls_tree_prefix : NULL,
- stdout, line_termination);
- strbuf_setlen(base, baselen);
++
++LINE_FINISH:
++ putchar(line_termination);
return retval;
}
@@ builtin/ls-tree.c: int cmd_ls_tree(int argc, const char **argv, const char *pref
* show_recursive() rolls its own matching code and is
* generally ignorant of 'struct pathspec'. The magic mask
+ ## quote.c ##
+@@ quote.c: void quote_two_c_style(struct strbuf *sb, const char *prefix, const char *path,
+
+ void write_name_quoted(const char *name, FILE *fp, int terminator)
+ {
+- if (terminator) {
++ if (0 < terminator || terminator == CQ_NO_TERMINATOR_C_QUOTED)
+ quote_c_style(name, NULL, fp, 0);
+- } else {
++ else
+ fputs(name, fp);
+- }
+- fputc(terminator, fp);
++ if (0 <= terminator)
++ fputc(terminator, fp);
+ }
+
+ void write_name_quoted_relative(const char *name, const char *prefix,
+
+ ## quote.h ##
+@@ quote.h: int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
+ #define CQUOTE_NODQ 01
+ size_t quote_c_style(const char *name, struct strbuf *, FILE *, unsigned);
+ void quote_two_c_style(struct strbuf *, const char *, const char *, unsigned);
++/*
++ * Write a name, typically a filename, followed by a terminator that
++ * separates it from what comes next.
++ * When terminator is NUL, the name is given as-is. Otherwise, the
++ * name is c-quoted, suitable for text output. HT and LF are typical
++ * values used for the terminator, but other positive values are possible.
++ *
++ * In addition to non-negative values two special values in terminator
++ * are possible.
++ *
++ * -1: show the name c-quoted, without adding any terminator.
++ * -2: show the name as-is, without adding any terminator.
++ */
++#define CQ_NO_TERMINATOR_C_QUOTED (-1)
++#define CQ_NO_TERMINATOR_AS_IS (-2)
+
+ void write_name_quoted(const char *name, FILE *, int terminator);
++/*
++ * Similar to the above, but the name is first made relative to the prefix
++ * before being shown.
++ */
+ void write_name_quoted_relative(const char *name, const char *prefix,
+ FILE *fp, int terminator);
+
+
## t/t3103-ls-tree-misc.sh ##
@@ t/t3103-ls-tree-misc.sh: test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
test_must_fail git ls-tree -r HEAD
--
2.33.1.10.g5f17c1a2c1.dirty
^ permalink raw reply [flat|nested] 2+ messages in thread
* [RFC PATCH 0/7] ls-tree --format
2021-12-17 6:57 [PATCH v6 0/1] support `--object-only` option for "git-ls-tree" Teng Long
@ 2021-12-17 13:30 ` Ævar Arnfjörð Bjarmason
0 siblings, 0 replies; 2+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-12-17 13:30 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Teng Long, Ævar Arnfjörð Bjarmason
On Fri, Dec 17 2021, Teng Long wrote:
> Many thanks to Junio and Ævar for your help and patient explanation.
> I noticed Ævar suggest the solution with using `--format`, but in
> this patch, the current approach continues. If this part of code needs
> to be improved or we want to support "--format" in "ls-tree" in the
> future, I'm more than glad to continue to contribute.
FWIW here's the changes I had locally & cleaned up now that did the
alternate --format approach.
I think you'll probably want to steal some of this, e.g. you're
patching the dead comment I removed in 1/6, 2-4/6 can be skipped, but
I thought they were nice.
Back when I last looked at this series, your --object-name patch was
much shorter, but now it's about the same size as the generic --format
support. So maybe it's worth considering implementing the more generic
path.
One reason I didn't submit this before is that I couldn't get past the
performance regression this would inttroduce, i.e. if moved entirely
to strbuf_expand(). Here though I'm keeping the old code, so it's no
slower than "master", unlike your patch. But I haven't dug into why
yours is slower:
$ git hyperfine -L rev origin/master,tl/object-name,avar/ls-tree-format -s 'make CFLAGS=-O3' './git -C /run/user/1001/linux ls-tree -r HEAD' --warmup 10 -r 10
Benchmark 1: ./git -C /run/user/1001/linux ls-tree -r HEAD' in 'origin/master
Time (mean ± σ): 67.8 ms ± 0.3 ms [User: 48.8 ms, System: 18.9 ms]
Range (min … max): 67.4 ms … 68.4 ms 10 runs
Benchmark 2: ./git -C /run/user/1001/linux ls-tree -r HEAD' in 'tl/object-name
Time (mean ± σ): 72.8 ms ± 0.4 ms [User: 50.6 ms, System: 22.1 ms]
Range (min … max): 72.0 ms … 73.2 ms 10 runs
Benchmark 3: ./git -C /run/user/1001/linux ls-tree -r HEAD' in 'avar/ls-tree-format
Time (mean ± σ): 67.6 ms ± 0.4 ms [User: 50.5 ms, System: 17.0 ms]
Range (min … max): 67.1 ms … 68.4 ms 10 runs
Summary
'./git -C /run/user/1001/linux ls-tree -r HEAD' in 'avar/ls-tree-format' ran
1.00 ± 0.01 times faster than './git -C /run/user/1001/linux ls-tree -r HEAD' in 'origin/master'
1.08 ± 0.01 times faster than './git -C /run/user/1001/linux ls-tree -r HEAD' in 'tl/object-name'
I then tacket a 6/6 at the end here to implement your --object-name in
terms of --format (but didn't update the comimt message etc.). That's
slower as expected:
$ git hyperfine -L rev tl/object-name,avar/ls-tree-format -s 'make CFLAGS=-O3' './git -C /run/user/1001/linux ls-tree --object-only -r HEAD' --warmup 10 -r 10
Benchmark 1: ./git -C /run/user/1001/linux ls-tree --object-only -r HEAD' in 'tl/object-name
Time (mean ± σ): 58.7 ms ± 0.4 ms [User: 43.0 ms, System: 15.6 ms]
Range (min … max): 58.4 ms … 59.6 ms 10 runs
Benchmark 2: ./git -C /run/user/1001/linux ls-tree --object-only -r HEAD' in 'avar/ls-tree-format
Time (mean ± σ): 65.6 ms ± 0.2 ms [User: 42.4 ms, System: 23.0 ms]
Range (min … max): 65.1 ms … 65.9 ms 10 runs
Summary
'./git -C /run/user/1001/linux ls-tree --object-only -r HEAD' in 'tl/object-name' ran
1.12 ± 0.01 times faster than './git -C /run/user/1001/linux ls-tree --object-only -r HEAD' in 'avar/ls-tree-format'
But it's not too bad, so maybe it's fine & worth making it more
generic?
Anyway. Just food for thought and and FYI in case you're
interested. Junio noted already that he'd like the --object-name
approach first, so if you still want to pursue your current
implementation I don't mind.
I do think you should be making performance testing a part of your
testing & cover letter writing though. A 8-10% slowdown isn't nothing,
especially for exactly the sort of plumbing command that'll likely to
be used to e.g. slurp up all paths in a very large repo.
These patches really aren't "ready". There's no docs, and as I noted
in some earlier thread the tests for ls-tree are really
lacking. E.g. I seem to have a rather obvious bug in how -t and the
--format interact here, but no test catches it.
Well, that one's me not having added a test, but I'm fairly sure there
might also be hidden bugs here due to lack of testing.
Teng Long (1):
ls-tree.c: support `--object-only` option for "git-ls-tree"
Ævar Arnfjörð Bjarmason (6):
ls-tree: remove commented-out code
ls-tree: add missing braces to "else" arms
ls-tree: use "enum object_type", not {blob,tree,commit}_type
ls-tree: use "size_t", not "int" for "struct strbuf"'s "len"
ls-tree: split up the "init" part of show_tree()
ls-tree: add a --format=<fmt> option
Documentation/git-ls-tree.txt | 7 +-
builtin/ls-tree.c | 226 ++++++++++++++++++++++++++++++----
t/t3103-ls-tree-misc.sh | 8 ++
t/t3104-ls-tree-oid.sh | 51 ++++++++
t/t3105-ls-tree-format.sh | 49 ++++++++
5 files changed, 313 insertions(+), 28 deletions(-)
create mode 100755 t/t3104-ls-tree-oid.sh
create mode 100755 t/t3105-ls-tree-format.sh
--
2.34.1.1119.g7a3fc8778ee
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-23 9:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23 9:50 [RFC PATCH 0/7] ls-tree --format Teng Long
-- strict thread matches above, loose matches on Subject: below --
2021-12-17 6:57 [PATCH v6 0/1] support `--object-only` option for "git-ls-tree" Teng Long
2021-12-17 13:30 ` [RFC PATCH 0/7] ls-tree --format Ævar Arnfjörð Bjarmason
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).