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

Create stronger guard rails on replace refs #1537

Commits on May 31, 2023

  1. repository: create disable_replace_refs()

    Several builtins depend on being able to disable the replace references
    so we actually operate on each object individually. These currently do
    so by directly mutating the 'read_replace_refs' global.
    
    A future change will move this global into a different place, so it will
    be necessary to change all of these lines. However, we can simplify that
    transition by abstracting the purpose of these global assignments with a
    method call.
    
    We will need to keep this read_replace_refs global forever, as we want
    to make sure that we never use replace refs throughout the life of the
    process if this method is called. Future changes may present a
    repository-scoped version of the variable to represent that repository's
    core.useReplaceRefs config value, but a zero-valued read_replace_refs
    will always override such a setting.
    
    Signed-off-by: Derrick Stolee <derrickstolee@github.com>
    derrickstolee committed May 31, 2023
    Configuration menu
    Copy the full SHA
    0616fdb View commit details
    Browse the repository at this point in the history

Commits on Jun 5, 2023

  1. replace-objects: create wrapper around setting

    The 'read_replace_objects' constant is initialized by git_default_config
    (if core.useReplaceRefs is disabled) and within setup_git_env (if
    GIT_NO_REPLACE_OBJECTS) is set. To ensure that this variable cannot be
    set accidentally in other places, wrap it in a replace_refs_enabled()
    method.
    
    Since we still assign this global in config.c, we are not able to remove
    the global scope of this variable and make it a static within
    replace-object.c. This will happen in a later change which will also
    prevent the variable from being read before it is initialized.
    
    Centralizing read access to the variable is an important first step.
    
    Signed-off-by: Derrick Stolee <derrickstolee@github.com>
    derrickstolee committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    4e75a76 View commit details
    Browse the repository at this point in the history
  2. repository: create read_replace_refs setting

    The 'read_replace_refs' global specifies whether or not we should
    respect the references of the form 'refs/replace/<oid>' to replace which
    object we look up when asking for '<oid>'. This global has caused issues
    when it is not initialized properly, such as in b6551fe (merge-tree:
    load default git config, 2023-05-10).
    
    To make this more robust, move its config-based initialization out of
    git_default_config and into prepare_repo_settings(). This provides a
    repository-scoped version of the 'read_replace_refs' global.
    
    The global still has its purpose: it is disabled process-wide by the
    GIT_NO_REPLACE_OBJECTS environment variable or by a call to
    disable_replace_refs() in some specific Git commands.
    
    Since we already encapsulated the use of the constant inside
    replace_refs_enabled(), we can perform the initialization inside that
    method, if necessary. This solves the problem of forgetting to check the
    config, as we will check it before returning this value.
    
    Due to this encapsulation, the global can move to be static within
    replace-object.c.
    
    There is an interesting behavior change possible here: we now have a
    repository-scoped understanding of this config value. Thus, if there was
    a command that recurses into submodules and might follow replace refs,
    then it would now respect the core.useReplaceRefs config value in each
    repository.
    
    'git grep --recurse-submodules' is such a command that recurses into
    submodules in-process. We can demonstrate the granularity of this config
    value via a test in t7814.
    
    Signed-off-by: Derrick Stolee <derrickstolee@github.com>
    derrickstolee committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    8b7c771 View commit details
    Browse the repository at this point in the history