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: fix a checkout bug with deep sparse-checkout paths #473

Commits on Dec 4, 2021

  1. t1092: add deeper changes during a checkout

    Extend the repository data in the setup of t1092 to include more
    directories within two parent directories. This reproduces a bug found
    by users of the sparse index feature with suitably-complicated
    sparse-checkout definitions.
    
    Add a failing test that fails in its first 'git checkout deepest' run in
    the sparse index case with this error:
    
      error: Your local changes to the following files would be overwritten by checkout:
              deep/deeper1/deepest2/a
              deep/deeper1/deepest3/a
      Please commit your changes or stash them before you switch branches.
      Aborting
    
    The next change will fix this error, and that fix will make it clear why
    the extra depth is necessary for revealing this bug. The assignment of
    the sparse-checkout definition to include deep/deeper1/deepest as a
    sibling directory is important to ensure that deep/deeper1 is not a
    sparse directory entry, but deep/deeper1/deepest2 is.
    
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Dec 4, 2021
    Configuration menu
    Copy the full SHA
    10b29a0 View commit details
    Browse the repository at this point in the history

Commits on Dec 6, 2021

  1. unpack-trees: use traverse_path instead of name

    The sparse_dir_matches_path() method compares a cache entry that is a
    sparse directory entry against a 'struct traverse_info *info' and a
    'struct name_entry *p' to see if the cache entry has exactly the right
    name for those other inputs.
    
    This method was introduced in 523506d (unpack-trees: unpack sparse
    directory entries, 2021-07-14), but included a significant mistake. The
    path comparisons used 'info->name' instead of 'info->traverse_path'.
    Since 'info->name' only stores a single tree entry name while
    'info->traverse_path' stores the full path from root, this method does
    not work when 'info' is in a subdirectory of a directory. Replacing the
    right strings and their corresponding lengths make the method work
    properly.
    
    The previous change included a failing test that exposes this issue.
    That test now passes. The critical detail is that as we go deep into
    unpack_trees(), the logic for merging a sparse directory entry with a
    tree entry during 'git checkout' relies on this
    sparse_dir_matches_path() in order to avoid calling
    traverse_trees_recursive() during unpack_callback() in this hunk:
    
    	if (!is_sparse_directory_entry(src[0], names, info) &&
    	    traverse_trees_recursive(n, dirmask, mask & ~dirmask,
    					    names, info) < 0) {
    		return -1;
    	}
    
    For deep paths, the short-circuit never occurred and
    traverse_trees_recursive() was being called incorrectly and that was
    causing other strange issues. Specifically, the error message from the
    now-passing test previously included this:
    
          error: Your local changes to the following files would be overwritten by checkout:
                  deep/deeper1/deepest2/a
                  deep/deeper1/deepest3/a
          Please commit your changes or stash them before you switch branches.
          Aborting
    
    These messages occurred because the 'current' cache entry in
    twoway_merge() was showing as NULL because the index did not contain
    entries for the paths contained within the sparse directory entries. We
    instead had 'oldtree' given as the entry at HEAD and 'newtree' as the
    entry in the target tree. This led to reject_merge() listing these
    paths.
    
    Now that sparse_dir_matches_path() works the same for deep paths as it
    does for shallow depths, the rest of the logic kicks in to properly
    handle modifying the sparse directory entries as designed.
    
    Reported-by: Gustave Granroth <gus.gran@gmail.com>
    Reported-by: Mike Marcelais <michmarc@exchange.microsoft.com>
    Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
    derrickstolee committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    80c54eb View commit details
    Browse the repository at this point in the history