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

[PATCH v2 5/8] sequencer: run post-rewrite hook

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 29, 2013, 03:56 UTC
Message-ID
<1369799788-24803-6-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1369799788-24803-1-git-send-email-felipe.contreras@gmail.com>
As we should.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 sequencer.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/sequencer.c b/sequencer.c
index c217716..3aa480e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -127,6 +127,37 @@ static void add_rewritten(unsigned char *from, unsigned char *to)
 	rewritten.nr++;
 }
 
+static void run_rewrite_hook(void)
+{
+	struct strbuf buf = STRBUF_INIT;
+	struct child_process proc;
+	const char *argv[3];
+	int code, i;
+
+	argv[0] = find_hook("post-rewrite");
+	if (!argv[0])
+		return;
+
+	argv[1] = "rebase";
+	argv[2] = NULL;
+
+	memset(&proc, 0, sizeof(proc));
+	proc.argv = argv;
+	proc.in = -1;
+	proc.stdout_to_stderr = 1;
+
+	code = start_command(&proc);
+	if (code)
+		return;
+	for (i = 0; i < rewritten.nr; i++) {
+		struct rewritten_list_item *item = &rewritten.items[i];
+		strbuf_addf(&buf, "%s %s\n", sha1_to_hex(item->from), sha1_to_hex(item->to));
+	}
+	write_in_full(proc.in, buf.buf, buf.len);
+	close(proc.in);
+	finish_command(&proc);
+}
+
 static void remove_sequencer_state(void)
 {
 	struct strbuf seq_dir = STRBUF_INIT;
@@ -1099,6 +1130,8 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
 		}
 	}
 
+	run_rewrite_hook();
+
 	/*
 	 * Sequence of picks finished successfully; cleanup by
 	 * removing the .git/sequencer directory
@@ -1136,14 +1169,24 @@ static int sequencer_continue(struct replay_opts *opts)
 	}
 	if (index_differs_from("HEAD", 0))
 		return error_dirty_index(opts);
+	{
+		unsigned char to[20];
+		if (!read_ref("HEAD", to))
+			add_rewritten(todo_list->item->object.sha1, to);
+	}
 	todo_list = todo_list->next;
 	return pick_commits(todo_list, opts);
 }
 
 static int single_pick(struct commit *cmit, struct replay_opts *opts)
 {
+	int ret;
 	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
-	return do_pick_commit(cmit, opts);
+	ret = do_pick_commit(cmit, opts);
+	if (ret)
+		return ret;
+	run_rewrite_hook();
+	return 0;
 }
 
 int sequencer_pick_revisions(struct replay_opts *opts)
-- 
1.8.3.rc3.312.g47657de
Previous: Felipe ContrerasNext: Junio C Hamano
Message 20 of 33 in “cherry-pick: improvements”
  1. 0/8 cherry-pick: improvementsFelipe Contreras, May 29, 2013
  2. 1/8 sequencer: remove useless indentationFelipe Contreras, May 29, 2013
  3. 2/8 sequencer: trivial fixFelipe Contreras, May 29, 2013
  4. 3/8 cherry-pick: add --skip-empty optionFelipe Contreras, May 29, 2013
  5. Junio C HamanoJun 3, 2013
  6. Junio C HamanoJun 3, 2013
  7. Felipe ContrerasJun 3, 2013
  8. Junio C HamanoJun 3, 2013
  9. Felipe ContrerasJun 4, 2013
  10. Junio C HamanoJun 4, 2013
  11. Felipe ContrerasJun 4, 2013
  12. Junio C HamanoJun 4, 2013
  13. Felipe ContrerasJun 5, 2013
  14. Junio C HamanoJun 5, 2013
  15. Felipe ContrerasJun 6, 2013
  16. Antoine PelisseJun 4, 2013
  17. 4/8 cherry-pick: store rewritten commitsFelipe Contreras, May 29, 2013
  18. Junio C HamanoJun 3, 2013
  19. Felipe ContrerasJun 3, 2013
  20. 5/8 sequencer: run post-rewrite hookFelipe Contreras, May 29, 2013
  21. Junio C HamanoJun 3, 2013
  22. Felipe ContrerasJun 3, 2013
  23. Thomas RastJun 4, 2013
  24. 6/8 cherry-pick: add support to copy notesFelipe Contreras, May 29, 2013
  25. 7/8 revert/cherry-pick: add --quiet optionFelipe Contreras, May 29, 2013
  26. Ramkumar RamachandraMay 29, 2013
  27. Felipe ContrerasMay 29, 2013
  28. Ramkumar RamachandraMay 29, 2013
  29. Felipe ContrerasMay 29, 2013
  30. Junio C HamanoJun 3, 2013
  31. 8/8 revert/cherry-pick: add --skip optionFelipe Contreras, May 29, 2013
  32. Ramkumar RamachandraMay 29, 2013
  33. Felipe ContrerasMay 29, 2013

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.