All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Christian Couder <chriscool@tuxfamily.org>,
	Thomas Rast <trast@inf.ethz.ch>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v2 6/8] cherry-pick: add support to copy notes
Date: Tue, 28 May 2013 22:56:26 -0500	[thread overview]
Message-ID: <1369799788-24803-7-git-send-email-felipe.contreras@gmail.com> (raw)
In-Reply-To: <1369799788-24803-1-git-send-email-felipe.contreras@gmail.com>

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/revert.c  |  2 ++
 sequencer.c       | 33 ++++++++++++++++++++++++++++++++-
 sequencer.h       |  1 +
 t/t3500-cherry.sh | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index 0e5ce71..b977124 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -119,6 +119,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 		OPT_END(),
 		OPT_END(),
 		OPT_END(),
+		OPT_END(),
 	};
 
 	if (opts->action == REPLAY_PICK) {
@@ -129,6 +130,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 			OPT_BOOLEAN(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")),
 			OPT_BOOLEAN(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")),
 			OPT_BOOLEAN(0, "skip-empty", &opts->skip_empty, N_("skip empty commits")),
+			OPT_BOOLEAN(0, "copy-notes", &opts->copy_notes, N_("copy notes")),
 			OPT_END(),
 		};
 		if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra))
diff --git a/sequencer.c b/sequencer.c
index 3aa480e..cc9c2bc 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -127,6 +127,27 @@ static void add_rewritten(unsigned char *from, unsigned char *to)
 	rewritten.nr++;
 }
 
+static void copy_notes(void)
+{
+	unsigned char note_commit[20];
+	struct strbuf buf = STRBUF_INIT;
+	struct notes_tree *t = &default_notes_tree;
+	int i;
+
+	init_notes(t, NULL, NULL, 0);
+
+	for (i = 0; i < rewritten.nr; i++) {
+		struct rewritten_list_item *item = &rewritten.items[i];
+		copy_note(t, item->from, item->to, 0, NULL);
+	}
+
+	strbuf_addstr(&buf, "Notes added by 'git cherry-pick'\n");
+	create_notes_commit(&default_notes_tree, NULL, &buf, note_commit);
+	strbuf_insert(&buf, 0, "notes: ", 7);
+	update_ref(buf.buf, t->ref, note_commit, NULL, 0, MSG_ON_ERR);
+	strbuf_release(&buf);
+}
+
 static void run_rewrite_hook(void)
 {
 	struct strbuf buf = STRBUF_INIT;
@@ -908,7 +929,10 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
 	else if (!strcmp(key, "options.strategy-option")) {
 		ALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc);
 		opts->xopts[opts->xopts_nr++] = xstrdup(value);
-	} else
+	}
+	else if (!strcmp(key, "options.copy-notes"))
+		opts->copy_notes = git_config_bool_or_int(key, value, &error_flag);
+	else
 		return error(_("Invalid key: %s"), key);
 
 	if (!error_flag)
@@ -1108,6 +1132,8 @@ static void save_opts(struct replay_opts *opts)
 							"options.strategy-option",
 							opts->xopts[i], "^$", 0);
 	}
+	if (opts->copy_notes)
+		git_config_set_in_file(opts_file, "options.copy-notes", "true");
 }
 
 static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
@@ -1132,6 +1158,9 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
 
 	run_rewrite_hook();
 
