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

[PATCH 5/5] sequencer: replace write_cherry_pick_head with update_ref

From
David Turner <dturner@twopensource.com>
Date
Jul 27, 2015, 20:08 UTC
Message-ID
<1438027720-23074-6-git-send-email-dturner@twopensource.com>
In-Reply-To
<1438027720-23074-1-git-send-email-dturner@twopensource.com>

Now update_ref (via write_pseudoref) does almost exactly what write_cherry_pick_head did, so we can remove write_cherry_pick_head and just use update_ref.

Signed-off-by: David Turner <dturner@twopensource.com>
---
 sequencer.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index c4f4b7d..554a704 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -158,23 +158,6 @@ static void free_message(struct commit *commit, struct commit_message *msg)
 	unuse_commit_buffer(commit, msg->message);
 }
 
-static void write_cherry_pick_head(struct commit *commit, const char *pseudoref)
-{
-	const char *filename;
-	int fd;
-	struct strbuf buf = STRBUF_INIT;
-
-	strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1));
-
-	filename = git_path("%s", pseudoref);
-	fd = open(filename, O_WRONLY | O_CREAT, 0666);
-	if (fd < 0)
-		die_errno(_("Could not open '%s' for writing"), filename);
-	if (write_in_full(fd, buf.buf, buf.len) != buf.len || close(fd))
-		die_errno(_("Could not write to '%s'"), filename);
-	strbuf_release(&buf);
-}
-
 static void print_advice(int show_hint, struct replay_opts *opts)
 {
 	char *msg = getenv("GIT_CHERRY_PICK_HELP");
@@ -607,9 +590,11 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
 	 * write it at all.
 	 */
 	if (opts->action == REPLAY_PICK && !opts->no_commit && (res == 0 || res == 1))
-		write_cherry_pick_head(commit, "CHERRY_PICK_HEAD");
+		update_ref(NULL, "CHERRY_PICK_HEAD", commit->object.sha1, NULL,
+			   REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
 	if (opts->action == REPLAY_REVERT && ((opts->no_commit && res == 0) || res == 1))
-		write_cherry_pick_head(commit, "REVERT_HEAD");
+		update_ref(NULL, "REVERT_HEAD", commit->object.sha1, NULL,
+			   REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
 
 	if (res) {
 		error(opts->action == REPLAY_REVERT
-- 
2.0.4.315.gad8727a-twtrsrc
Previous: David TurnerNext: Junio C Hamano
Message 10 of 11 in “pseudorefs”
  1. 0/5 pseudorefsDavid Turner, Jul 27, 2015
  2. 1/5 refs: Introduce pseudoref and per-worktree ref conceptsDavid Turner, Jul 27, 2015
  3. Eric SunshineJul 28, 2015
  4. 2/5 notes: replace pseudorefs with real refsDavid Turner, Jul 27, 2015
  5. 3/5 pseudorefs: create and use pseudoref update and delete functionsDavid Turner, Jul 27, 2015
  6. David TurnerJul 28, 2015
  7. 4/5 rebase: use update_refDavid Turner, Jul 27, 2015
  8. Junio C HamanoJul 28, 2015
  9. David TurnerJul 28, 2015
  10. 5/5 sequencer: replace write_cherry_pick_head with update_refDavid Turner, Jul 27, 2015
  11. Junio C HamanoJul 27, 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.