• Show log

    Commit

  • Hash : 70f8f24d
    Author : Stefan Sperling
    Date : 2022-04-14T15:05:19

    speed up initial stage of packing by adding a "skip" commit color
    
    The skip color marks boundary commits and their ancestors. Boundary commits
    are reachable both via references which we want to exclude from the pack,
    and via references which we want to include in the pack.
    We continue processing commit history up to the point we are left with only
    skip commits on the queue.  This can speed up findtwixt() significantly and
    avoids wrong results produced by the old algorithm which made no distinction
    between "drop" and "skip".
    
    This idea was first implemented by Michael Forney for git9:
    https://git.9front.org/plan9front/plan9front/2e47badb88312c5c045a8042dc2ef80148e5ab47/commit.html
    Michael's log message for git9 is reproduced below:
    
    git/query: refactor graph painting algorithm (findtwixt, lca)
    
    We now keep track of 3 sets during traversal:
    - keep: commits we've reached from head commits
    - drop: commits we've reached from tail commits
    - skip: ancestors of commits in both 'keep' and 'drop'
    
    Commits in 'keep' and/or 'drop' may be added later to the 'skip' set
    if we discover later that they are part of a common subgraph of the
    head and tail commits.
    
    From these sets we can calculate the commits we are interested in:
    lca commits are those in 'keep' and 'drop', but not in 'skip'.
    findtwixt commits are those in 'keep', but not in 'drop' or 'skip'.
    
    The "LCA" commit returned is a common ancestor such that there are no
    other common ancestors that can reach that commit.  Although there can
    be multiple commits that meet this criteria, where one is technically
    lower on the commit-graph than the other, these cases only happen in
    complex merge arrangements and any choice is likely a decent merge
    base.
    
    Repainting is now done in paint() directly.  When we find a boundary
    commit, we switch our paint color to 'skip'.  'skip' painting does
    not stop when it hits another color; we continue until we are left
    with only 'skip' commits on the queue.
    
    This fixes several mishandled cases in the current algorithm:
    1. If we hit the common subgraph from tail commits first (if the tail
       commit was newer than the head commit), we ended up traversing the
       entire commit graph.  This is because we couldn't distinguish
       between 'drop' commits that were part of the common subgraph, and
       those that were still looking for it.
    2. If we traversed through an initial part of the common subgraph from
       head commits before reaching it from tail commits, these commits
       were returned from findtwixt even though they were also reachable
       from tail commits.
    3. In the same case as 2, we might end up choosing an incorrect
       commit as the LCA, which is an ancestor of the real LCA.