threads / discuss / 62802

Should 'git replace' respect GIT_NAMESPACE?

Subject: Should 'git replace' respect GIT_NAMESPACE?

## tl;dr

4 messages between Jan 14, 2025 and Jan 15, 2025.

replies: 3people: 2as markdown or json

Josh Bleecher Snyder· Jan 14, 2025, 05:16 UTC · lore

I was hoping it would, so I could have different replacements in different namespaces, but it doesn't look like it does as of ~now:

$ git version git version 2.47.1

$ GIT_NAMESPACE=foo git replace 751eeb3b4d23c7fbde919aedde8c091f04f4f819 a9dfd084086ee4d6bf00a33b0976f28c0997457e

$ git rev-parse refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819 a9dfd084086ee4d6bf00a33b0976f28c0997457e

$ git rev-parse refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819 refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819 fatal: ambiguous argument 'refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819': unknown revision or path not in the working tree.

$ git log -n 1 --oneline 751eeb3b4d23c7fbde919aedde8c091f04f4f819 751eeb3 (replaced) add go.mod

$ GIT_NAMESPACE=foo git log -n 1 --oneline 751eeb3b4d23c7fbde919aedde8c091f04f4f819 751eeb3 (replaced) add go.mod

Is this a bug in which case I might hope for a fix, or is it working as intended?

-josh
Christian Couder· Jan 14, 2025, 08:36 UTC · re: Josh Bleecher Snyder · lore

Re: Should 'git replace' respect GIT_NAMESPACE?

On Tue, Jan 14, 2025 at 6:17 AM Josh Bleecher Snyder <josharian@gmail.com> wrote:

>
> I was hoping it would, so I could have different replacements in
> different namespaces, but it doesn't look like it does as of ~now:

It might be interesting to know what you wanted to do with different replacements in different namespaces.

When replace refs were introduced, there were discussions about extending replace refs to be able to have different sets of replace refs used at different times, so that it would be possible to have different "views" of a repository. For example there could be the following views:

  - the "default" or "canonical" view where no replace refs are used,
  - the "timestamp fixed" view where some replace refs to fix
timestamp issues are used,
  - the "authorship fixed" view where some replace refs to fix
authorship and committership issues are used,
  - the "build fixed" view where some replace refs are used so that
the build work on all commits (which should help with bisecting),
  - the "old history" view where some old history of the code (that
was not imported when Git started to be used) is linked by some
replace refs,
etc.
Show 26 quoted lines
> $ git version
> git version 2.47.1
>
> $ GIT_NAMESPACE=foo git replace
> 751eeb3b4d23c7fbde919aedde8c091f04f4f819
> a9dfd084086ee4d6bf00a33b0976f28c0997457e
>
> $ git rev-parse refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819
> a9dfd084086ee4d6bf00a33b0976f28c0997457e
>
> $ git rev-parse
> refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819
> refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819
> fatal: ambiguous argument
> 'refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819':
> unknown revision or path not in the working tree.
>
> $ git log -n 1 --oneline 751eeb3b4d23c7fbde919aedde8c091f04f4f819
> 751eeb3 (replaced) add go.mod
>
> $ GIT_NAMESPACE=foo git log -n 1 --oneline
> 751eeb3b4d23c7fbde919aedde8c091f04f4f819
> 751eeb3 (replaced) add go.mod
>
> Is this a bug in which case I might hope for a fix, or is it working
> as intended?

I don't think anyone mentioned using both namespaces and replace refs together before, so it's hard to say.

I think namespaces are considered a server side thing to avoid duplicating objects in the common case where different users have different forks of the same original repo. And namespaces might not even be used much on the server side as there is the "alternates" mechanism that can be used for the same purpose. Also on the server side, you generally want to disable ref replacement entirely as it's just simpler, and most often what users want, to use the default view without any replacement. So it might just happen very rarely that people want to use both namespaces and replace refs together.

Josh Bleecher Snyder· Jan 14, 2025, 22:39 UTC · re: Christian Couder · lore

Re: Should 'git replace' respect GIT_NAMESPACE?

