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

Clarify API for dir.[ch] and unpack-trees.[ch] -- mark relevant fields as internal #1149

Closed
wants to merge 13 commits into from

Commits on Feb 26, 2023

  1. t2021: fix platform-specific leftover cruft

    t2021.6 existed to test the status of a symlink that was left around by
    previous tests.  It tried to also clean up the symlink after it was done
    so that subsequent tests wouldn't be tripped up by it.  Unfortunately,
    since this test had a SYMLINK prerequisite, that made the cleanup
    platform dependent...and made a testcase I was trying to add to this
    testsuite fail (that testcase will be included in the next patch).
    Before we go and add new testcases, fix this cleanup by moving it into a
    separate test.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    7bbc457 View commit details
    Browse the repository at this point in the history
  2. unpack-trees: heed requests to overwrite ignored files

    When a directory exists but has only ignored files within it and we are
    trying to switch to a branch that has a file where that directory is,
    the behavior depends upon --[no]-overwrite-ignore.  If the user wants to
    --overwrite-ignore (the default), then we should delete the ignored file
    and directory and switch to the new branch.
    
    The code to handle this in verify_clean_subdirectory() in unpack-trees
    tried to handle this via paying attention to the exclude_per_dir setting
    of the internal dir field.  This came from commit c819353 ("Fix
    switching to a branch with D/F when current branch has file D.",
    2007-03-15), which pre-dated 039bc64 ("core.excludesfile clean-up",
    2007-11-14), and thus did not pay attention to ignore patterns from
    other relevant files.  Change it to use setup_standard_excludes() so
    that it is also aware of excludes specified in other locations.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    8ffdb6c View commit details
    Browse the repository at this point in the history
  3. dir: separate public from internal portion of dir_struct

    In order to make it clearer to callers what portions of dir_struct are
    public API, and avoid errors from them setting fields that are meant as
    internal API, split the fields used for internal implementation reasons
    into a separate embedded struct.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    879a93a View commit details
    Browse the repository at this point in the history
  4. dir: add a usage note to exclude_per_dir

    As evidenced by the fix a couple commits ago, places in the code using
    exclude_per_dir are likely buggy and should be adapted to call
    setup_standard_excludes() instead.  Unfortunately, the usage of
    exclude_per_dir has been hardcoded into the arguments ls-files accepts,
    so we cannot actually remove it.  Add a note that it is deprecated and
    no other callers should use it directly.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    4ce9fae View commit details
    Browse the repository at this point in the history
  5. dir: mark output only fields of dir_struct as such

    While at it, also group these fields together for convenience.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    1234440 View commit details
    Browse the repository at this point in the history
  6. unpack-trees: clean up some flow control

    The update_sparsity() function was introduced in commit 7af7a25
    ("unpack-trees: add a new update_sparsity() function", 2020-03-27).
    Prior to that, unpack_trees() was used, but that had a few bugs because
    the needs of the caller were different, and different enough that
    unpack_trees() could not easily be modified to handle both usecases.
    
    The implementation detail that update_sparsity() was written by copying
    unpack_trees() and then streamlining it, and then modifying it in the
    needed ways still shows through in that there are leftover vestiges in
    both functions that are no longer needed.  Clean them up.  In
    particular:
    
      * update_sparsity() allows a pattern list to be passed in, but
        unpack_trees() never should use a different pattern list.  Add a
        check and a BUG() if this gets violated.
      * update_sparsity() has a check early on that will BUG() if
        o->skip_sparse_checkout is set; as such, there's no need to check
        for that condition again later in the code.  We can simply remove
        the check and its corresponding goto label.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    4e86e39 View commit details
    Browse the repository at this point in the history
  7. sparse-checkout: avoid using internal API of unpack-trees

    struct unpack_trees_options has the following field and comment:
    
    	struct pattern_list *pl; /* for internal use */
    
    Despite the internal-use comment, commit e091228 ("sparse-checkout:
    update working directory in-process", 2019-11-21) starting setting this
    field from an external caller.  At the time, the only way around that
    would have been to modify unpack_trees() to take an extra pattern_list
    argument, and there's a lot of callers of that function.  However, when
    we split update_sparsity() off as a separate function, with
    sparse-checkout being the sole caller, the need to update other callers
    went away.  Fix this API problem by adding a pattern_list argument to
    update_sparsity() and stop setting the internal o.pl field directly.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    cd3d489 View commit details
    Browse the repository at this point in the history
  8. sparse-checkout: avoid using internal API of unpack-trees, take 2

    Commit 2f6b1eb ("cache API: add a "INDEX_STATE_INIT" macro/function,
    add release_index()", 2023-01-12) mistakenly added some initialization
    of a member of unpack_trees_options that was intended to be
    internal-only.  This initialization should be done within
    update_sparsity() instead.
    
    Note that while o->result is mostly meant for unpack_trees() and
    update_sparsity() mostly operates without o->result,
    check_ok_to_remove() does consult it so we need to ensure it is properly
    initialized.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    09140cb View commit details
    Browse the repository at this point in the history
  9. unpack_trees: start splitting internal fields from public API

    This just splits the two fields already marked as internal-only into a
    separate internal struct.  Future commits will add more fields that
    were meant to be internal-only but were not explicitly marked as such
    to the same struct.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    27f2d47 View commit details
    Browse the repository at this point in the history
  10. unpack-trees: mark fields only used internally as internal

    Continue the work from the previous patch by finding additional fields
    which are only used internally but not yet explicitly marked as such,
    and include them in the internal fields struct.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    4236c0d View commit details
    Browse the repository at this point in the history
  11. unpack-trees: rewrap a few overlong lines from previous patch

    The previous patch made many lines a little longer, resulting in four
    becoming a bit too long.  They were left as-is for the previous patch
    to facilitate reviewers verifying that we were just adding "internal."
    in a bunch of places, but rewrap them now.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    76f4a54 View commit details
    Browse the repository at this point in the history
  12. unpack-trees: special case read-tree debugging as internal usage

    builtin/read-tree.c has some special functionality explicitly designed
    for debugging unpack-trees.[ch].  Associated with that is two fields
    that no other external caller would or should use.  Mark these as
    internal to unpack-trees, but allow builtin/read-tree to read or write
    them for this special case.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    ee36935 View commit details
    Browse the repository at this point in the history
  13. unpack-trees: add usage notices around df_conflict_entry

    Avoid making users believe they need to initialize df_conflict_entry
    to something (as happened with other output only fields before) with
    a quick comment and a small sanity check.
    
    Signed-off-by: Elijah Newren <newren@gmail.com>
    newren committed Feb 26, 2023
    Configuration menu
    Copy the full SHA
    6575c00 View commit details
    Browse the repository at this point in the history