name-rev: deprecate --stdin in favor of --annotate-stdin

Introduce a --annotate-stdin that is functionally equivalent of --stdin. --stdin does not behave as --stdin in other subcommands, such as pack-objects whereby it takes one argument per line. Since --stdin can be a confusing and misleading name, rename it to --annotate-stdin. This change adds a warning to --stdin warning that it will be removed in the future. Signed-off-by: "John Cai" <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Cai committed Jan 5, 2022 at 23:29 UTC 34ae3b707146c05d27cf744e58f95a25a31b3499
8 files changed +67 -26
Documentation/git-name-rev.txt
+28 -2
@@ -42,11 +42,37 @@ OPTIONS
42 --all::
43 List all commits reachable from all refs
44
45 ---stdin::
45 +--annotate-stdin::
46 Transform stdin by substituting all the 40-character SHA-1
47 hexes (say $hex) with "$hex ($rev_name)". When used with
48 --name-only, substitute with "$rev_name", omitting $hex
49 - altogether. Intended for the scripter's use.
49 + altogether.
50 ++
51 +For example:
52 ++
53 +-----------
54 +$ cat sample.txt
55 +
56 +An abbreviated revision 2ae0a9cb82 will not be substituted.
57 +The full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907,
58 +while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad
59 +
60 +$ git name-rev --annotate-stdin <sample.txt
61 +
62 +An abbreviated revision 2ae0a9cb82 will not be substituted.
63 +The full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907 (master),
64 +while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad
65 +
66 +$ git name-rev --name-only --annotate-stdin <sample.txt
67 +
68 +An abbreviated revision 2ae0a9cb82 will not be substituted.
69 +The full name after substitution is master,
70 +while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad
71 +-----------
72 +
73 +--stdin::
74 + This option is deprecated in favor of 'git name-rev --annotate-stdin'.
75 + They are functionally equivalent.
76
77 --name-only::
78 Instead of printing both the SHA-1 and the name, print only
builtin/name-rev.c
+14 -5
@@ -527,7 +527,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
527 int cmd_name_rev(int argc, const char **argv, const char *prefix)
528 {
529 struct object_array revs = OBJECT_ARRAY_INIT;
530 - int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
530 + int all = 0, annotate_stdin = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
531 struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP };
532 struct option opts[] = {
533 OPT_BOOL(0, "name-only", &data.name_only, N_("print only ref-based names (no object names)")),
@@ -538,7 +538,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
538 N_("ignore refs matching <pattern>")),
539 OPT_GROUP(""),
540 OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),
541 - OPT_BOOL(0, "stdin", &transform_stdin, N_("read from stdin")),
541 + OPT_BOOL(0, "stdin", &transform_stdin, N_("deprecated: use annotate-stdin instead")),
542 + OPT_BOOL(0, "annotate-stdin", &annotate_stdin, N_("annotate text from stdin")),
543 OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
544 OPT_BOOL(0, "always", &always,
545 N_("show abbreviated commit object as fallback")),
@@ -554,11 +555,19 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
555 init_commit_rev_name(&rev_names);
556 git_config(git_default_config, NULL);
557 argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
557 - if (all + transform_stdin + !!argc > 1) {
558 +
559 + if (transform_stdin) {
560 + warning("--stdin is deprecated. Please use --annotate-stdin instead, "
561 + "which is functionally equivalent.\n"
562 + "This option will be removed in a future release.");
563 + annotate_stdin = 1;
564 + }
565 +
566 + if (all + annotate_stdin + !!argc > 1) {
567 error("Specify either a list, or --all, not both!");
568 usage_with_options(name_rev_usage, opts);
569 }
561 - if (all || transform_stdin)
570 + if (all || annotate_stdin)
571 cutoff = 0;
572
573 for (; argc; argc--, argv++) {
@@ -613,7 +622,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
622 for_each_ref(name_ref, &data);
623 name_tips();
624
616 - if (transform_stdin) {
625 + if (annotate_stdin) {
626 char buffer[2048];
627
628 while (!feof(stdin)) {
t/t3412-rebase-root.sh
+1 -1
@@ -11,7 +11,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
12 log_with_names () {
13 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
14 - git name-rev --stdin --name-only --refs=refs/heads/$1
14 + git name-rev --annotate-stdin --name-only --refs=refs/heads/$1
15 }
16
17
t/t4202-log.sh
+1 -1
@@ -659,7 +659,7 @@ EOF
659
660 test_expect_success 'log --graph with full output' '
661 git log --graph --date-order --pretty=short |
662 - git name-rev --name-only --stdin |
662 + git name-rev --name-only --annotate-stdin |
663 sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
664 test_cmp expect actual
665 '
t/t6007-rev-list-cherry-pick-file.sh
+13 -13
@@ -58,7 +58,7 @@ EOF
58
59 test_expect_success '--left-right' '
60 git rev-list --left-right B...C > actual &&
61 - git name-rev --stdin --name-only --refs="*tags/*" \
61 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
62 < actual > actual.named &&
63 test_cmp expect actual.named
64 '
@@ -78,14 +78,14 @@ EOF
78
79 test_expect_success '--cherry-pick bar does not come up empty' '
80 git rev-list --left-right --cherry-pick B...C -- bar > actual &&
81 - git name-rev --stdin --name-only --refs="*tags/*" \
81 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
82 < actual > actual.named &&
83 test_cmp expect actual.named
84 '
85
86 test_expect_success 'bar does not come up empty' '
87 git rev-list --left-right B...C -- bar > actual &&
88 - git name-rev --stdin --name-only --refs="*tags/*" \
88 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
89 < actual > actual.named &&
90 test_cmp expect actual.named
91 '
@@ -97,14 +97,14 @@ EOF
97
98 test_expect_success '--cherry-pick bar does not come up empty (II)' '
99 git rev-list --left-right --cherry-pick F...E -- bar > actual &&
100 - git name-rev --stdin --name-only --refs="*tags/*" \
100 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
101 < actual > actual.named &&
102 test_cmp expect actual.named
103 '
104
105 test_expect_success 'name-rev multiple --refs combine inclusive' '
106 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
107 - git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" \
107 + git name-rev --annotate-stdin --name-only --refs="*tags/F" --refs="*tags/E" \
108 <actual >actual.named &&
109 test_cmp expect actual.named
110 '
@@ -116,7 +116,7 @@ EOF
116 test_expect_success 'name-rev --refs excludes non-matched patterns' '
117 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
118 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
119 - git name-rev --stdin --name-only --refs="*tags/F" \
119 + git name-rev --annotate-stdin --name-only --refs="*tags/F" \
120 <actual >actual.named &&
121 test_cmp expect actual.named
122 '
@@ -128,14 +128,14 @@ EOF
128 test_expect_success 'name-rev --exclude excludes matched patterns' '
129 git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
130 git rev-list --left-right --cherry-pick F...E -- bar >actual &&
131 - git name-rev --stdin --name-only --refs="*tags/*" --exclude="*E" \
131 + git name-rev --annotate-stdin --name-only --refs="*tags/*" --exclude="*E" \
132 <actual >actual.named &&
133 test_cmp expect actual.named
134 '
135
136 test_expect_success 'name-rev --no-refs clears the refs list' '
137 git rev-list --left-right --cherry-pick F...E -- bar >expect &&
138 - git name-rev --stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
138 + git name-rev --annotate-stdin --name-only --refs="*tags/F" --refs="*tags/E" --no-refs --refs="*tags/G" \
139 <expect >actual &&
140 test_cmp expect actual
141 '
@@ -149,7 +149,7 @@ EOF
149
150 test_expect_success '--cherry-mark' '
151 git rev-list --cherry-mark F...E -- bar > actual &&
152 - git name-rev --stdin --name-only --refs="*tags/*" \
152 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
153 < actual > actual.named &&
154 test_cmp expect actual.named
155 '
@@ -163,7 +163,7 @@ EOF
163
164 test_expect_success '--cherry-mark --left-right' '
165 git rev-list --cherry-mark --left-right F...E -- bar > actual &&
166 - git name-rev --stdin --name-only --refs="*tags/*" \
166 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
167 < actual > actual.named &&
168 test_cmp expect actual.named
169 '
@@ -174,14 +174,14 @@ EOF
174
175 test_expect_success '--cherry-pick --right-only' '
176 git rev-list --cherry-pick --right-only F...E -- bar > actual &&
177 - git name-rev --stdin --name-only --refs="*tags/*" \
177 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
178 < actual > actual.named &&
179 test_cmp expect actual.named
180 '
181
182 test_expect_success '--cherry-pick --left-only' '
183 git rev-list --cherry-pick --left-only E...F -- bar > actual &&
184 - git name-rev --stdin --name-only --refs="*tags/*" \
184 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
185 < actual > actual.named &&
186 test_cmp expect actual.named
187 '
@@ -193,7 +193,7 @@ EOF
193
194 test_expect_success '--cherry' '
195 git rev-list --cherry F...E -- bar > actual &&
196 - git name-rev --stdin --name-only --refs="*tags/*" \
196 + git name-rev --annotate-stdin --name-only --refs="*tags/*" \
197 < actual > actual.named &&
198 test_cmp expect actual.named
199 '
t/t6012-rev-list-simplify.sh
+1 -1
@@ -12,7 +12,7 @@ note () {
12 }
13
14 unnote () {
15 - git name-rev --tags --stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g"
15 + git name-rev --tags --annotate-stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g"
16 }
17
18 #
t/t6111-rev-list-treesame.sh
+2 -1
@@ -23,7 +23,8 @@ note () {
23 }
24
25 unnote () {
26 - git name-rev --tags --stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\))\([ ]\)|\1\2|g"
26 + git name-rev --tags --annotate-stdin | \
27 + sed -e "s|$OID_REGEX (tags/\([^)]*\))\([ ]\)|\1\2|g"
28 }
29
30 test_expect_success setup '
t/t6120-describe.sh
+7 -2
@@ -270,7 +270,7 @@ test_expect_success 'name-rev --all' '
270 test_cmp expect actual
271 '
272
273 -test_expect_success 'name-rev --stdin' '
273 +test_expect_success 'name-rev --annotate-stdin' '
274 >expect.unsorted &&
275 for rev in $(git rev-list --all)
276 do
@@ -278,11 +278,16 @@ test_expect_success 'name-rev --stdin' '
278 echo "$rev ($name)" >>expect.unsorted
279 done &&
280 sort <expect.unsorted >expect &&
281 - git rev-list --all | git name-rev --stdin >actual.unsorted &&
281 + git rev-list --all | git name-rev --annotate-stdin >actual.unsorted &&
282 sort <actual.unsorted >actual &&
283 test_cmp expect actual
284 '
285
286 +test_expect_success 'name-rev --stdin deprecated' "
287 + git rev-list --all | git name-rev --stdin 2>actual &&
288 + grep -E 'warning: --stdin is deprecated' actual
289 +"
290 +
291 test_expect_success 'describe --contains with the exact tags' '
292 echo "A^0" >expect &&
293 tag_object=$(git rev-parse refs/tags/A) &&