Skip to content

Commit 44a6b6c

Browse files
committed
ref-filter: resurrect "strip" as a synonym to "lstrip"
We forgot that "strip" was introduced at 0571979 ("tag: do not show ambiguous tag names as "tags/foo"", 2016-01-25) as part of Git 2.8 (and 2.7.1) when we started calling this "lstrip" to make it easier to explain the new "rstrip" operation. We shouldn't have renamed the existing one; "lstrip" should have been a new synonym that means the same thing as "strip". Scripts in the wild are surely using the original form already. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d9e4ce commit 44a6b6c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Documentation/git-for-each-ref.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ refname::
107107
enough components, the result becomes an empty string if
108108
stripping with positive <N>, or it becomes the full refname if
109109
stripping with negative <N>. Neither is an error.
110+
+
111+
`strip` can be used as a synomym to `lstrip`.
110112

111113
objecttype::
112114
The type of the object (`blob`, `tree`, `commit`, `tag`).

ref-filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ static void refname_atom_parser_internal(struct refname_atom *atom,
112112
atom->option = R_NORMAL;
113113
else if (!strcmp(arg, "short"))
114114
atom->option = R_SHORT;
115-
else if (skip_prefix(arg, "lstrip=", &arg)) {
115+
else if (skip_prefix(arg, "lstrip=", &arg) ||
116+
skip_prefix(arg, "strip=", &arg)) {
116117
atom->option = R_LSTRIP;
117118
if (strtol_i(arg, 10, &atom->lstrip))
118119
die(_("Integer value expected refname:lstrip=%s"), arg);

t/t6300-for-each-ref.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,26 @@ test_atom head refname:rstrip=1 refs/heads
5959
test_atom head refname:rstrip=2 refs
6060
test_atom head refname:rstrip=-1 refs
6161
test_atom head refname:rstrip=-2 refs/heads
62+
test_atom head refname:strip=1 heads/master
63+
test_atom head refname:strip=2 master
64+
test_atom head refname:strip=-1 master
65+
test_atom head refname:strip=-2 heads/master
6266
test_atom head upstream refs/remotes/origin/master
6367
test_atom head upstream:short origin/master
6468
test_atom head upstream:lstrip=2 origin/master
6569
test_atom head upstream:lstrip=-2 origin/master
6670
test_atom head upstream:rstrip=2 refs/remotes
6771
test_atom head upstream:rstrip=-2 refs/remotes
72+
test_atom head upstream:strip=2 origin/master
73+
test_atom head upstream:strip=-2 origin/master
6874
test_atom head push refs/remotes/myfork/master
6975
test_atom head push:short myfork/master
7076
test_atom head push:lstrip=1 remotes/myfork/master
7177
test_atom head push:lstrip=-1 master
7278
test_atom head push:rstrip=1 refs/remotes/myfork
7379
test_atom head push:rstrip=-1 refs
80+
test_atom head push:strip=1 remotes/myfork/master
81+
test_atom head push:strip=-1 master
7482
test_atom head objecttype commit
7583
test_atom head objectsize 171
7684
test_atom head objectname $(git rev-parse refs/heads/master)
@@ -636,6 +644,10 @@ EOF
636644
test_expect_success 'Verify usage of %(symref:lstrip) atom' '
637645
git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
638646
git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
647+
test_cmp expected actual &&
648+
649+
git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
650+
git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
639651
test_cmp expected actual
640652
'
641653

0 commit comments

Comments
 (0)