git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] branch: update all per-worktree HEADs when renaming a branch

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 22, 2016, 00:49 UTC
Message-ID
<CACsJy8BKBiYTsp5wv9ynr++p2TE-dzS9J+DkOPEKumCL-reLVw@mail.gmail.com>
In-Reply-To
<CAPig+cRQj4td82DuqL0tD=3znLAmT4nBrfOjK3phqM7iomQseA@mail.gmail.com>
On Tue, Mar 22, 2016 at 12:41 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 33 quoted lines
>> diff --git a/worktree.c b/worktree.c
>> @@ -217,3 +217,41 @@ char *find_shared_symref(const char *symref, const char *target)
>> +int update_worktrees_head_symref(const char *oldref, const char *newref)
>> +{
>> +       int error = 0;
>> +       struct strbuf path = STRBUF_INIT;
>> +       struct strbuf origref = STRBUF_INIT;
>> +       int i;
>> +       struct worktree **worktrees = get_worktrees();
>> +
>> +       for (i = 0; worktrees[i]; i++) {
>> +               if (worktrees[i]->is_detached)
>> +                       continue;
>> +
>> +               strbuf_reset(&path);
>> +               strbuf_reset(&origref);
>> +               strbuf_addf(&path, "%s/HEAD", worktrees[i]->git_dir);
>> +
>> +               if (parse_ref(path.buf, &origref, NULL))
>> +                       continue;
>> +
>> +               if (!strcmp(origref.buf, oldref)) {
>> +                       int prefix_len = strlen(absolute_path(get_git_common_dir())) + 1;
>> +                       const char *symref = path.buf + prefix_len;
>> +
>> +                       /* no need to pass logmsg here as HEAD didn't really move */
>> +                       if (create_symref(symref, newref, NULL)) {
>> +                               error = -1;
>> +                               break;
>
> Is aborting upon the first error desired behavior? (Genuine question.)
> Would it make more sense to continue attempting the rename for the
> remaining worktrees (and remember that an error was encountered)?

Since all these HEADs stay at the same (or close) location, if one fails, I think the rest will fail too. Which leads to a series of warnings if we continue anyway. A more interesting approach is update HEADs in a transaction, so we successfully update all or we update none. But I do not know if ref transactions can be used for HEAD, especially worktree HEADs. I'm ok with either abort here or continue anyway, though.

-- 
Duy
Previous: Eric SunshineNext: Kazuki Yamaguchi
Message 3 of 5 in “branch: update all per-worktree HEADs when renaming a branch”
  1. branch: update all per-worktree HEADs when renaming a branchKazuki Yamaguchi, Mar 21, 2016
  2. Eric SunshineMar 21, 2016
  3. Duy NguyenMar 22, 2016
  4. Kazuki YamaguchiMar 25, 2016
  5. Kazuki YamaguchiMar 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.