]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/files: sort reflogs returned by the reflog iterator
authorPatrick Steinhardt <ps@pks.im>
Wed, 21 Feb 2024 12:37:27 +0000 (13:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Feb 2024 17:58:05 +0000 (09:58 -0800)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c
t/t0600-reffiles-backend.sh
t/t1405-main-ref-store.sh
t/t1406-submodule-ref-store.sh

index 75dcc21ecb5ab83cadd37a899a252618a0c66df0..2ffc63185f82348a18a2a6651bf324e68b961e54 100644 (file)
@@ -2193,7 +2193,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
 
        strbuf_addf(&sb, "%s/logs", gitdir);
 
-       diter = dir_iterator_begin(sb.buf, 0);
+       diter = dir_iterator_begin(sb.buf, DIR_ITERATOR_SORTED);
        if (!diter) {
                strbuf_release(&sb);
                return empty_ref_iterator_begin();
@@ -2202,7 +2202,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
        CALLOC_ARRAY(iter, 1);
        ref_iterator = &iter->base;
 
-       base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 0);
+       base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 1);
        iter->dir_iterator = diter;
        iter->ref_store = ref_store;
        strbuf_release(&sb);
index e6a5f1868f917d01b791dbed2a5afce2b1965fca..4f860285cce8de99f494b9c10f3e08b8c480ba4b 100755 (executable)
@@ -287,7 +287,7 @@ test_expect_success 'for_each_reflog()' '
        mkdir -p     .git/worktrees/wt/logs/refs/bisect &&
        echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random &&
 
-       $RWT for-each-reflog | cut -d" " -f 2- | sort >actual &&
+       $RWT for-each-reflog | cut -d" " -f 2- >actual &&
        cat >expected <<-\EOF &&
        HEAD 0x1
        PSEUDO-WT 0x0
@@ -297,7 +297,7 @@ test_expect_success 'for_each_reflog()' '
        EOF
        test_cmp expected actual &&
 
-       $RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual &&
+       $RMAIN for-each-reflog | cut -d" " -f 2- >actual &&
        cat >expected <<-\EOF &&
        HEAD 0x1
        PSEUDO-MAIN 0x0
index 976bd71efb561d7a374b801ef087edc51f8de01a..cfb583f54499e60108ed98d3b54a5925356b522b 100755 (executable)
@@ -74,7 +74,7 @@ test_expect_success 'verify_ref(new-main)' '
 '
 
 test_expect_success 'for_each_reflog()' '
-       $RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
+       $RUN for-each-reflog | cut -d" " -f 2- >actual &&
        cat >expected <<-\EOF &&
        HEAD 0x1
        refs/heads/main 0x0
index e6a7f7334b6a96e4aa310532c8dc7d6c727fdd16..40332e23cc43b338b0d8d8c729f230603649233b 100755 (executable)
@@ -63,7 +63,7 @@ test_expect_success 'verify_ref(new-main)' '
 '
 
 test_expect_success 'for_each_reflog()' '
-       $RUN for-each-reflog | sort | cut -d" " -f 2- >actual &&
+       $RUN for-each-reflog | cut -d" " -f 2- >actual &&
        cat >expected <<-\EOF &&
        HEAD 0x1
        refs/heads/main 0x0