git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Victoria Dye <vdye@github.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Rubén Justo" <rjusto@gmail.com>
Cc: Git List <git@vger.kernel.org>, Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH 2/2] branch: clear target branch configuration before copying or renaming
Date: Fri, 18 Nov 2022 08:36:41 -0800	[thread overview]
Message-ID: <ddc1b100-98f3-7ddf-aa2b-af080cb40443@github.com> (raw)
In-Reply-To: <221118.864juwhkcc.gmgdl@evledraar.gmail.com>

Ævar Arnfjörð Bjarmason wrote:
> 
> On Thu, Nov 17 2022, Rubén Justo wrote:
>> Whenever we copy or move (forced or not) we must make sure that there is
>> no residual configuration that will be, probably erroneously, inherited
>> by the new branch.  To avoid confusions, clear any branch configuration
>> before setting the configuration from the copied or moved branch.
> 
> So, whatever tea leaves we read into the history, or whether this was a
> good or bad design in the first place, I think we should probably lean
> towards not having this be a bug fix, but a new feature. Both modes are
> clearly easy to support.
> 
> And then document it in terms of some new switch being the equivalent to
> --remove-section followed by a rename, the existing thing a rename etc.

I've noticed a bit of a pattern on the mailing list where, if the desired
user experience is unclear, the suggestion is "add an option! then users can
choose for themselves." But then, at the same time, we'll complain about
option bloat (as you [1] and Taylor [2] did on another recent series).

I don't see a compelling enough reason to introduce an option variant here.
Could I imagine a user wanting such a feature? Yes. But it also isn't clear
what users would practically use. I think a more conservative approach would
be appropriate: in this case, come to an agreement on a sane default (i.e.,
should we preserve the source's, or the destination's, tracking config?),
then wait for feedback to indicate whether there's a desire for an
alternative to that default.

[1] https://lore.kernel.org/git/221117.86k03tiudl.gmgdl@evledraar.gmail.com/
[2] https://lore.kernel.org/git/Y3ave2+kEwLTvtE6@nand.local/

> 
>> @@ -583,12 +583,17 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
>>  
>>  	strbuf_release(&logmsg);
>>  
>> -	strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
>> -	strbuf_addf(&newsection, "branch.%s", interpreted_newname);
>> -	if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
>> -		die(_("Branch is renamed, but update of config-file failed"));
>> -	if (copy && strcmp(interpreted_oldname, interpreted_newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
>> -		die(_("Branch is copied, but update of config-file failed"));
>> +	if (strcmp(interpreted_oldname, interpreted_newname)) {
>> +		strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
>> +		strbuf_addf(&newsection, "branch.%s", interpreted_newname);
>> +
>> +		delete_branch_config(interpreted_newname);
>> +
>> +		if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
>> +			die(_("Branch is renamed, but update of config-file failed"));
>> +		if (copy && git_config_copy_section(oldsection.buf, newsection.buf) < 0)
>> +			die(_("Branch is copied, but update of config-file failed"));
> 
> Aside from any question of a hypothetical "should", your implementation
> is running head-first into a major caveat in our config API.
> 
> Which is that we don't have transactions or rollbacks, and we don't even
> carry a lock forward for all of these.
> 
> So, there's crappy edge cases in the old implementation as you've found,
> but at least it mostly failed-safe.
> 
> But here we'll delete_branch_config(), then release the lock, and then
> try to rename the new branch to that location, which might fail.
> 
> So, we'll be left with no config for the thing we tried to clobber, nor
> the new config.

This is a good point, so to add to it: I think a fairly unobtrusive solution
would be to move the config deletion after the rename is 100% complete.


  reply	other threads:[~2022-11-18 16:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17  1:33 [PATCH 0/2] branch: fix some malfunctions in -m/-c Rubén Justo
2022-11-17  1:36 ` [PATCH 1/2] branch: force-copy a branch to itself via @{-1} is a no-op Rubén Justo
2022-11-17 22:18   ` Victoria Dye
2022-11-20  8:10     ` Rubén Justo
2022-11-18  3:58   ` Ævar Arnfjörð Bjarmason
2022-11-20  9:34     ` Rubén Justo
2022-11-17  1:44 ` [PATCH 2/2] branch: clear target branch configuration before copying or renaming Rubén Justo
2022-11-18  2:10   ` Victoria Dye
2022-11-20  9:20     ` Rubén Justo
2022-11-20 22:10       ` Victoria Dye
2022-11-21 23:13         ` Rubén Justo
2022-11-18  4:51   ` Ævar Arnfjörð Bjarmason
2022-11-18 16:36     ` Victoria Dye [this message]
2022-11-18 18:12       ` Ævar Arnfjörð Bjarmason
2022-11-20 14:55         ` Rubén Justo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ddc1b100-98f3-7ddf-aa2b-af080cb40443@github.com \
    --to=vdye@github.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=rjusto@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).