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

[PATCH v8 5/8] notes: implement parse_combine_rewrite_fn using parse_notes_merge_strategy

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Aug 17, 2015, 08:46 UTC
Message-ID
<1439801191-3026-6-git-send-email-jacob.e.keller@intel.com>
In-Reply-To
<1439801191-3026-1-git-send-email-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>

Teach the rewrite combine notes to use the same names as git-notes merge. This will support all current names plus a few new synonyms.

Update documentation to point to NOTES MERGE STRATEGIES to explain the various rewrite options available.

Implementing rewrite functionality completely in terms of merging is left as an exercise for a future contributor.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 Documentation/config.txt    |  8 ++++---
 Documentation/git-notes.txt | 18 ++++++++++-----
 notes-utils.c               | 26 +++++++++++++--------
 t/t3301-notes.sh            | 55 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 89 insertions(+), 18 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index de67ad1fdedf..4daa804b1eab 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1946,9 +1946,11 @@ notes.rewrite.<command>::
 notes.rewriteMode::
 	When copying notes during a rewrite (see the
 	"notes.rewrite.<command>" option), determines what to do if
-	the target commit already has a note.  Must be one of
-	`overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
-	Defaults to `concatenate`.
+	the target commit already has a note.  With the exception of `manual`,
+	any automatic merge strategy may be chosen.  Beware that in the
+	re-write context the typical notion of `ours` and `theirs` is reversed.
+	See the "NOTES MERGE STRATEGIES" section above for information on each
+	of the available strategies.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index 5028e9355de5..678dadfdf3c3 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -336,9 +336,11 @@ environment variable.
 
 notes.rewriteMode::
 	When copying notes during a rewrite, what to do if the target
-	commit already has a note.  Must be one of `overwrite`,
-	`concatenate`, `cat_sort_uniq`, or `ignore`.  Defaults to
-	`concatenate`.
+	commit already has a note.  With the exception of `manual`, any
+	automatic merge strategy may be chosen.  Beware that in the re-write
+	context the typical notion of `ours` and `theirs` is reversed .  See
+	the "NOTES MERGE STRATEGIES" section above for information on each of
+	the available strategies.
 +
 This setting can be overridden with the `GIT_NOTES_REWRITE_MODE`
 environment variable.
@@ -374,9 +376,13 @@ does not match any refs is silently ignored.
 
 'GIT_NOTES_REWRITE_MODE'::
 	When copying notes during a rewrite, what to do if the target
-	commit already has a note.
-	Must be one of `overwrite`, `concatenate`, `cat_sort_uniq`, or `ignore`.
-	This overrides the `core.rewriteMode` setting.
+	commit already has a note.  With the exception of `manual`, any
+	automatic merge strategy may be chosen.  Beware that in the re-write
+	context the typical notion of `ours` and `theirs` is reversed .  See
+	the "NOTES MERGE STRATEGIES" section above for information on each of
+	the available strategies.
++
+Overrides the notes.rewriteMode configuration option.
 
 'GIT_NOTES_REWRITE_REF'::
 	When rewriting commits, which notes to copy from the original
diff --git a/notes-utils.c b/notes-utils.c
index 656b0ea152e2..8d4cc8909bcf 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -80,16 +80,24 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s)
 
 static combine_notes_fn parse_combine_notes_fn(const char *v)
 {
-	if (!strcasecmp(v, "overwrite"))
-		return combine_notes_overwrite;
-	else if (!strcasecmp(v, "ignore"))
-		return combine_notes_ignore;
-	else if (!strcasecmp(v, "concatenate"))
-		return combine_notes_concatenate;
-	else if (!strcasecmp(v, "cat_sort_uniq"))
-		return combine_notes_cat_sort_uniq;
-	else
+	enum notes_merge_strategy s;
+
+	if (parse_notes_merge_strategy(v, &s))
 		return NULL;
+
+	switch (s) {
+	case NOTES_MERGE_RESOLVE_OURS:
+		return combine_notes_ignore;
+	case NOTES_MERGE_RESOLVE_THEIRS:
+		return combine_notes_overwrite;
+	case NOTES_MERGE_RESOLVE_UNION:
+		return combine_notes_concatenate;
+	case NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:
+		return combine_notes_cat_sort_uniq;
+	case NOTES_MERGE_RESOLVE_MANUAL:
+	default:
+		return NULL;
+	}
 }
 
 static int notes_rewrite_config(const char *k, const char *v, void *cb)
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 8cffd35fb03d..eb1b5824a422 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -997,6 +997,26 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git notes copy --for-rewrite (theirs)' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
+
+		${indent}15th
+
+		Notes:
+		${indent}a fresh note
+	EOF
+	git notes add -f -m"a fresh note" HEAD^ &&
+	test_config notes.rewriteMode theirs &&
+	test_config notes.rewriteRef "refs/notes/*" &&
+	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	git notes copy --for-rewrite=foo &&
+	git log -1 >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_config notes.rewriteMode ignore &&
 	test_config notes.rewriteRef "refs/notes/*" &&
@@ -1006,6 +1026,15 @@ test_expect_success 'git notes copy --for-rewrite (ignore)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git notes copy --for-rewrite (ours)' '
+	test_config notes.rewriteMode ours &&
+	test_config notes.rewriteRef "refs/notes/*" &&
+	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	git notes copy --for-rewrite=foo &&
+	git log -1 >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git notes copy --for-rewrite (append)' '
 	cat >expect <<-EOF &&
 		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
@@ -1028,6 +1057,30 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'git notes copy --for-rewrite (union append)' '
+	cat >expect <<-EOF &&
+		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
+		Author: A U Thor <author@example.com>
+		Date:   Thu Apr 7 15:27:13 2005 -0700
+
+		${indent}15th
+
+		Notes:
+		${indent}a fresh note
+		${indent}
+		${indent}another fresh note
+		${indent}
+		${indent}yet again a fresh note
+	EOF
+	git notes add -f -m"yet again a fresh note" HEAD^ &&
+	test_config notes.rewriteMode union &&
+	test_config notes.rewriteRef "refs/notes/*" &&
+	echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
+	git notes copy --for-rewrite=foo &&
+	git log -1 >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 	cat >expect <<-EOF &&
 		commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
@@ -1041,6 +1094,8 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 		${indent}
 		${indent}another fresh note
 		${indent}
+		${indent}yet again a fresh note
+		${indent}
 		${indent}append 1
 		${indent}
 		${indent}append 2
-- 
2.5.0.280.g4aaba03
Previous: Junio C HamanoNext: Jacob Keller
Message 9 of 14 in “implement notes.mergeStrategy option”
  1. 0/8 implement notes.mergeStrategy optionJacob Keller, Aug 17, 2015
  2. 1/8 notes: document cat_sort_uniq rewriteModeJacob Keller, Aug 17, 2015
  3. 2/8 notes: extract enum notes_merge_strategy to notes-utils.hJacob Keller, Aug 17, 2015
  4. 3/8 note: extract parse_notes_merge_strategy to notes-utilsJacob Keller, Aug 17, 2015
  5. 4/8 notes: allow use of the "rewrite" terminology for merge strategiesJacob Keller, Aug 17, 2015
  6. Johan HerlandAug 17, 2015
  7. Jacob KellerAug 17, 2015
  8. Junio C HamanoAug 17, 2015
  9. 5/8 notes: implement parse_combine_rewrite_fn using parse_notes_merge_strategyJacob Keller, Aug 17, 2015
  10. 6/8 notes: add tests for --commit/--abort/--strategy exclusivityJacob Keller, Aug 17, 2015
  11. 7/8 notes: add notes.mergeStrategy option to select default strategyJacob Keller, Aug 17, 2015
  12. 8/8 notes: teach git-notes about notes.<ref>.mergeStrategy optionJacob Keller, Aug 17, 2015
  13. Johan HerlandAug 17, 2015
  14. Jacob KellerAug 17, 2015

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.