Skip to content

Regression of revwalk behavior  #2182

Closed

Description

@nulltoken

Relates to libgit2/libgit2sharp#612 (comment)

Against the testrepo.git test repository

$ git rev-list br2 master e908
a65fedf39aefe402d3bb6e24df4d4f5fe4547750
e90810b8df3e80c413d903f631643c716887138d
6dcf9bf7541ee10456529833502442f385010c3d
a4a7dce85cf63874e984719f4fdd239f5145052f
be3563ae3f795b2b4353bcce3a527ad0a4f7f644
c47800c7266a2be04c571c04d5a6614691ea99bd
9fd738e8f7967c078dceed8190330fc8648ee56a
4a202b346bb0fb0db7eff3cffeb3c70babbd2045
5b5b025afb0b4c913b4c338a42934a3863bf3644
8496071c1b46c854b31185ea97743be6a8774479

The test (see below) pass, when applied on top of 65e9dc6 and produces the following output

a65fedf39aefe402d3bb6e24df4d4f5fe4547750
e90810b8df3e80c413d903f631643c716887138d
6dcf9bf7541ee10456529833502442f385010c3d
a4a7dce85cf63874e984719f4fdd239f5145052f
be3563ae3f795b2b4353bcce3a527ad0a4f7f644
c47800c7266a2be04c571c04d5a6614691ea99bd
9fd738e8f7967c078dceed8190330fc8648ee56a
4a202b346bb0fb0db7eff3cffeb3c70babbd2045
5b5b025afb0b4c913b4c338a42934a3863bf3644
8496071c1b46c854b31185ea97743be6a8774479

However, when applied on the latest tip (9af1488), it fails, the revwalk outputting the commits in the following order

a65fedf39aefe402d3bb6e24df4d4f5fe4547750
a4a7dce85cf63874e984719f4fdd239f5145052f
e90810b8df3e80c413d903f631643c716887138d
6dcf9bf7541ee10456529833502442f385010c3d
be3563ae3f795b2b4353bcce3a527ad0a4f7f644
9fd738e8f7967c078dceed8190330fc8648ee56a
c47800c7266a2be04c571c04d5a6614691ea99bd
4a202b346bb0fb0db7eff3cffeb3c70babbd2045
5b5b025afb0b4c913b4c338a42934a3863bf3644
8496071c1b46c854b31185ea97743be6a8774479
diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c
index 9fe8a35..77ef7ca 100644
--- a/tests/revwalk/basic.c
+++ b/tests/revwalk/basic.c
@@ -290,3 +290,79 @@ void test_revwalk_basic__push_all(void)
    /* git rev-list --count --all #=> 15 */
    cl_assert_equal_i(15, i);
 }
+
+
+static void dump(const git_oid *oid)
+{
+   char str[41];
+   git_oid_fmt(str, oid);
+   str[40] = 0;
+   printf("%s\n", str);
+}
+/*
+* $ git rev-list br2 master e908
+* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+* e90810b8df3e80c413d903f631643c716887138d
+* 6dcf9bf7541ee10456529833502442f385010c3d
+* a4a7dce85cf63874e984719f4fdd239f5145052f
+* be3563ae3f795b2b4353bcce3a527ad0a4f7f644
+* c47800c7266a2be04c571c04d5a6614691ea99bd
+* 9fd738e8f7967c078dceed8190330fc8648ee56a
+* 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
+* 5b5b025afb0b4c913b4c338a42934a3863bf3644
+* 8496071c1b46c854b31185ea97743be6a8774479
+*/
+void test_revwalk_basic__mimic_git_rev_list(void)
+{
+   git_oid oid;
+
+   revwalk_basic_setup_walk(NULL);
+   git_revwalk_sorting(_walk, GIT_SORT_TIME);
+
+   cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/br2"));
+   cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/master"));
+   cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
+   cl_git_pass(git_revwalk_push(_walk, &oid));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "6dcf9bf7541ee10456529833502442f385010c3d"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //  cl_assert_equal_i(0, git_oid_streq(&oid, "a4a7dce85cf63874e984719f4fdd239f5145052f"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //  cl_assert_equal_i(0, git_oid_streq(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
+
+   cl_git_pass(git_revwalk_next(&oid, _walk));
+   dump(&oid);
+   //cl_assert_equal_i(0, git_oid_streq(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
+
+   cl_git_fail_with(git_revwalk_next(&oid, _walk), GIT_ITEROVER);
+}

Activity

  1. nulltoken commented on Mar 11, 2014

    @nulltoken
    MemberAuthor
  2. nulltoken commented on Mar 12, 2014

    @nulltoken
    MemberAuthor
    $ git bisect bad
    4075e060b45a73834a24684ed835d52f7176d58b is the first bad commit
    commit 4075e060b45a73834a24684ed835d52f7176d58b
    Author: Russell Belfer <[email protected]>
    Date:   Mon Feb 3 21:02:08 2014 -0800
    
        Replace pqueue with code from hashsig heap
    
        I accidentally wrote a separate priority queue implementation when
        I was working on file rename detection as part of the file hash
        signature calculation code.  To simplify licensing terms, I just
        adapted that to a general purpose priority queue and replace the
        old priority queue implementation that was borrowed from elsewhere.
    
        This also removes parts of the COPYING document that no longer
        apply to libgit2.
    

    @arrbee It looks like this is linked to the pqueue change. Do you think you could give a peek a this?

  3. arrbee commented on Mar 12, 2014

    @arrbee
    Member

    Sure, I'll take a look.

  4. nulltoken commented on Mar 12, 2014

    @nulltoken
    MemberAuthor

    @arrbee 💖

  5. arrbee commented on Mar 12, 2014

    @arrbee
    Member

    Okay, I've written a super simple test that just directly uses git_pqueue and pushes and pops in the same order that the revwalker would and replicates this problem. By taking the rev walker out of the picture, it will hopefully make this a lot simpler to diagnose.

  6. arrbee commented on Mar 12, 2014

    @arrbee
    Member

    Okay, I think I've found the problem. There is a place where the new pqueue uses a < and should use a <=.

    This bug snuck in because the element comparison function I used in the pqueue tests is "complete" (i.e. it explicitly returns -1, 0, or 1 for all variants) whereas the TIMESORT comparison function is one-sided (i.e. it just returns a < b and so it will only ever return 0 or 1).

    Fix to follow shortly once I make sure it all looks good.

  7. nulltoken commented on Mar 12, 2014

    @nulltoken
    MemberAuthor

    Closed with #2184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions