Skip to contentSkip to conversation

notes: handle multiple worktrees

PATCH Superseded David Turner 2 participants 4 messages Jun 15, 2016

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 notes: handle multiple worktrees

Before creating NOTES_MERGE_REF, check NOTES_MERGE_REF using die_if_shared_symref. This prevents simultaneous merges to the same notes branch from different worktrees.

---

This version addresses Eric Sunshine's critiques of v1. It breaks out the symref-checking functionality into die_if_shared_symref, leaving die_if_checked_out to handle HEAD.

---
 builtin/notes.c                  |  2 ++
 t/t3320-notes-merge-worktrees.sh | 71 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100755 t/t3320-notes-merge-worktrees.sh
builtin/notes.c +2 -0
index 63f95fc..78a264e 100644
@@ -19,6 +19,7 @@
 #include "string-list.h"
 #include "notes-merge.h"
 #include "notes-utils.h"
+#include "branch.h"
 
 static const char * const git_notes_usage[] = {
 	N_("git notes [--ref <notes-ref>] [list [<object>]]"),
@@ -829,6 +830,7 @@ static int merge(int argc, const char **argv, const char *prefix)
 		update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL,
 			   0, UPDATE_REFS_DIE_ON_ERR);
 		/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
+		die_if_shared_symref("NOTES_MERGE_REF", default_notes_ref());
 		if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
 			die("Failed to store link to current notes ref (%s)",
 			    default_notes_ref());
t/t3320-notes-merge-worktrees.sh new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
#1 lore raw
Quoted 12 lines · David Turner

Before creating NOTES_MERGE_REF, check NOTES_MERGE_REF using die_if_shared_symref. This prevents simultaneous merges to the same notes branch from different worktrees.

---

This version addresses Eric Sunshine's critiques of v1. It breaks out the symref-checking functionality into die_if_shared_symref, leaving die_if_checked_out to handle HEAD.

Quoted 5 lines
---
 builtin/notes.c                  |  2 ++
 t/t3320-notes-merge-worktrees.sh | 71 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100755 t/t3320-notes-merge-worktrees.sh

Hmm, is this the whole thing?

Or is a prerequisite patch to add that "symref check" infrastructure missing on the receiving end?

This is a tangent, but there is a bigger spanner in "bisect". It uses refs/bisect/* to keep track of the current bisection state, but that state is tied to a particular worktree, and it should not be shared across other worktrees.

We need to reserve a part of refs/* hierarchy (e.g. refs/private/*) for per worktree private stuff and handle them just like we do per-worktree pseudorefs, or something like that.

#2 lore raw
Quoted 20 lines · Junio C Hamano
Quoted 12 lines · David Turner

Before creating NOTES_MERGE_REF, check NOTES_MERGE_REF using die_if_shared_symref. This prevents simultaneous merges to the same notes branch from different worktrees.

---

This version addresses Eric Sunshine's critiques of v1. It breaks out the symref-checking functionality into die_if_shared_symref, leaving die_if_checked_out to handle HEAD.

Quoted 5 lines
---
 builtin/notes.c                  |  2 ++
 t/t3320-notes-merge-worktrees.sh | 71 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100755 t/t3320-notes-merge-worktrees.sh
Quoted 4 lines

Hmm, is this the whole thing?

Or is a prerequisite patch to add that "symref check" infrastructure missing on the receiving end?

Oops, resent with first patch included -- I forgot I had split it.

Quoted 4 lines

This is a tangent, but there is a bigger spanner in "bisect". It uses refs/bisect/* to keep track of the current bisection state, but that state is tied to a particular worktree, and it should not be shared across other worktrees.

Good point.

Quoted 3 lines

We need to reserve a part of refs/* hierarchy (e.g. refs/private/*) for per worktree private stuff and handle them just like we do per-worktree pseudorefs, or something like that.

In the pseudorefs series, is_per_worktree_ref is a separate function precisely so that we can make this sort of change. To bikeshed a bit, I propose worktree_refs/*, since:

(a) "private" can have many meanings, and
(b) common_list in path.c doesn't do exceptions ("refs/ except refs/worktree/"). We could of course do a manual exception, but that's not pretty.

I further propose to add some patches (to go on top of the pseudorefs series):

(a) include worktree-refs/ in per_worktree_refs and include worktree-refs/ in per_worktree_refs in common_list, and
(b) include changes to bisect which switches it over to use worktree_refs/*. To make this change compatible with bisections started with old git versions, we should just unconditionally rename refs/bisect to worktree-refs/bisect, and, in the event of EISDIR (meaning that both refs/bisect and worktree-refs/bisect exist), die with a message explaining the situation.

#3 lore raw
Quoted 5 lines · David Turner

I further propose to add some patches (to go on top of the pseudorefs series):

(a) include worktree-refs/ in per_worktree_refs and include worktree-refs/ in per_worktree_refs in common_list, and

Do you mean .git/worktree-refs/, just next to .git/refs? Then I think it makes sense.

Quoted 3 lines

(b) include changes to bisect which switches it over to use worktree_refs/*. To make this change compatible with bisections started with old git versions,...

I personally am not sure if it is worth the effort to cater to those who start bisection, stop and then upgrade their git version and expect to continue.