Skip to content

Commit 34ae3b7

Browse files
john-caigitster
authored andcommitted
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" <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ae0a9c commit 34ae3b7

File tree

8 files changed

+67
-26
lines changed

8 files changed

+67
-26
lines changed

Documentation/git-name-rev.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,37 @@ OPTIONS
4242
--all::
4343
List all commits reachable from all refs
4444

45-
--stdin::
45+
--annotate-stdin::
4646
Transform stdin by substituting all the 40-character SHA-1
4747
hexes (say $hex) with "$hex ($rev_name)". When used with
4848
--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.
5076

5177
--name-only::
5278
Instead of printing both the SHA-1 and the name, print only

builtin/name-rev.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
527527
int cmd_name_rev(int argc, const char **argv, const char *prefix)
528528
{
529529
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;
531531
struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP };
532532
struct option opts[] = {
533533
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)
538538
N_("ignore refs matching <pattern>")),
539539
OPT_GROUP(""),
540540
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")),
542543
OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
543544
OPT_BOOL(0, "always", &always,
544545
N_("show abbreviated commit object as fallback")),
@@ -554,11 +555,19 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
554555
init_commit_rev_name(&rev_names);
555556
git_config(git_default_config, NULL);
556557
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) {
558567
error("Specify either a list, or --all, not both!");
559568
usage_with_options(name_rev_usage, opts);
560569
}
561-
if (all || transform_stdin)
570+
if (all || annotate_stdin)
562571
cutoff = 0;
563572

564573
for (; argc; argc--, argv++) {
@@ -613,7 +622,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
613622
for_each_ref(name_ref, &data);
614623
name_tips();
615624

616-
if (transform_stdin) {
625+
if (annotate_stdin) {
617626
char buffer[2048];
618627

619628
while (!feof(stdin)) {

t/t3412-rebase-root.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1111

1212
log_with_names () {
1313
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
1515
}
1616

1717

t/t4202-log.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ EOF
659659

660660
test_expect_success 'log --graph with full output' '
661661
git log --graph --date-order --pretty=short |
662-
git name-rev --name-only --stdin |
662+
git name-rev --name-only --annotate-stdin |
663663
sed "s/Merge:.*/Merge: A B/;s/ *\$//" >actual &&
664664
test_cmp expect actual
665665
'

t/t6007-rev-list-cherry-pick-file.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ EOF
5858

5959
test_expect_success '--left-right' '
6060
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/*" \
6262
< actual > actual.named &&
6363
test_cmp expect actual.named
6464
'
@@ -78,14 +78,14 @@ EOF
7878

7979
test_expect_success '--cherry-pick bar does not come up empty' '
8080
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/*" \
8282
< actual > actual.named &&
8383
test_cmp expect actual.named
8484
'
8585

8686
test_expect_success 'bar does not come up empty' '
8787
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/*" \
8989
< actual > actual.named &&
9090
test_cmp expect actual.named
9191
'
@@ -97,14 +97,14 @@ EOF
9797

9898
test_expect_success '--cherry-pick bar does not come up empty (II)' '
9999
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/*" \
101101
< actual > actual.named &&
102102
test_cmp expect actual.named
103103
'
104104

105105
test_expect_success 'name-rev multiple --refs combine inclusive' '
106106
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" \
108108
<actual >actual.named &&
109109
test_cmp expect actual.named
110110
'
@@ -116,7 +116,7 @@ EOF
116116
test_expect_success 'name-rev --refs excludes non-matched patterns' '
117117
git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
118118
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" \
120120
<actual >actual.named &&
121121
test_cmp expect actual.named
122122
'
@@ -128,14 +128,14 @@ EOF
128128
test_expect_success 'name-rev --exclude excludes matched patterns' '
129129
git rev-list --left-right --right-only --cherry-pick F...E -- bar >>expect &&
130130
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" \
132132
<actual >actual.named &&
133133
test_cmp expect actual.named
134134
'
135135

136136
test_expect_success 'name-rev --no-refs clears the refs list' '
137137
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" \
139139
<expect >actual &&
140140
test_cmp expect actual
141141
'
@@ -149,7 +149,7 @@ EOF
149149

150150
test_expect_success '--cherry-mark' '
151151
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/*" \
153153
< actual > actual.named &&
154154
test_cmp expect actual.named
155155
'
@@ -163,7 +163,7 @@ EOF
163163

164164
test_expect_success '--cherry-mark --left-right' '
165165
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/*" \
167167
< actual > actual.named &&
168168
test_cmp expect actual.named
169169
'
@@ -174,14 +174,14 @@ EOF
174174

175175
test_expect_success '--cherry-pick --right-only' '
176176
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/*" \
178178
< actual > actual.named &&
179179
test_cmp expect actual.named
180180
'
181181

182182
test_expect_success '--cherry-pick --left-only' '
183183
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/*" \
185185
< actual > actual.named &&
186186
test_cmp expect actual.named
187187
'
@@ -193,7 +193,7 @@ EOF
193193

194194
test_expect_success '--cherry' '
195195
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/*" \
197197
< actual > actual.named &&
198198
test_cmp expect actual.named
199199
'

t/t6012-rev-list-simplify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note () {
1212
}
1313

1414
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"
1616
}
1717

1818
#

t/t6111-rev-list-treesame.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ note () {
2323
}
2424

2525
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"
2728
}
2829

2930
test_expect_success setup '

t/t6120-describe.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,24 @@ test_expect_success 'name-rev --all' '
270270
test_cmp expect actual
271271
'
272272

273-
test_expect_success 'name-rev --stdin' '
273+
test_expect_success 'name-rev --annotate-stdin' '
274274
>expect.unsorted &&
275275
for rev in $(git rev-list --all)
276276
do
277277
name=$(git name-rev --name-only $rev) &&
278278
echo "$rev ($name)" >>expect.unsorted
279279
done &&
280280
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 &&
282282
sort <actual.unsorted >actual &&
283283
test_cmp expect actual
284284
'
285285

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+
286291
test_expect_success 'describe --contains with the exact tags' '
287292
echo "A^0" >expect &&
288293
tag_object=$(git rev-parse refs/tags/A) &&

0 commit comments

Comments
 (0)