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

Re: [RFC] Teach git-branch howto rename a branch

From
Junio C Hamano <junkio@cox.net>
Date
Nov 25, 2006, 10:35 UTC
Message-ID
<7vd57b3jc2.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<8c5c35580611250116h466e3649p2630ee6641b6e6f4@mail.gmail.com>
"Lars Hjemli" <lh@elementstorage.no> writes:
Show 6 quoted lines
> Is it ok to put
>
> static int log_ref_write(struct ref_lock *lock,
> 	const unsigned char *sha1, const char *msg)
>
> into refs.h?

I think a cleaner implementation that does not have such a layering violation would involve defining rename_refs() interface in refs.c, next to the delete_ref() that exists there.

The division of labor would be for builtin-branch.c to make sure both oldname and newname are branch names, and rename_refs() to rename the reflog (if exists) and the ref at the same time. To deal with D/F conflicts sanely, I suspect it would involve a call to rename(2) to move the reflog to a temporary location, perhaps $GIT_DIR/.tmp-renamed-log, deletion of the old ref by calling delete_ref(), and then another rename(2) to move that temporary one to its final location, followed by the usual "ref creation dance" of calling lock_any_ref_for_update() and write_ref_sha1().

Side note:

If we do not mind losing the reflog of oldname, then "delete and then create" would be sufficient, but that is not the case.

Unlike "git does not track individual files so we do not record renames" mantra, branches, and more in general, refs, have meaningful identity (at least locally), and unlike the file contents, the "contents" of a ref does not migrate _partially_ from ref to ref. It would make sense to keep track of renames for them.

Previous: Lars HjemliNext: Lars Hjemli
Message 7 of 13 in “[RFC] Teach git-branch howto rename a branch”
  1. Lars HjemliNov 24, 2006
  2. Junio C HamanoNov 25, 2006
  3. Shawn PearceNov 25, 2006
  4. Jakub NarebskiNov 25, 2006
  5. Shawn PearceNov 25, 2006
  6. Lars HjemliNov 25, 2006
  7. Junio C HamanoNov 25, 2006
  8. Lars HjemliNov 25, 2006
  9. git-branch -D: make it work even when on a yet-to-be-born branchJunio C Hamano, Nov 25, 2006
  10. Lars HjemliNov 25, 2006
  11. Fredrik KuivinenNov 25, 2006
  12. Lars HjemliNov 25, 2006
  13. Josef WeidendorferNov 26, 2006

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.