Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse Index: Integrate with merge, cherry-pick, rebase, and revert #1019

Commits on Sep 7, 2021

  1. diff: ignore sparse paths in diffstat

    The diff_populate_filespec() method is used to describe the diff after a
    merge operation is complete. In order to avoid expanding a sparse index,
    the reuse_worktree_file() needs to be adapted to ignore files that are
    outside of the sparse-checkout cone. The file names and OIDs used for
    this check come from the merged tree in the case of the ORT strategy,
    not the index, hence the ability to look into these paths without having
    already expanded the index.
    
    The work done by reuse_worktree_file() is only an optimization, and
    requires the file being on disk for it to be of any value. Thus, it is
    safe to exit the method early if we do not expect the file on disk.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Sep 7, 2021
    Configuration menu
    Copy the full SHA
    a696318 View commit details
    Browse the repository at this point in the history

Commits on Sep 8, 2021

  1. merge: make sparse-aware with ORT

    Allow 'git merge' to operate without expanding a sparse index, at least
    not immediately. The index still will be expanded in a few cases:
    
    1. If the merge strategy is 'recursive', then we enable
       command_requires_full_index at the start of the merge_recursive()
       method. We expect sparse-index users to also have the 'ort' strategy
       enabled.
    
    2. With the 'ort' strategy, if the merge results in a conflicted file,
       then we expand the index before updating the working tree. The loop
       that iterates over the worktree replaces index entries and tracks
       'origintal_cache_nr' which can become completely wrong if the index
       expands in the middle of the operation. This safety valve is
       important before that loop starts. A later change will focus this
       to only expand if we indeed have a conflict outside of the
       sparse-checkout cone.
    
    3. Other merge strategies are executed as a 'git merge-X' subcommand,
       and those strategies are currently protected with the
       'command_requires_full_index' guard.
    
    Some test updates are required, including a mistaken 'git checkout -b'
    that did not specify the base branch, causing merges to be fast-forward
    merges.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Sep 8, 2021
    Configuration menu
    Copy the full SHA
    141f7fb View commit details
    Browse the repository at this point in the history
  2. merge-ort: expand only for out-of-cone conflicts

    Merge conflicts happen often enough to want to avoid expanding a sparse
    index when they happen, as long as those conflicts are within the
    sparse-checkout cone. If a conflict exists outside of the
    sparse-checkout cone, then we still need to expand before iterating over
    the index entries. This is critical to do in advance because of how the
    original_cache_nr is tracked to allow inserting and replacing cache
    entries.
    
    Iterate over the conflicted files and check if any paths are outside of
    the sparse-checkout cone. If so, then expand the full index.
    
    Add a test that demonstrates that we do not expand the index, even when
    we hit a conflict within the sparse-checkout cone.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Sep 8, 2021
    Configuration menu
    Copy the full SHA
    c3c9ffd View commit details
    Browse the repository at this point in the history
  3. t1092: add cherry-pick, rebase tests

    Add tests to check that cherry-pick and rebase behave the same in the
    sparse-index case as in the full index cases. These tests are agnostic
    to GIT_TEST_MERGE_ALGORITHM, so a full CI test suite will check both the
    'ort' and 'recursive' strategies on this test.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Sep 8, 2021
    Configuration menu
    Copy the full SHA
    7aae572 View commit details
    Browse the repository at this point in the history
  4. sequencer: ensure full index if not ORT strategy

    The sequencer is used by 'cherry-pick' and 'rebase' to sequence a list
    of operations that modify the index. Since we intend to remove the need
    for 'command_requires_full_index', we need to ensure the sparse index is
    expanded every time it is written to disk between these steps. That is,
    unless the merge strategy is 'ort' where the index can remain sparse
    throughout.
    
    There are two main places to be extra careful about a full index:
    
    1. Right before calling merge_trees(), ensure the index is full. This
       happens within an 'else' where the 'if' block checks if the 'ort'
       strategy is selected.
    
    2. During read_and_refresh_cache(), the index might be written to disk
       and converted to sparse in the process. Ensure it expands back to
       full afterwards by checking if the strategy is _not_ 'ort'. This
       'if' statement is the logical negation of the 'if' in item (1).
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Sep 8, 2021
    Configuration menu
    Copy the full SHA
    20f5bba View commit details
    Browse the repository at this point in the history
  5. sparse-index: integrate with cherry-pick and rebase

    The hard work was already done with 'git merge' and the ORT strategy.
    Just add extra tests to see that we get the expected results in the
    non-conflict cases.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Sep 8, 2021
    Configuration menu
    Copy the full SHA
    36cecb2 View commit details
    Browse the repository at this point in the history