Skip to content

Commit e69e8ff

Browse files
pks-tgitster
authored andcommitted
refs/files: sort reflogs returned by the reflog iterator
We use a directory iterator to return reflogs via the reflog iterator. This iterator returns entries in the same order as readdir(3P) would and will thus yield reflogs with no discernible order. Set the new `DIR_ITERATOR_SORTED` flag that was introduced in the preceding commit so that the order is deterministic. While the effect of this can only been observed in a test tool, a subsequent commit will start to expose this functionality to users via a new `git reflog list` subcommand. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de34f26 commit e69e8ff

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

refs/files-backend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
21932193

21942194
strbuf_addf(&sb, "%s/logs", gitdir);
21952195

2196-
diter = dir_iterator_begin(sb.buf, 0);
2196+
diter = dir_iterator_begin(sb.buf, DIR_ITERATOR_SORTED);
21972197
if (!diter) {
21982198
strbuf_release(&sb);
21992199
return empty_ref_iterator_begin();
@@ -2202,7 +2202,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
22022202
CALLOC_ARRAY(iter, 1);
22032203
ref_iterator = &iter->base;
22042204

2205-
base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 0);
2205+
base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 1);
22062206
iter->dir_iterator = diter;
22072207
iter->ref_store = ref_store;
22082208
strbuf_release(&sb);

t/t0600-reffiles-backend.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ test_expect_success 'for_each_reflog()' '
287287
mkdir -p .git/worktrees/wt/logs/refs/bisect &&
288288
echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random &&
289289
290-
$RWT for-each-reflog | cut -d" " -f 2- | sort >actual &&
290+
$RWT for-each-reflog | cut -d" " -f 2- >actual &&
291291
cat >expected <<-\EOF &&
292292
HEAD 0x1
293293
PSEUDO-WT 0x0
@@ -297,7 +297,7 @@ test_expect_success 'for_each_reflog()' '
297297
EOF
298298
test_cmp expected actual &&
299299
300-
$RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual &&
300+
$RMAIN for-each-reflog | cut -d" " -f 2- >actual &&
301301
cat >expected <<-\EOF &&
302302
HEAD 0x1
303303
PSEUDO-MAIN 0x0

t/t1405-main-ref-store.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test_expect_success 'verify_ref(new-main)' '
7474
'
7575

7676
test_expect_success 'for_each_reflog()' '
77-
$RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
77+
$RUN for-each-reflog | cut -d" " -f 2- >actual &&
7878
cat >expected <<-\EOF &&
7979
HEAD 0x1
8080
refs/heads/main 0x0

t/t1406-submodule-ref-store.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_expect_success 'verify_ref(new-main)' '
6363
'
6464

6565
test_expect_success 'for_each_reflog()' '
66-
$RUN for-each-reflog | sort | cut -d" " -f 2- >actual &&
66+
$RUN for-each-reflog | cut -d" " -f 2- >actual &&
6767
cat >expected <<-\EOF &&
6868
HEAD 0x1
6969
refs/heads/main 0x0

0 commit comments

Comments
 (0)