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

Re: [PATCH v6 2/7] cherry-pick: treat CHERRY_PICK_HEAD and REVERT_HEAD as refs

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jul 6, 2015, 16:00 UTC
Message-ID
<559AA61E.1010308@alum.mit.edu>
In-Reply-To
<1435609076-8592-3-git-send-email-dturner@twopensource.com>
On 06/29/2015 10:17 PM, David Turner wrote:
Show 54 quoted lines
> Instead of directly writing to and reading from files in
> $GIT_DIR, use ref API to interact with CHERRY_PICK_HEAD
> and REVERT_HEAD.
> 
> Signed-off-by: David Turner <dturner@twopensource.com>
> ---
>  branch.c                         |  4 ++--
>  builtin/commit.c                 |  6 +++---
>  builtin/merge.c                  |  2 +-
>  contrib/completion/git-prompt.sh |  4 ++--
>  git-gui/lib/commit.tcl           |  2 +-
>  sequencer.c                      | 39 ++++++++++++++++++++-------------------
>  t/t7509-commit.sh                |  4 ++--
>  wt-status.c                      |  6 ++----
>  8 files changed, 33 insertions(+), 34 deletions(-)
> 
> [...]
> diff --git a/sequencer.c b/sequencer.c
> index f8421a8..44c43e5 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -158,21 +158,22 @@ 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)
> +static void write_cherry_pick_head(struct commit *commit, const char *ref)
>  {
> -	const char *filename;
> -	int fd;
> -	struct strbuf buf = STRBUF_INIT;
> +	struct strbuf err = STRBUF_INIT;
> +	void *transaction;
>  
> -	strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1));
> +	transaction = ref_transaction_begin(&err);
> +	if (!transaction)
> +		die(_("Could not create transaction: %s"), err.buf);
>  
> -	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);
> +	if (ref_transaction_update(transaction, ref, commit->object.sha1,
> +				   NULL, REF_NODEREF, NULL,
> +				   &err))
> +		die(_("Could not write ref %s: %s"), ref, err.buf);
> +
> +	if (ref_transaction_commit(transaction, &err))
> +		die(_("Could not commit ref write %s: %s"), ref, err.buf);
>  }

I didn't check all the details, but this code looks a lot like what update_ref() does. Maybe you can use that function?

>  static void print_advice(int show_hint, struct replay_opts *opts)
> @@ -186,7 +187,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
> [...]
Otherwise, looks good to me.
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
Previous: David TurnerNext: David Turner
Message 9 of 31 in “refs backend preamble”
  1. 0/7 refs backend preambleDavid Turner, Jun 29, 2015
  2. 1/7 refs.c: add err arguments to reflog functionsDavid Turner, Jun 29, 2015
  3. Michael HaggertyJul 6, 2015
  4. David TurnerJul 7, 2015
  5. Michael HaggertyJul 8, 2015
  6. Junio C HamanoJul 8, 2015
  7. Michael HaggertyJul 9, 2015
  8. 2/7 cherry-pick: treat CHERRY_PICK_HEAD and REVERT_HEAD as refsDavid Turner, Jun 29, 2015
  9. Michael HaggertyJul 6, 2015
  10. 3/7 bisect: treat BISECT_HEAD as a refDavid Turner, Jun 29, 2015
  11. 4/7 refs: Break out check for reflog autocreationDavid Turner, Jun 29, 2015
  12. 5/7 refs: new public ref function: safe_create_reflogDavid Turner, Jun 29, 2015
  13. Michael HaggertyJul 6, 2015
  14. David TurnerJul 7, 2015
  15. Michael HaggertyJul 8, 2015
  16. 6/7 git-reflog: add create and exists functionsDavid Turner, Jun 29, 2015
  17. Eric SunshineJun 30, 2015
  18. David TurnerJun 30, 2015
  19. Junio C HamanoJun 30, 2015
  20. Eric SunshineJun 30, 2015
  21. Junio C HamanoJun 30, 2015
  22. David TurnerJun 30, 2015
  23. Junio C HamanoJun 30, 2015
  24. Michael HaggertyJul 6, 2015
  25. David TurnerJul 8, 2015
  26. Michael HaggertyJul 8, 2015
  27. David TurnerJul 8, 2015
  28. 7/7 git-stash: use git-reflog instead of creating filesDavid Turner, Jun 29, 2015
  29. Junio C HamanoJun 29, 2015
  30. Junio C HamanoJun 29, 2015
  31. David TurnerJun 29, 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.