Show 23 quoted lines
> > I was hoping it would, so I could have different replacements in
> > different namespaces, but it doesn't look like it does as of ~now:
>
> It might be interesting to know what you wanted to do with different
> replacements in different namespaces.
>
> When replace refs were introduced, there were discussions about
> extending replace refs to be able to have different sets of replace
> refs used at different times, so that it would be possible to have
> different "views" of a repository. For example there could be the
> following views:
>
>   - the "default" or "canonical" view where no replace refs are used,
>   - the "timestamp fixed" view where some replace refs to fix
> timestamp issues are used,
>   - the "authorship fixed" view where some replace refs to fix
> authorship and committership issues are used,
>   - the "build fixed" view where some replace refs are used so that
> the build work on all commits (which should help with bisecting),
>   - the "old history" view where some old history of the code (that
> was not imported when Git started to be used) is linked by some
> replace refs,
> etc.

That is indeed roughly what I had in mind: a bunch of different views of the repo.

Show 39 quoted lines
> > $ git version
> > git version 2.47.1
> >
> > $ GIT_NAMESPACE=foo git replace
> > 751eeb3b4d23c7fbde919aedde8c091f04f4f819
> > a9dfd084086ee4d6bf00a33b0976f28c0997457e
> >
> > $ git rev-parse refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819
> > a9dfd084086ee4d6bf00a33b0976f28c0997457e
> >
> > $ git rev-parse
> > refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819
> > refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819
> > fatal: ambiguous argument
> > 'refs/namespaces/foo/refs/replace/751eeb3b4d23c7fbde919aedde8c091f04f4f819':
> > unknown revision or path not in the working tree.
> >
> > $ git log -n 1 --oneline 751eeb3b4d23c7fbde919aedde8c091f04f4f819
> > 751eeb3 (replaced) add go.mod
> >
> > $ GIT_NAMESPACE=foo git log -n 1 --oneline
> > 751eeb3b4d23c7fbde919aedde8c091f04f4f819
> > 751eeb3 (replaced) add go.mod
> >
> > Is this a bug in which case I might hope for a fix, or is it working
> > as intended?
>
> I don't think anyone mentioned using both namespaces and replace refs
> together before, so it's hard to say.
>
> I think namespaces are considered a server side thing to avoid
> duplicating objects in the common case where different users have
> different forks of the same original repo. And namespaces might not
> even be used much on the server side as there is the "alternates"
> mechanism that can be used for the same purpose. Also on the server
> side, you generally want to disable ref replacement entirely as it's
> just simpler, and most often what users want, to use the default view
> without any replacement. So it might just happen very rarely that
> people want to use both namespaces and replace refs together.
Got it. Thanks.
Do you have suggestions for alternative mechanisms I might use?

I want to be able to easily enable/disable a set of replace directives for the purposes of running other git commands, without globally altering the repository. Otherwise I have to worry about locking, cleanup when something goes wrong, and state visibility and management. All possible to fix, but messy compared with something like namespaces.

-josh
Christian Couder· Jan 15, 2025, 09:21 UTC · re: Josh Bleecher Snyder · lore

Re: Should 'git replace' respect GIT_NAMESPACE?

On Tue, Jan 14, 2025 at 11:40 PM Josh Bleecher Snyder <josharian@gmail.com> wrote:

Show 8 quoted lines
> Do you have suggestions for alternative mechanisms I might use?
>
> I want to be able to easily enable/disable a set of replace directives
> for the purposes of running other git commands, without globally
> altering the repository. Otherwise I have to worry about locking,
> cleanup when something goes wrong, and state visibility and
> management. All possible to fix, but messy compared with something
> like namespaces.

The simplest would likely be to develop a small set of shell scripts/commands to move or copy replace refs around. These scripts or commands could use `git for-each-ref` to get replace ref information and then `git update-ref` to create and/or delete replace refs.

For example a 'mv-rep-refs <src> <dst>' command would move all the refs under "refs/replace/views/<src>/" to "refs/replace/views/<dst>/" except if <src> or <dst> is '.' which would mean "refs/replace/". Then `mv-rep-refs build-fixes .` could activate the replace refs that fix the build.

Alternatively you could work on implementing a similar "view" mechanism in Git itself and submit your patches here.

← back to recent threads