* Re: [PATCH 2/7] repack: use die_for_incompatible_opt3() for -A/-k/--cruft
From: Taylor Blau @ 2023-12-06 19:18 UTC (permalink / raw)
To: René Scharfe; +Cc: git
In-Reply-To: <20231206115215.94467-3-l.s.r@web.de>
On Wed, Dec 06, 2023 at 12:51:56PM +0100, René Scharfe wrote:
> diff --git a/builtin/repack.c b/builtin/repack.c
> index edaee4dbec..c54777bbe5 100644
> --- a/builtin/repack.c
> +++ b/builtin/repack.c
> @@ -1203,19 +1203,13 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
> if (delete_redundant && repository_format_precious_objects)
> die(_("cannot delete packs in a precious-objects repo"));
>
> - if (keep_unreachable &&
> - (unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE)))
> - die(_("options '%s' and '%s' cannot be used together"), "--keep-unreachable", "-A");
> + die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
> + keep_unreachable, "-k/--keep-unreachable",
> + pack_everything & PACK_CRUFT, "--cruft");
Oof, thanks for cleaning this one up.
I had to read this hunk a couple of times to convince myself that it was
doing the right thing, but I believe it is.
> - if (pack_everything & PACK_CRUFT) {
> + if (pack_everything & PACK_CRUFT)
> pack_everything |= ALL_INTO_ONE;
And adding the ALL_INTO_ONE bit here does not effect either of the below
two checks, so moving them up is fine, too.
> - if (unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE))
> - die(_("options '%s' and '%s' cannot be used together"), "--cruft", "-A");
> - if (keep_unreachable)
> - die(_("options '%s' and '%s' cannot be used together"), "--cruft", "-k");
> - }
Thanks,
Taylor
^ permalink raw reply
* Re: [PATCH 4/7] revision, rev-parse: factorize incompatibility messages about --exclude-hidden
From: Taylor Blau @ 2023-12-06 19:25 UTC (permalink / raw)
To: René Scharfe; +Cc: Patrick Steinhardt, git
In-Reply-To: <4954cf77-63f6-4225-833f-3c28d642ed11@web.de>
On Wed, Dec 06, 2023 at 06:07:29PM +0100, René Scharfe wrote:
> > It's not perfect
> > of course, but would at least ensure that we can easily convert things
> > over time without having to duplicate the exact message everywhere.
>
> Maybe the simplest option would be to use a macro, e.g.
>
> #define INCOMPATIBLE_OPTIONS_MESSAGE \
> _("options '%s' and '%s' cannot be used together")
>
> It could be used with both error() and die(), and the compiler would
> still ensure that two strings are passed along with it, but I don't know
> how to encode that requirement in the macro name somehow to make it
> self-documenting. Perhaps by getting the number two in there?
I think that this is a great idea. It nicely solves Patrick's concern
that we have to duplicate this message ID everywhere, and equally solves
yours by calling error() inline instead of having to pass down the
option values.
I think that including a number in the macro name would be helpful here.
> > I don't think it's a problem to not convert everything in one go. The
> > current series is a good step in the right direction, and any additional
> > instances that were missed can be fixed in follow-ups.
>
> Right; whatever we do, we can (and should) do it step by step.
I agree :-).
Thanks,
Taylor
^ permalink raw reply
* Re: [PATCH] object-name: reject too-deep recursive ancestor queries
From: Jeff King @ 2023-12-06 19:40 UTC (permalink / raw)
To: Patrick Steinhardt
Cc: Junio C Hamano, Taylor Blau, git,
Carlos Andrés Ramírez Cataño
In-Reply-To: <ZWB26TH0CFW1KC4L@tanuki>
On Fri, Nov 24, 2023 at 11:11:53AM +0100, Patrick Steinhardt wrote:
> > When we get "HEAD~~~~~~~~~^2~~~~~~" from the user, do we somehow try
> > to create a file or a directory with that name and fail due to
> > ENAMETOOLONG?
>
> Sorry, this was a typo on my part. I didn't mean "revision", I meant
> "reference" here. References are limited to at most 4kB on most
> platforms due to filesystem limitations, whereas revisions currently
> have no limits in place.
Even without filesystem limitations, references are effectively limited
to 64kb due to the pkt-line format.
Revisions can be much longer than a reference, though. We accept
"some_ref:some/path/in/tree", for instance[1]. I think you could argue
that paths are likewise limited by the filesystem, though. Even on
systems like Linux where paths can grow arbitrarily long (by descending
and adding to the current directory), you're still limited in specifying
a full pathname. And Git will always use the full path from the project
root when creating worktree entries. Plus my recent tree-depth patches
effectively limit us to 16MB in the default config.
So I think it might be reasonable to limit revision lengths just as a
belt-and-suspenders against overflow attacks, etc. But I suspect that
the limits we'd choose there might not match what we'd want for
protection against stack exhaustion via recursion. E.g., I think 8k is
probably the minimum I'd want for a revision ("my/4k/ref:my/4k/path").
If one "~" character can create an expensive recursion, that might be
too much.
So we probably need something like Taylor's patch anyway (or to switch
to an iterative algorithm, though that might be tricky because of the
way we parse). I agree it needs to handle "^", though.
-Peff
[1] There are other more exotic revisions, too. The most arbitrary-sized
that comes to mind is ":/some-string-to-match". I doubt anybody
would be too mad if that were limited to 8k or even 4k, though.
^ permalink raw reply
* Re: [PATCH] commit-graph: disable GIT_COMMIT_GRAPH_PARANOIA by default
From: Jeff King @ 2023-12-06 19:49 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Junio C Hamano, git, Karthik Nayak
In-Reply-To: <ZVTJFOSnVonoPgZk@tanuki>
On Wed, Nov 15, 2023 at 02:35:16PM +0100, Patrick Steinhardt wrote:
> > > Just to make sure we do not miscommunicate, I do not think we want
> > > to trigger the paranoia mode only in our tests. We want to be
> > > paranoid to help real users who used "--missing" for their real use,
> > > so enabling PARANOIA in the test script is a wrong approach. We
> > > should enable it inside "rev-list --missing" codepath.
> >
> > Yeah. Just like we auto-enabled GIT_REF_PARANOIA for git-gc, etc, I
> > think we should do the same here.
>
> I'm honestly still torn on this one. There are two cases that I can
> think of where missing objects would be benign and where one wants to
> use `git rev-list --missing`:
>
> - Repositories with promisor remotes, to find the boundary of where
> we need to fetch new objects.
>
> - Quarantine directories where you only intend to list new objects
> or find the boundary.
>
> And in neither of those cases I can see a path for how the commit-graph
> would contain such missing commits when using regular tooling to perform
> repository maintenance.
Sorry for being unclear (and for the very slow response!). What I meant
by "here" was not "rev-list --missing" in particular, but rather that
"here" is "GIT_COMMIT_GRAPH_PARANOIA". And like GIT_REF_PARANOIA, we
should make sure it is turned on when checking for repository
corruption.
So specifically I meant that turning it off should:
1. Not cause us to miss corruption with fsck.
2. Not cause us to make corruption worse during a destructive repack
(e.g., "repack -ad").
3. Not admit corruption into the repository by fooling the rev-list
invocation for check_connected().
I don't think the third one uses --missing at all, but even if it did,
the interesting thing to me is not "--missing", but rather that the
caller knows it is doing a corruption check. So it would set the
environment variable itself.
So in your loosening patch, I would have expected to see a couple of
those cases overriding the new "default to off" behavior. But it may be
that they are not necessary (e.g., I think fsck may turn off the commit
graph entirely already).
> So I'm still not sure why we think that this case is so much more
> special than others. If a user wants to check for repository corruption
> the tool shouldn't be `git rev-list --missing`, but git-fsck(1). To me,
> the former is only useful in very specific circumstances where the user
> knows what they are doing, and in none of the usecases I can think of
> should we have a stale commit-graph _unless_ we have actual repository
> corruption.
>
> In reverse, to me this means that `--missing` is no more special than
> any of the other low-level tooling, where our stance seems to be "We
> assume that the repository is not corrupt". In that spirit, I'd argue
> that the same default value should apply here as for all the other
> cases.
Yeah, I think we are on the same page here. The need for paranoia is
really in the eyes of the caller, because only they know how careful
they want the operation to be.
> Oh, well. I'll wait for answers to this reply until tomorrow, and if I
> still haven't been able to convince anybody then I'll assume it's just
> me and adapt accordingly :)
Sorry, better late than never. ;)
-Peff
^ permalink raw reply
* Re: Minor UX annoyance w/`git add --patch untracked/file`
From: Jeff King @ 2023-12-06 19:54 UTC (permalink / raw)
To: Vito Caputo; +Cc: git
In-Reply-To: <20231130192637.wqpmidfv2roqmxdx@shells.gnugeneration.com>
On Thu, Nov 30, 2023 at 11:26:37AM -0800, Vito Caputo wrote:
> Couldn't the following two steps be done automagically by --patch:
>
> ```
> git add -N path/to/untracked/file/wishing/to/partially/add
> git add --patch path/to/untracked/file/wishing/to/partially/add
> ```
>
> when one simply does:
>
> `git add --patch path/to/untracked/file/wishing/to/partially/add`
>
> ?
They _could_, but keep in mind that the argument is not strictly a path.
It is a pathspec that may match multiple paths. So:
git add -p path/to/
for example will pick up the tracked files in path/to/, but not your
untracked one.
It would be possible to distinguish the two cases, and only auto-add
files which are explicitly mentioned as full paths. But we usually shy
away from too many special cases like this, as the resulting behavior
can end up confusing and hard to explain.
-Peff
^ permalink raw reply
* Re: [PATCH] setup: recognize bare repositories with packed-refs
From: Jeff King @ 2023-12-06 20:10 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Adam Majer, git
In-Reply-To: <ZWcOvjGPVS_CMUAk@tanuki>
On Wed, Nov 29, 2023 at 11:13:18AM +0100, Patrick Steinhardt wrote:
> As I'm currently working on the reftable backend this thought has also
> crossed my mind. The reftable backend doesn't only create "refs/", but
> it also creates "HEAD" with contents "ref: refs/heads/.invalid" so that
> Git commands recognize the Git directory properly. Longer-term I would
> really love to see us doing a better job of detecting Git repositories
> so that we don't have to carry this legacy baggage around.
>
> I can see different ways for how to do this:
>
> - Either we iterate through all known reference backends, asking
> each of them whether they recognize the directory as something
> they understand.
>
> - Or we start parsing the gitconfig of the repository so that we can
> learn about which reference backend to expect, and then ask that
> specific backend whether it thinks that the directory indeed looks
> like something it can handle.
>
> I'd personally prefer the latter, but I'm not sure whether we really
> want to try and parse any file that happens to be called "config".
We do eventually parse the config file to pick up repositoryFormatVersion.
But there's sort of a chicken-and-egg here where we only do so after
gaining some confidence that it's a repo directory. :)
I actually think the "ask each backend if it looks plausible" is
reasonable, at least for an implementation that knows about all
backends. Though what gives me pause is how older versions of Git will
behave with a new-format repository that does not have a "refs"
directory.
There are really two compatibility checks. In is_git_directory(), we
want to say "is this a repo or not". And then later we parse the config,
make sure the repository format is OK, and that we support all
extensions. So right now, an older version of Git that encounters a
reftable-formatted repo (that has a vestigial "refs/" directory) says
"ah, that is a repo, but I don't understand it" (the latter because
presumably the repo version/extensions in .git/config are values it
doesn't know about). But if we get rid of "refs/", then older versions
of Git will stop even considering it as a repo at all, and will keep
searching up to the ceiling directory. So either:
1. They'll find nothing, and you'll get "you're not in a git repo",
rather than "you're in a git repo, but I don't understand it".
Which is slightly worse.
2. They'll find some _other_ containing repo. Which could be quite
confusing.
So forgetting at all about how we structure the code, it seems to me
that the problem is not new code, but all of the existing code which
looks for access("refs", X_OK).
I dunno. Maybe that is being too paranoid about backwards compatibility.
People will have to turn on reftable manually, at least for a while, and
would hopefully know what they are signing up for, and that old versions
might not work as well. And by the time a new format becomes the
default, it's possible that those older versions would have become quite
rare.
> Just throwing this out there, but we could use this as an excuse to
> introduce "extensions.refFormat". If it's explicitly configured to be
> "reffiles" then we accept repositories even if they don't have the
> "refs/" directory or a "packed-refs" file. This would still require work
> in alternative implementations of Git, but this work will need to happen
> anyway when the reftable backend lands.
>
> I'd personally love for this extension to be introduced before I'm
> sending the reftable backend upstream so that we can have discussions
> around it beforehand.
We already have an extension config option to specify that we're using
reftable, don't we? But anything in config has the same chicken-and-egg
problems as above, I think.
-Peff
^ permalink raw reply
* Re: [PATCH] setup: recognize bare repositories with packed-refs
From: Jeff King @ 2023-12-06 21:08 UTC (permalink / raw)
To: Taylor Blau; +Cc: Adam Majer, git
In-Reply-To: <ZWethlRRtuQLDRlJ@nand.local>
On Wed, Nov 29, 2023 at 04:30:46PM -0500, Taylor Blau wrote:
> On Tue, Nov 28, 2023 at 02:04:46PM -0500, Jeff King wrote:
> > - whatever is consuming the embedded repos could "mkdir -p refs
> > objects" as needed. This is a minor pain, but I think in the long
> > term we are moving to a world where you have to explicitly do
> > "GIT_DIR=$PWD/embedded.git" to access an embedded bare repo. So
> > they're already special and require some setup; adding an extra step
> > may not be so bad.
>
> I hope not. I suppose that using embedded bare repositories in a test
> requires additional setup at least to "cd" into the directory (if they
> are not using `$GIT_DIR` or `--git-dir` already). But I fear that
> imposing even a small change like this is too tall an order for how many
> millions of these exist in the wild across all sorts of projects.
I dunno. I am skeptical that there are millions of these. Who really
wants to embed bare git repos except for projects related to Git itself,
which want test vectors? Is there a use case I'm missing?
-Peff
^ permalink raw reply
* Re: [PATCH 1/7] setup: extract function to create the refdb
From: Karthik Nayak @ 2023-12-06 21:10 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
In-Reply-To: <b69c57d27269c9b40c9e4394861dffd8a8b9860c.1701863960.git.ps@pks.im>
On Wed, Dec 6, 2023 at 1:40 PM Patrick Steinhardt <ps@pks.im> wrote:
> +static void create_reference_database(const char *initial_branch, int quiet)
> +{
> + struct strbuf err = STRBUF_INIT;
> + int reinit = is_reinit();
> +
> + /*
> + * We need to create a "refs" dir in any case so that older
> + * versions of git can tell that this is a repository.
> + */
How does this work though, even if an earlier version of git can tell
that this is a repository,
it still won't be able to read the reftable backend. In that sense,
what do we achieve here?
> + safe_create_dir(git_path("refs"), 1);
> + adjust_shared_perm(git_path("refs"));
> +
Not related to your commit per se, but we ignore the return value
here, shouldn't we die in this case?
^ permalink raw reply
* Re: [PATCH 4/7] builtin/clone: fix bundle URIs with mismatching object formats
From: Karthik Nayak @ 2023-12-06 21:13 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
In-Reply-To: <c7a9d6ef74ff39e660f80e2e104a96b7c875845d.1701863960.git.ps@pks.im>
On Wed, Dec 6, 2023 at 1:40 PM Patrick Steinhardt <ps@pks.im> wrote:
> The first Git step where we expect the repository to be fully initalized
> is when we fetch bundles via bundle URIs. Funny enough, the comments
> there also state that "the_repository must match the cloned repo", which
> is indeed not necessarily the case for the hash algorithm right now. So
> in practice it is the right thing to detect the remote's object format
> before downloading bundle URIs anyway, and not doing so causes clones
> with bundle URIS to fail when the local default object format does not
> match the remote repository's format.
>
Nit: s/URIS/URIs
^ permalink raw reply
* Re: --end-of-options inconsistently available?!
From: Jeff King @ 2023-12-06 21:16 UTC (permalink / raw)
To: Sven Strickroth; +Cc: git
In-Reply-To: <ab14260c-d515-425e-8ef6-5739d3d6ca4e@cs-ware.de>
On Tue, Nov 28, 2023 at 09:40:08AM +0100, Sven Strickroth wrote:
> > This one is intentional. rev-parse in its default mode is not just
> > spitting out revisions, but also options that are meant to be passed
> > along to the revision machinery via other commands (like rev-list). So
> > for example:
> >
> > $ git rev-parse --foo HEAD
> > --foo
> > 564d0252ca632e0264ed670534a51d18a689ef5d
> >
> > And it does understand end-of-options explicitly, so:
> >
> > $ git rev-parse --end-of-options --foo --
> > --end-of-options
> > fatal: bad revision '--foo'
> >
> > If you just want to parse a name robustly, use --verify.
>
> I would expect that -- and --end-of-options are handled in a special way
> here so that rev-parse can also be used in scripts. I need to check whether
> --verify works for me (from the manual I thought I need to specify full
> reference names).
They _are_ handled specially, and for the purpose of using rev-parse in
scripts. It's just that in its default mode it does not do what you
want, because it has another purpose.
> > > $ git checkout -f --end-of-options HEAD~1 -- afile.txt
> > > fatal: only one reference expected, 2 given.
> >
> > I think this is the same KEEP_DASHDASH problem as with git-reset.
>
> I also found another problem:
> $ git format-patch --end-of-options -1
> fatal: option '-1' must come before non-option arguments
>
> Where -1 is the number of commits here...
This is the same as the "log --end-of-options --foo" example I showed
earlier. That "-1" cannot mean "use 1 commit", since you used it after
--end-of-options. It will correctly resolve refs/heads/-1 if you have
such a ref. But if you don't, then the DWIM logic for distinguishing
revisions and pathspecs produces a confusing message.
It would be possible to fix that (by telling verify_filename() that we
saw --end-of-options, and not to treat dashes specially). But in
practice if you are bothering to use --end-of-options, you really ought
to be using "--" as well, like:
git format-patch --end-of-options $revs -- $paths
in which case it will know that "-1" _must_ be a revision, and complain:
$ git format-patch --end-of-options -1 --
fatal: bad revision '-1'
-Peff
^ permalink raw reply
* [PATCH] parse-options: decouple "--end-of-options" and "--"
From: Jeff King @ 2023-12-06 22:21 UTC (permalink / raw)
To: Sven Strickroth; +Cc: git
In-Reply-To: <20231127212254.GA87495@coredump.intra.peff.net>
On Mon, Nov 27, 2023 at 04:22:54PM -0500, Jeff King wrote:
> So something like this works:
>
> diff --git a/builtin/reset.c b/builtin/reset.c
> index 4b018d20e3..a0d801179a 100644
> --- a/builtin/reset.c
> +++ b/builtin/reset.c
> @@ -259,6 +259,9 @@ static void parse_args(struct pathspec *pathspec,
> * At this point, argv points immediately after [-opts].
> */
>
> + if (argv[0] && !strcmp(argv[0], "--end-of-options"))
> + argv++;
> +
> if (argv[0]) {
> if (!strcmp(argv[0], "--")) {
> argv++; /* reset to HEAD, possibly with paths */
>
> but it feels like a maintenance problem that we'd have to audit every
> caller that uses KEEP_DASHDASH.
So here's my attempt at a central fix. There is a downside (see the
discussion below), but I think in practice it should be a strict
improvement for most commands. I won't be too surprised if we find a
counter-example, but even if we do, my gut feeling is that we should fix
that command on top of this, rather than give up and require every
command to be aware of --end-of-options.
-- >8 --
Subject: [PATCH] parse-options: decouple "--end-of-options" and "--"
When we added generic end-of-options support in 51b4594b40
(parse-options: allow --end-of-options as a synonym for "--",
2019-08-06), we made them true synonyms. They both stop option parsing,
and they are both returned in the resulting argv if the KEEP_DASHDASH
flag is used.
The hope was that this would work for all callers:
- most generic callers would not pass KEEP_DASHDASH, and so would just
do the right thing (stop parsing there) without needing to know
anything more.
- callers with KEEP_DASHDASH were generally going to rely on
setup_revisions(), which knew to handle --end-of-options specially
But that turned out miss quite a few cases that pass KEEP_DASHDASH but
do their own manual parsing. For example, "git reset", "git checkout",
and so on want pass KEEP_DASHDASH so they can support:
git reset $revs -- $paths
but of course aren't going to actually do a traversal, so they don't
call setup_revisions(). And those cases currently get confused by
--end-of-options being left in place, like:
$ git reset --end-of-options HEAD
fatal: option '--end-of-options' must come before non-option arguments
We could teach each of these callers to handle the leftover option
explicitly. But let's try to be a bit more clever and see if we can
solve it centrally in parse-options.c.
The bogus assumption here is that KEEP_DASHDASH tells us the caller
wants to see --end-of-options in the result. But really, the callers
which need to know that --end-of-options was reached are those that may
potentially parse more options from argv. In other words, those that
pass the KEEP_UNKNOWN_OPT flag.
If such a caller is aware of --end-of-options (e.g., because they call
setup_revisions() with the result), then this will continue to do the
right thing, treating anything after --end-of-options as a non-option.
And if the caller is not aware of --end-of-options, they are better off
keeping it intact, because either:
1. They are just passing the options along to somebody else anyway, in
which case that somebody would need to know about the
--end-of-options marker.
2. They are going to parse the remainder themselves, at which point
choking on --end-of-options is much better than having it silently
removed. The point is to avoid option injection from untrusted
command line arguments, and bailing is better than quietly treating
the untrusted argument as an option.
This fixes bugs with --end-of-options across several commands, but I've
focused on two in particular here:
- t7102 confirms that "git reset --end-of-options --foo" now works.
This checks two things. One, that we no longer barf on
"--end-of-options" itself (which previously we did, even if the rev
was something vanilla like "HEAD" instead of "--foo"). And two, that
we correctly treat "--foo" as a revision rather than an option.
This fix applies to any other cases which pass KEEP_DASHDASH but not
KEEP_UNKNOWN_OPT, like "git checkout", "git check-attr", "git grep",
etc, which would previously choke on "--end-of-options".
- t9350 shows the opposite case: fast-export passed KEEP_UNKNOWN_OPT
but not KEEP_DASHDASH, but then passed the result on to
setup_revisions(). So it never saw --end-of-options, and would
erroneously parse "fast-export --end-of-options --foo" as having a
"--foo" option. This is now fixed.
Note that this does shut the door for callers which want to know if we
hit end-of-options, but don't otherwise need to keep unknown opts. The
obvious thing here is feeding it to the DWIM verify_filename()
machinery. And indeed, this is a problem even for commands which do
understand --end-of-options already. For example, without this patch,
you get:
$ git log --end-of-options --foo
fatal: option '--foo' must come before non-option arguments
because we refuse to accept "--foo" as a filename (because it starts
with a dash) even though we could know that we saw end-of-options. The
verify_filename() function simply doesn't accept this extra information.
So that is the status quo, and this patch doubles down further on that.
Commands like "git reset" have the same problem, but they won't even
know that parse-options saw --end-of-options! So even if we fixed
verify_filename(), they wouldn't have anything to pass to it.
But in practice I don't think this is a big deal. If you are being
careful enough to use --end-of-options, then you should also be using
"--" to disambiguate and avoid the DWIM behavior in the first place. In
other words, doing:
git log --end-of-options --this-is-a-rev -- --this-is-a-path
works correctly, and will continue to do so. And likewise, with this
patch now:
git reset --end-of-options --this-is-a-rev -- --this-is-a-path
will work, as well.
Signed-off-by: Jeff King <peff@peff.net>
---
parse-options.c | 9 +++++++--
t/t7102-reset.sh | 8 ++++++++
t/t9350-fast-export.sh | 10 ++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index e0c94b0546..d50962062e 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -929,13 +929,18 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
continue;
}
- if (!arg[2] /* "--" */ ||
- !strcmp(arg + 2, "end-of-options")) {
+ if (!arg[2] /* "--" */) {
if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) {
ctx->argc--;
ctx->argv++;
}
break;
+ } else if (!strcmp(arg + 2, "end-of-options")) {
+ if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN_OPT)) {
+ ctx->argc--;
+ ctx->argv++;
+ }
+ break;
}
if (internal_help && !strcmp(arg + 2, "help-all"))
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 4287863ae6..62d9f846ce 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -616,4 +616,12 @@ test_expect_success 'reset --mixed sets up work tree' '
test_must_be_empty actual
'
+test_expect_success 'reset handles --end-of-options' '
+ git update-ref refs/heads/--foo HEAD^ &&
+ git log -1 --format=%s refs/heads/--foo >expect &&
+ git reset --hard --end-of-options --foo &&
+ git log -1 --format=%s HEAD >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index 26c25c0eb2..e9a12c18bb 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -791,4 +791,14 @@ test_expect_success 'fast-export --first-parent outputs all revisions output by
)
'
+test_expect_success 'fast-export handles --end-of-options' '
+ git update-ref refs/heads/nodash HEAD &&
+ git update-ref refs/heads/--dashes HEAD &&
+ git fast-export --end-of-options nodash >expect &&
+ git fast-export --end-of-options --dashes >actual.raw &&
+ # fix up lines which mention the ref for comparison
+ sed s/--dashes/nodash/ <actual.raw >actual &&
+ test_cmp expect actual
+'
+
test_done
--
2.43.0.664.ga12c899002
^ permalink raw reply related
* t7900 fails with recent debian systemd?
From: Jeff King @ 2023-12-06 22:31 UTC (permalink / raw)
To: git
I noticed t7900 failing today. The failure looks like this:
$ ./t7900-maintenance.sh -v -i -x
[...]
+ systemd-analyze verify systemd/user/git-maintenance@hourly.service
Unit git-maintenance@hourly.service not found.
error: last command exited with $?=1
not ok 36 - start and stop Linux/systemd maintenance
The problem started after upgrading my Debian unstable system to the
systemd 255~rc4-2 deb. Downgrading back to 254.5-1 makes the test pass
again.
I'm sure it's something silly with finding paths in XDG_CONFIG_HOME or
something like that. I haven't dug further, but I thought I'd post this
to save somebody else going through the same initial debugging. (And of
course any wisdom or further debugging is greatly appreciated).
-Peff
^ permalink raw reply
* Re: t7900 fails with recent debian systemd?
From: Jeff King @ 2023-12-06 22:36 UTC (permalink / raw)
To: git
In-Reply-To: <20231206223145.GA638844@coredump.intra.peff.net>
On Wed, Dec 06, 2023 at 05:31:45PM -0500, Jeff King wrote:
> I noticed t7900 failing today. The failure looks like this:
>
> $ ./t7900-maintenance.sh -v -i -x
> [...]
> + systemd-analyze verify systemd/user/git-maintenance@hourly.service
> Unit git-maintenance@hourly.service not found.
> error: last command exited with $?=1
> not ok 36 - start and stop Linux/systemd maintenance
>
> The problem started after upgrading my Debian unstable system to the
> systemd 255~rc4-2 deb. Downgrading back to 254.5-1 makes the test pass
> again.
>
> I'm sure it's something silly with finding paths in XDG_CONFIG_HOME or
> something like that. I haven't dug further, but I thought I'd post this
> to save somebody else going through the same initial debugging. (And of
> course any wisdom or further debugging is greatly appreciated).
After stracing, it is indeed looking for:
trash directory.t7900-maintenance/systemd/user/git-maintenance@hourly.service
but that file doesn't exist. We installed git-maintenance@hourly.timer,
and git-maintenance@.service. Is the latter supposed to be a wildcard of
some kind? Maybe the rules changed. I don't really know anything about
systemd.
-Peff
^ permalink raw reply
* Re: t7900 fails with recent debian systemd?
From: Eric Sunshine @ 2023-12-06 22:40 UTC (permalink / raw)
To: Jeff King; +Cc: git
In-Reply-To: <20231206223612.GA650770@coredump.intra.peff.net>
On Wed, Dec 6, 2023 at 5:36 PM Jeff King <peff@peff.net> wrote:
> After stracing, it is indeed looking for:
>
> trash directory.t7900-maintenance/systemd/user/git-maintenance@hourly.service
>
> but that file doesn't exist. We installed git-maintenance@hourly.timer,
> and git-maintenance@.service. Is the latter supposed to be a wildcard of
> some kind? Maybe the rules changed. I don't really know anything about
> systemd.
Apparently, that's intentional. From builtin/gc.c:
/*
* No matter the schedule, we use the same service and can make
* use of the templating system. When installing
* git-maintenance@<schedule>.timer, systemd will notice that
* git-maintenance@.service exists as a template and will use this
* file and insert the <schedule> into the template at the
* position of "%i".
*/
static int systemd_timer_write_service_template(const char *exec_path)
{
char *local_service_name = xstrfmt(SYSTEMD_UNIT_FORMAT, "", "service");
I'm not sure why the comment is talking about "%i", though.
^ permalink raw reply
* What's the recommendation for forgetting all rerere's records?
From: Sean Allred @ 2023-12-06 22:37 UTC (permalink / raw)
To: git
Hi all,
When outside the context of a conflict (no rebase/merge in progress),
what's the intended workflow to clear out the contents of
$GIT_DIR/rr-cache?
We have developers who'd like to discard their faulty resolutions after
completing a rebase gone awry (but not aborted). There doesn't seem to
be a recommendation in git-rerere(1) for how to deal with this
situation. (git-rerere-forget seems to only work in the context of an
active conflict -- and is documented as such.)
I'm wary of recommending `rm -rf "$(git rev-parse --git-dir)/rr-cache"`
-- it's hard to describe this as anything but hacky when the rest of the
experience is handled in porcelain.
Thanks!
--
Sean Allred
^ permalink raw reply
* Re: git switch has fatal dependency on default fetch config
From: Jeremiah Steele (Jerry) @ 2023-12-07 2:20 UTC (permalink / raw)
To: Jeff King; +Cc: git
In-Reply-To: <20231206191148.GA103708@coredump.intra.peff.net>
For me, the main convenience of upstream tracking is for "git status" ahead/behind info, which requires you to have already fetched changes from the remote. For my "normal" work, I have a small set of branches set as default fetch refs. When I need to work on a branch not in that set, I fetch that specific branch. (I'm not interested in downloading and creating hundreds of branches when I only need one.)
The requirement to reverse-engineer from the *default* fetch refspec seems like an odd implementation choice and a major shortcoming for storing tracking configuration. The vast majority of the time, origin/branch will map to refs/heads/branch on the remote anyhow. When I have a command that sets up tracking configuration, I would expect to be able to specify the remote refspec somehow, rather than having a hard dependency on a configuration value for default behavior. I feel like the following sequence should work as expected (with a limited default fetch spec), but there are several things that go wrong:
% git fetch origin feature # should fetch to refs/remotes/origin/feature
% git switch feature # should find origin/feature, create a local branch with the same name, and set up tracking
Oh well.
Thanks for the response and the explanation.
> On Dec 6, 2023, at 11:11 AM, Jeff King <peff@peff.net> wrote:
>
> On Tue, Dec 05, 2023 at 07:41:28PM -0800, Jeremiah Steele (Jerry) wrote:
>
>> Changing the default fetch refspec for a remote breaks git switch:
>>
>> % git branch -r
>> origin/HEAD -> origin/master
>> origin/feature
>> origin/master
>> % git remote set-branches origin master
>> % git switch -c feature --track origin/feature
>> fatal: cannot set up tracking information; starting point 'origin/feature' is not a branch
>> % git remote set-branches --add origin feature
>> % git switch -c feature --track origin/feature
>> branch 'feature' set up to track 'origin/feature'.
>> Switched to a new branch 'feature'
>>
>> It seems like I should be able to fetch a remote branch and track it
>> without having to monkey around with my default fetch config. Is there
>> a reason git switch has a hard dependency on the default remote fetch
>> refspec configuration?
>
> I think it's required by the form of the tracking config, which is
> defined by a named remote and a remote branch, like:
>
> [branch "foo"]
> remote = origin
> merge = refs/heads/foo
>
> You explicitly asked to track "origin/feature", which means that Git has
> to be able to turn that into config as above. It can handle two cases:
>
> 1. It's a local branch in refs/heads/, in which case the remote is "."
> and the "merge" field is the name of the branch.
>
> 2. It's a ref that can be found by reversing a fetch refspec. With the
> default remote.origin.fetch refspec of refs/heads/*:refs/remotes/origin/*,
> we know that "refs/remotes/origin/feature" comes from "refs/heads/feature"
> on the "origin" remote.
>
> But since you used "remote set-branches" to limit that refspec, we
> can't do that same reversal. And "origin/feature", while we do
> still have it as a ref, does not correspond to any remote ref we'd
> fetch. So we don't know how to set up the tracking config.
>
> The notion of "tracking" really came about as defining what "git pull"
> does. And without a remote that fetches, "git pull" does not really make
> much sense.
>
> I'd guess that you are more interested in being able to just use
> @{upstream}, especially as the default for things like rebase, etc. And
> that could work without being able to actually fetch the ref. But those
> two things are intertwined in Git. You obviously can still base a branch
> off of "origin/feature", but you'll have to specify it manually when
> doing rebase, etc.
>
> -Peff
^ permalink raw reply
* [PATCH 0/1] MyFirstContribution: configure shallow threads for git format-patch
From: Stan Hu @ 2023-12-07 5:46 UTC (permalink / raw)
To: git; +Cc: Patrick Steinhardt, Stan Hu
This documents the preference for using shallow threads and how
to configure a project to use them.
Stan Hu (1):
MyFirstContribution: configure shallow threads for git format-patch
Documentation/MyFirstContribution.txt | 11 +++++++++++
1 file changed, 11 insertions(+)
--
2.42.0
^ permalink raw reply
* [PATCH 1/1] MyFirstContribution: configure shallow threads for git format-patch
From: Stan Hu @ 2023-12-07 5:46 UTC (permalink / raw)
To: git; +Cc: Patrick Steinhardt, Stan Hu
In-Reply-To: <cover.1701927372.git.stanhu@gmail.com>
Most users on the Git mailing list prefers to use of shallow threads,
but this preference was not documented. This commit adds a blurb about
how to configure this globally via `git config`.
Signed-off-by: Stan Hu <stanhu@gmail.com>
---
Documentation/MyFirstContribution.txt | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt
index 7cfed60c2e..3ac7455b1d 100644
--- a/Documentation/MyFirstContribution.txt
+++ b/Documentation/MyFirstContribution.txt
@@ -1004,6 +1004,17 @@ determine the right way to configure it to use your SMTP server; again, as this
configuration can change significantly based on your system and email setup, it
is out of scope for the context of this tutorial.
+[[configure-shallow-threads]]
+=== Configuring shallow threads for `git format-patch`
+
+It is common practice on the Git mailing list to use "shallow" threads,
+where every mail is a reply to the first mail of the series. You can
+configure the default threading style of `git format-patch` via:
+
+-----
+$ git config format.thread shallow
+----
+
[[format-patch]]
=== Preparing Initial Patchset
--
2.42.0
^ permalink raw reply related
* [PATCH v2 0/2] completion: refactor and support reftables backend
From: Stan Hu @ 2023-12-07 6:06 UTC (permalink / raw)
To: git; +Cc: Stan Hu
In-Reply-To: <20231130202404.89791-1-stanhu@gmail.com>
This patch series addresses the review feedback:
1. Renames the '__git_ref_exists' helper to '__git_pseudoref_exists'.
2. cleans up the commit messages to refer to pseudorefs instead of 'special refs'.
Stan Hu (2):
completion: refactor existence checks for pseudorefs
completion: support pseudoref existence checks for reftables
contrib/completion/git-completion.bash | 43 +++++++++++++++++++++++---
1 file changed, 38 insertions(+), 5 deletions(-)
--
2.42.0
^ permalink raw reply
* [PATCH v2 1/2] completion: refactor existence checks for pseudorefs
From: Stan Hu @ 2023-12-07 6:06 UTC (permalink / raw)
To: git; +Cc: Stan Hu
In-Reply-To: <cover.1701928891.git.stanhu@gmail.com>
In preparation for the reftable backend, this commit introduces a
'__git_pseudoref_exists' function that continues to use 'test -f' to
determine whether a given pseudoref exists in the local filesystem.
Signed-off-by: Stan Hu <stanhu@gmail.com>
---
contrib/completion/git-completion.bash | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 13a39ebd2e..9fbdc13f9a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -122,6 +122,15 @@ __git ()
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
}
+# Runs git in $__git_repo_path to determine whether a ref exists.
+# 1: The ref to search
+__git_ref_exists ()
+{
+ local ref=$1
+
+ [ -f "$__git_repo_path/$ref" ]
+}
+
# Removes backslash escaping, single quotes and double quotes from a word,
# stores the result in the variable $dequoted_word.
# 1: The word to dequote.
@@ -1625,7 +1634,7 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
_git_cherry_pick ()
{
__git_find_repo_path
- if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
+ if __git_ref_exists CHERRY_PICK_HEAD; then
__gitcomp "$__git_cherry_pick_inprogress_options"
return
fi
@@ -2067,7 +2076,7 @@ _git_log ()
__git_find_repo_path
local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ if __git_ref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$prev,$cur" in
@@ -2934,6 +2943,7 @@ _git_reset ()
_git_restore ()
{
+ __git_find_repo_path
case "$prev" in
-s)
__git_complete_refs
@@ -2952,7 +2962,7 @@ _git_restore ()
__gitcomp_builtin restore
;;
*)
- if __git rev-parse --verify --quiet HEAD >/dev/null; then
+ if __git_ref_exists HEAD; then
__git_complete_index_file "--modified"
fi
esac
@@ -2963,7 +2973,7 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
_git_revert ()
{
__git_find_repo_path
- if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
+ if __git_ref_exists REVERT_HEAD; then
__gitcomp "$__git_revert_inprogress_options"
return
fi
@@ -3592,7 +3602,7 @@ __gitk_main ()
__git_find_repo_path
local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ if __git_ref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$cur" in
--
2.42.0
^ permalink raw reply related
* [PATCH v2 2/2] completion: support pseudoref existence checks for reftables
From: Stan Hu @ 2023-12-07 6:06 UTC (permalink / raw)
To: git; +Cc: Stan Hu
In-Reply-To: <cover.1701928891.git.stanhu@gmail.com>
In contrib/completion/git-completion.bash, there are a bunch of
instances where we read pseudorefs, such as HEAD, MERGE_HEAD,
REVERT_HEAD, and others via the filesystem. However, the upcoming
reftable refs backend won't use '.git/HEAD' at all but instead will
write an invalid refname as placeholder for backwards compatibility,
which will break the git-completion script.
Update the '__git_pseudoref_exists' function to:
1. Recognize the placeholder '.git/HEAD' written by the reftable
backend (its content is specified in the reftable specs).
2. If reftable is in use, use 'git rev-parse' to determine whether the
given ref exists.
3. Otherwise, continue to use 'test -f' to check for the ref's filename.
Signed-off-by: Stan Hu <stanhu@gmail.com>
---
contrib/completion/git-completion.bash | 39 ++++++++++++++++++++------
1 file changed, 31 insertions(+), 8 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 9fbdc13f9a..b2e407c7e7 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -122,12 +122,35 @@ __git ()
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
}
-# Runs git in $__git_repo_path to determine whether a ref exists.
-# 1: The ref to search
-__git_ref_exists ()
+# Helper function to read the first line of a file into a variable.
+# __git_eread requires 2 arguments, the file path and the name of the
+# variable, in that order.
+#
+# This is taken from git-prompt.sh.
+__git_eread ()
+{
+ test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
+}
+
+# Runs git in $__git_repo_path to determine whether a pseudoref exists.
+# 1: The pseudo-ref to search
+__git_pseudoref_exists()
{
local ref=$1
+ # If the reftable is in use, we have to shell out to 'git rev-parse'
+ # to determine whether the ref exists instead of looking directly in
+ # the filesystem to determine whether the ref exists. Otherwise, use
+ # Bash builtins since executing Git commands are expensive on some
+ # platforms.
+ if __git_eread "$__git_repo_path/HEAD" head; then
+ b="${head#ref: }"
+ if [ "$b" == "refs/heads/.invalid" ]; then
+ __git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null
+ return $?
+ fi
+ fi
+
[ -f "$__git_repo_path/$ref" ]
}
@@ -1634,7 +1657,7 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
_git_cherry_pick ()
{
__git_find_repo_path
- if __git_ref_exists CHERRY_PICK_HEAD; then
+ if __git_pseudoref_exists CHERRY_PICK_HEAD; then
__gitcomp "$__git_cherry_pick_inprogress_options"
return
fi
@@ -2076,7 +2099,7 @@ _git_log ()
__git_find_repo_path
local merge=""
- if __git_ref_exists MERGE_HEAD; then
+ if __git_pseudoref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$prev,$cur" in
@@ -2962,7 +2985,7 @@ _git_restore ()
__gitcomp_builtin restore
;;
*)
- if __git_ref_exists HEAD; then
+ if __git_pseudoref_exists HEAD; then
__git_complete_index_file "--modified"
fi
esac
@@ -2973,7 +2996,7 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
_git_revert ()
{
__git_find_repo_path
- if __git_ref_exists REVERT_HEAD; then
+ if __git_pseudoref_exists REVERT_HEAD; then
__gitcomp "$__git_revert_inprogress_options"
return
fi
@@ -3602,7 +3625,7 @@ __gitk_main ()
__git_find_repo_path
local merge=""
- if __git_ref_exists MERGE_HEAD; then
+ if __git_pseudoref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$cur" in
--
2.42.0
^ permalink raw reply related
* Re: t7900 fails with recent debian systemd?
From: Jeff King @ 2023-12-07 6:27 UTC (permalink / raw)
To: Eric Sunshine; +Cc: git
In-Reply-To: <CAPig+cT-vCraf2tfA3t3Rh6mLNTr0rB5mApmz0vu2MCRvssaVw@mail.gmail.com>
On Wed, Dec 06, 2023 at 05:40:59PM -0500, Eric Sunshine wrote:
> On Wed, Dec 6, 2023 at 5:36 PM Jeff King <peff@peff.net> wrote:
> > After stracing, it is indeed looking for:
> >
> > trash directory.t7900-maintenance/systemd/user/git-maintenance@hourly.service
> >
> > but that file doesn't exist. We installed git-maintenance@hourly.timer,
> > and git-maintenance@.service. Is the latter supposed to be a wildcard of
> > some kind? Maybe the rules changed. I don't really know anything about
> > systemd.
>
> Apparently, that's intentional. From builtin/gc.c:
>
> /*
> * No matter the schedule, we use the same service and can make
> * use of the templating system. When installing
> * git-maintenance@<schedule>.timer, systemd will notice that
> * git-maintenance@.service exists as a template and will use this
> * file and insert the <schedule> into the template at the
> * position of "%i".
> */
> static int systemd_timer_write_service_template(const char *exec_path)
> {
> char *local_service_name = xstrfmt(SYSTEMD_UNIT_FORMAT, "", "service");
OK, that makes sense, and this is indeed the way to do template files in
systemd.
> I'm not sure why the comment is talking about "%i", though.
The "%i" replacement is done on the contents of the template file
itself. So inside git-maintenance@.service, the ExecStart line specifies
that we should run "git maintenance run --schedule=%i".
This looks like a regression in systemd itself. I was able to bisect and
I left a comment there:
https://github.com/systemd/systemd/pull/30172#issuecomment-1844699620
I don't really see a way to work around it within our test suite, short
of just skipping the "systemd-analyze verify" calls entirely. Hopefully
my analysis is right and they will fix it soon, and we can consider it
"not our problem" on this end. :)
-Peff
^ permalink raw reply
* Re: [PATCH] object-name: reject too-deep recursive ancestor queries
From: Patrick Steinhardt @ 2023-12-07 6:52 UTC (permalink / raw)
To: Jeff King
Cc: Junio C Hamano, Taylor Blau, git,
Carlos Andrés Ramírez Cataño
In-Reply-To: <20231206194035.GB103708@coredump.intra.peff.net>
[-- Attachment #1: Type: text/plain, Size: 2500 bytes --]
On Wed, Dec 06, 2023 at 02:40:35PM -0500, Jeff King wrote:
> On Fri, Nov 24, 2023 at 11:11:53AM +0100, Patrick Steinhardt wrote:
>
> > > When we get "HEAD~~~~~~~~~^2~~~~~~" from the user, do we somehow try
> > > to create a file or a directory with that name and fail due to
> > > ENAMETOOLONG?
> >
> > Sorry, this was a typo on my part. I didn't mean "revision", I meant
> > "reference" here. References are limited to at most 4kB on most
> > platforms due to filesystem limitations, whereas revisions currently
> > have no limits in place.
>
> Even without filesystem limitations, references are effectively limited
> to 64kb due to the pkt-line format.
>
> Revisions can be much longer than a reference, though. We accept
> "some_ref:some/path/in/tree", for instance[1]. I think you could argue
> that paths are likewise limited by the filesystem, though. Even on
> systems like Linux where paths can grow arbitrarily long (by descending
> and adding to the current directory), you're still limited in specifying
> a full pathname. And Git will always use the full path from the project
> root when creating worktree entries. Plus my recent tree-depth patches
> effectively limit us to 16MB in the default config.
I was only able to trigger these issues with _really_ long revisions,
like hundreds of megabytes. But that's on a glibc system, other systems
based on e.g. musl libc have a much smaller stack by default where these
limits would be hit sooner.
> So I think it might be reasonable to limit revision lengths just as a
> belt-and-suspenders against overflow attacks, etc. But I suspect that
> the limits we'd choose there might not match what we'd want for
> protection against stack exhaustion via recursion. E.g., I think 8k is
> probably the minimum I'd want for a revision ("my/4k/ref:my/4k/path").
> If one "~" character can create an expensive recursion, that might be
> too much.
Fair enough. I think combining the two approaches would be sensible as a
defense-in-depth approach.
Patrick
> So we probably need something like Taylor's patch anyway (or to switch
> to an iterative algorithm, though that might be tricky because of the
> way we parse). I agree it needs to handle "^", though.
>
> -Peff
>
> [1] There are other more exotic revisions, too. The most arbitrary-sized
> that comes to mind is ":/some-string-to-match". I doubt anybody
> would be too mad if that were limited to 8k or even 4k, though.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply
* [PATCH] bisect: always clean on reset
From: Jeff King @ 2023-12-07 6:53 UTC (permalink / raw)
To: Janik Haag; +Cc: git
In-Reply-To: <20231113210820.GB2028092@coredump.intra.peff.net>
On Mon, Nov 13, 2023 at 04:08:20PM -0500, Jeff King wrote:
> So really, you just want the "clean" part of "bisect reset", but not the
> "reset". We could have a separate "bisect clean" that would do what you
> want (clean state without trying to reset HEAD). But I don't think it
> would be unreasonable to "reset" to just unconditionally clean. I think
> it would probably just be a few lines in bisect_reset() to avoid the
> early return, and skip the call to "checkout" when we have no branch to
> go back to.
>
> Maybe a good simple patch for somebody interested in getting into Git
> development?
I didn't want to forget about this, so I rolled it up into a patch.
-- >8 --
Subject: [PATCH] bisect: always clean on reset
Usually "bisect reset" cleans up any refs/bisect/ refs, along with
meta-files like .git/BISECT_LOG. But it only does so after deciding that
a bisection is active, which it does by reading BISECT_START. This is
usually fine, but it's possible to get into a confusing state if the
BISECT_START file is gone, but other cruft is left (this might be due to
a bug, or a system crash, etc).
And since "bisect reset" refuses to do anything in this state, the user
has no easy way to clean up the leftover cruft. While another "bisect
start" would clear the state, in the interim it can be annoying, as
other tools (like our bash prompt code) think we are bisecting, and
for-each-ref output may be polluted with refs/bisect/ entries.
Further adding to the confusion is that running "bisect reset $some_ref"
skips the BISECT_START check. So it never realizes that there's no
bisection active and does the cleanup anyway!
So let's just make sure we always do the cleanup, whether we looked at
BISECT_START or not. If the user doesn't give us a commit to reset to,
we'll still say "We are not bisecting" and skip the call to "git
checkout".
Reported-by: Janik Haag <janik@aq0.de>
Signed-off-by: Jeff King <peff@peff.net>
---
builtin/bisect.c | 9 ++++-----
t/t6030-bisect-porcelain.sh | 6 ++++++
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 35938b05fd..c5565686bf 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -233,11 +233,10 @@ static int bisect_reset(const char *commit)
struct strbuf branch = STRBUF_INIT;
if (!commit) {
- if (strbuf_read_file(&branch, git_path_bisect_start(), 0) < 1) {
+ if (!strbuf_read_file(&branch, git_path_bisect_start(), 0))
printf(_("We are not bisecting.\n"));
- return 0;
- }
- strbuf_rtrim(&branch);
+ else
+ strbuf_rtrim(&branch);
} else {
struct object_id oid;
@@ -246,7 +245,7 @@ static int bisect_reset(const char *commit)
strbuf_addstr(&branch, commit);
}
- if (!ref_exists("BISECT_HEAD")) {
+ if (branch.len && !ref_exists("BISECT_HEAD")) {
struct child_process cmd = CHILD_PROCESS_INIT;
cmd.git_cmd = 1;
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 2a5b7d8379..7b24d1684e 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -170,6 +170,12 @@ test_expect_success 'bisect reset when not bisecting' '
cmp branch.expect branch.output
'
+test_expect_success 'bisect reset cleans up even when not bisecting' '
+ echo garbage >.git/BISECT_LOG &&
+ git bisect reset &&
+ test_path_is_missing .git/BISECT_LOG
+'
+
test_expect_success 'bisect reset removes packed refs' '
git bisect reset &&
git bisect start &&
--
2.43.0.664.ga12c899002
^ permalink raw reply related
* Re: [PATCH] setup: recognize bare repositories with packed-refs
From: Patrick Steinhardt @ 2023-12-07 7:01 UTC (permalink / raw)
To: Jeff King; +Cc: Adam Majer, git
In-Reply-To: <20231206201048.GE103708@coredump.intra.peff.net>
[-- Attachment #1: Type: text/plain, Size: 5150 bytes --]
On Wed, Dec 06, 2023 at 03:10:48PM -0500, Jeff King wrote:
> On Wed, Nov 29, 2023 at 11:13:18AM +0100, Patrick Steinhardt wrote:
>
> > As I'm currently working on the reftable backend this thought has also
> > crossed my mind. The reftable backend doesn't only create "refs/", but
> > it also creates "HEAD" with contents "ref: refs/heads/.invalid" so that
> > Git commands recognize the Git directory properly. Longer-term I would
> > really love to see us doing a better job of detecting Git repositories
> > so that we don't have to carry this legacy baggage around.
> >
> > I can see different ways for how to do this:
> >
> > - Either we iterate through all known reference backends, asking
> > each of them whether they recognize the directory as something
> > they understand.
> >
> > - Or we start parsing the gitconfig of the repository so that we can
> > learn about which reference backend to expect, and then ask that
> > specific backend whether it thinks that the directory indeed looks
> > like something it can handle.
> >
> > I'd personally prefer the latter, but I'm not sure whether we really
> > want to try and parse any file that happens to be called "config".
>
> We do eventually parse the config file to pick up repositoryFormatVersion.
> But there's sort of a chicken-and-egg here where we only do so after
> gaining some confidence that it's a repo directory. :)
>
> I actually think the "ask each backend if it looks plausible" is
> reasonable, at least for an implementation that knows about all
> backends. Though what gives me pause is how older versions of Git will
> behave with a new-format repository that does not have a "refs"
> directory.
>
> There are really two compatibility checks. In is_git_directory(), we
> want to say "is this a repo or not". And then later we parse the config,
> make sure the repository format is OK, and that we support all
> extensions. So right now, an older version of Git that encounters a
> reftable-formatted repo (that has a vestigial "refs/" directory) says
> "ah, that is a repo, but I don't understand it" (the latter because
> presumably the repo version/extensions in .git/config are values it
> doesn't know about). But if we get rid of "refs/", then older versions
> of Git will stop even considering it as a repo at all, and will keep
> searching up to the ceiling directory. So either:
>
> 1. They'll find nothing, and you'll get "you're not in a git repo",
> rather than "you're in a git repo, but I don't understand it".
> Which is slightly worse.
>
> 2. They'll find some _other_ containing repo. Which could be quite
> confusing.
>
> So forgetting at all about how we structure the code, it seems to me
> that the problem is not new code, but all of the existing code which
> looks for access("refs", X_OK).
True. The question is of course how much value there is in an old tool
to be able to discover a new repository that it wouldn't be able to read
in the first place due to it not understanding the reference format. So
I'd very much like to see that eventually, we're able to get rid of
"legacy" cruft that doesn't serve any purpose anymore.
The question is whether we can do a better job of this going forward so
that at least we don't have to pose the same question in the future.
Right now, we'll face the same problem whenever any part of the current
on-disk repository data structures changes.
I wonder whether it would make sense to introduce something like a
filesystem-level hint, e.g. in the form of a new ".is-git-repository"
file. If Git discovers that file then it assumes the directory to be a
Git repository -- and everything else is set up by parsing the config
and thus the repository's configured format.
> I dunno. Maybe that is being too paranoid about backwards compatibility.
> People will have to turn on reftable manually, at least for a while, and
> would hopefully know what they are signing up for, and that old versions
> might not work as well. And by the time a new format becomes the
> default, it's possible that those older versions would have become quite
> rare.
>
> > Just throwing this out there, but we could use this as an excuse to
> > introduce "extensions.refFormat". If it's explicitly configured to be
> > "reffiles" then we accept repositories even if they don't have the
> > "refs/" directory or a "packed-refs" file. This would still require work
> > in alternative implementations of Git, but this work will need to happen
> > anyway when the reftable backend lands.
> >
> > I'd personally love for this extension to be introduced before I'm
> > sending the reftable backend upstream so that we can have discussions
> > around it beforehand.
>
> We already have an extension config option to specify that we're using
> reftable, don't we? But anything in config has the same chicken-and-egg
> problems as above, I think.
Not yet, no. I plan to submit the new "extensions.refFormat" extension
soonish though, probably next week.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox