Skip to content

Commit 10be1c4

Browse files
committed
Merge branch 'kn/for-each-ref-skip-updates'
Code clean-up. * kn/for-each-ref-skip-updates: ref-filter: use REF_ITERATOR_SEEK_SET_PREFIX instead of '1' t6302: add test combining '--start-after' with '--exclude' for-each-ref: reword the documentation for '--start-after' for-each-ref: fix documentation argument ordering ref-cache: use 'size_t' instead of int for length
2 parents 0dc39a6 + 444ad14 commit 10be1c4

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

Documentation/git-for-each-ref.adoc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ git-for-each-ref - Output information on each ref
77

88
SYNOPSIS
99
--------
10-
[verse]
11-
'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
10+
[synopsis]
11+
git for-each-ref [--count=<count>] [--shell|--perl|--python|--tcl]
1212
[(--sort=<key>)...] [--format=<format>]
13-
[--include-root-refs] [ --stdin | <pattern>... ]
14-
[--points-at=<object>]
13+
[--include-root-refs] [--points-at=<object>]
1514
[--merged[=<object>]] [--no-merged[=<object>]]
1615
[--contains[=<object>]] [--no-contains[=<object>]]
17-
[--exclude=<pattern> ...] [--start-after=<marker>]
16+
[(--exclude=<pattern>)...] [--start-after=<marker>]
17+
[ --stdin | <pattern>... ]
1818

1919
DESCRIPTION
2020
-----------
@@ -114,7 +114,8 @@ TAB %(refname)`.
114114
deleted, modified or added between invocations. Output will only yield those
115115
references which follow the marker lexicographically. Output begins from the
116116
first reference that would come after the marker alphabetically. Cannot be
117-
used with general pattern matching or custom sort options.
117+
used with `--sort=<key>` or `--stdin` options, or the _<pattern>_ argument(s)
118+
to limit the refs.
118119

119120
FIELD NAMES
120121
-----------

builtin/for-each-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int cmd_for_each_ref(int argc,
4545
OPT_GROUP(""),
4646
OPT_INTEGER( 0 , "count", &format.array_opts.max_count, N_("show only <n> matched refs")),
4747
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
48-
OPT_STRING( 0 , "start-after", &filter.start_after, N_("start-start"), N_("start iteration after the provided marker")),
48+
OPT_STRING( 0 , "start-after", &filter.start_after, N_("start-after"), N_("start iteration after the provided marker")),
4949
OPT__COLOR(&format.use_color, N_("respect format colors")),
5050
OPT_REF_FILTER_EXCLUDE(&filter),
5151
OPT_REF_SORT(&sorting_options),

ref-filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3254,8 +3254,9 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref
32543254

32553255
if (filter->start_after)
32563256
ret = start_ref_iterator_after(iter, filter->start_after);
3257-
else if (prefix)
3258-
ret = ref_iterator_seek(iter, prefix, 1);
3257+
else
3258+
ret = ref_iterator_seek(iter, prefix,
3259+
REF_ITERATOR_SEEK_SET_PREFIX);
32593260

32603261
if (!ret)
32613262
ret = do_for_each_ref_iterator(iter, fn, cb_data);

refs/ref-cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,14 @@ static int cache_ref_iterator_seek(struct ref_iterator *ref_iterator,
498498
* indexing to each level as needed.
499499
*/
500500
do {
501-
int len, idx;
501+
int idx;
502+
size_t len;
502503
int cmp = 0;
503504

504505
sort_ref_dir(dir);
505506

506507
slash = strchr(slash, '/');
507-
len = slash ? slash - refname : (int)strlen(refname);
508+
len = slash ? (size_t)(slash - refname) : strlen(refname);
508509

509510
for (idx = 0; idx < dir->nr; idx++) {
510511
cmp = strncmp(refname, dir->entries[idx]->name, len);

t/t6302-for-each-ref-filter.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,25 @@ test_expect_success 'start after, overflow specific reference path' '
712712
test_cmp expect actual
713713
'
714714

715+
test_expect_success 'start after, with exclude pattern' '
716+
cat >expect <<-\EOF &&
717+
refs/tags/annotated-tag
718+
refs/tags/doubly-annotated-tag
719+
refs/tags/doubly-signed-tag
720+
refs/tags/foo1.10
721+
refs/tags/foo1.3
722+
refs/tags/foo1.6
723+
refs/tags/four
724+
refs/tags/one
725+
refs/tags/signed-tag
726+
refs/tags/three
727+
refs/tags/two
728+
EOF
729+
git for-each-ref --format="%(refname)" --start-after=refs/odd/spot \
730+
--exclude=refs/tags/foo >actual &&
731+
test_cmp expect actual
732+
'
733+
715734
test_expect_success 'start after, last reference' '
716735
cat >expect <<-\EOF &&
717736
EOF

0 commit comments

Comments
 (0)