+	if (opts->copy_notes)
+		copy_notes();
+
 	/*
 	 * Sequence of picks finished successfully; cleanup by
 	 * removing the .git/sequencer directory
@@ -1186,6 +1215,8 @@ static int single_pick(struct commit *cmit, struct replay_opts *opts)
 	if (ret)
 		return ret;
 	run_rewrite_hook();
+	if (opts->copy_notes)
+		copy_notes();
 	return 0;
 }
 
diff --git a/sequencer.h b/sequencer.h
index 84b9957..6cc072c 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -36,6 +36,7 @@ struct replay_opts {
 	int allow_empty_message;
 	int keep_redundant_commits;
 	int skip_empty;
+	int copy_notes;
 
 	int mainline;
 
diff --git a/t/t3500-cherry.sh b/t/t3500-cherry.sh
index f038f34..79c1219 100755
--- a/t/t3500-cherry.sh
+++ b/t/t3500-cherry.sh
@@ -55,4 +55,36 @@ test_expect_success \
      expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
 '
 
+test_expect_success \
+    'copy notes' \
+    'git checkout master &&
+    echo notes > C &&
+    test_tick &&
+    git commit -a -m "Update C" &&
+    git notes add -m "a note" &&
+    git checkout -b note-test HEAD^ &&
+    git cherry-pick --copy-notes -x master &&
+    test "a note" = "$(git notes show HEAD)"
+'
+
+test_expect_success \
+    'copy multiple notes' \
+    'git checkout master &&
+    echo "multiple notes" > C &&
+    git commit -a -m "Update C again" &&
+    git notes add -m "another note" &&
+    git commit -a -m "Empty" --allow-empty &&
+    echo "more notes" > C &&
+    git commit -a -m "Update C once more" &&
+    git notes add -m "final note" &&
+    git checkout note-test &&
+    git reset --hard master~3 &&
+    test_expect_code 1 git cherry-pick --copy-notes -x HEAD..master &&
+    git reset --hard &&
+    git cherry-pick --continue
+    test "a note" = "$(git notes show HEAD~2)" &&
+    test "another note" = "$(git notes show HEAD~1)" &&
+    test "final note" = "$(git notes show HEAD)"
+'
+
 test_done
-- 
1.8.3.rc3.312.g47657de

  parent reply	other threads:[~2013-05-29  3:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29  3:56 [PATCH v2 0/8] cherry-pick: improvements Felipe Contreras
2013-05-29  3:56 ` [PATCH v2 1/8] sequencer: remove useless indentation Felipe Contreras
2013-05-29  3:56 ` [PATCH v2 2/8] sequencer: trivial fix Felipe Contreras
2013-05-29  3:56 ` [PATCH v2 3/8] cherry-pick: add --skip-empty option Felipe Contreras
2013-06-03 18:40   ` Junio C Hamano
2013-06-03 19:21     ` Junio C Hamano
2013-06-03 21:10     ` Felipe Contreras
2013-06-03 21:45       ` Junio C Hamano
2013-06-04 17:10         ` Felipe Contreras
2013-06-04 17:35           ` Junio C Hamano
2013-06-04 17:40             ` Felipe Contreras
2013-06-04 18:30               ` Junio C Hamano
2013-06-05 14:52                 ` Felipe Contreras
2013-06-05 18:13                   ` Junio C Hamano
2013-06-06  5:01                     ` Felipe Contreras
2013-06-04  6:31       ` Antoine Pelisse
2013-05-29  3:56 ` [PATCH v2 4/8] cherry-pick: store rewritten commits Felipe Contreras
2013-06-03 18:49   ` Junio C Hamano
2013-06-03 20:55     ` Felipe Contreras
2013-05-29  3:56 ` [PATCH v2 5/8] sequencer: run post-rewrite hook Felipe Contreras
2013-06-03 18:57   ` Junio C Hamano
2013-06-03 21:01     ` Felipe Contreras
2013-06-04  9:03     ` Thomas Rast
2013-05-29  3:56 ` Felipe Contreras [this message]
2013-05-29  3:56 ` [PATCH v2 7/8] revert/cherry-pick: add --quiet option Felipe Contreras
2013-05-29 12:33   ` Ramkumar Ramachandra
2013-05-29 13:28     ` Felipe Contreras
2013-05-29 13:32       ` Ramkumar Ramachandra
2013-05-29 13:40         ` Felipe Contreras
2013-06-03 18:59   ` Junio C Hamano
2013-05-29  3:56 ` [PATCH v2 8/8] revert/cherry-pick: add --skip option Felipe Contreras
2013-05-29 12:27   ` Ramkumar Ramachandra
2013-05-29 13:27     ` Felipe Contreras

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

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

  git send-email \
    --in-reply-to=1369799788-24803-7-git-send-email-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=trast@inf.ethz.ch \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.