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

Re: [PATCH 4/4] create_symref: use existing ref-lock code

From
Jeff King <peff@peff.net>
Date
Dec 22, 2015, 00:58 UTC
Message-ID
<20151222005824.GB6901@sigill.intra.peff.net>
In-Reply-To
<xmqq8u4nfrvv.fsf@gitster.mtv.corp.google.com>
On Mon, Dec 21, 2015 at 12:50:28PM -0800, Junio C Hamano wrote:
Show 21 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> >  #ifndef NO_SYMLINK_HEAD
> > -	if (prefer_symlink_refs) {
> > -		unlink(ref_path);
> > -		if (!symlink(target, ref_path))
> > -			goto done;
> 
> I see that the original was sloppy (most certainly my bad) ...
> 
> > +	char *ref_path = get_locked_file_path(lock->lk);
> > +	unlink(ref_path);
> 
> ... and you inherited that.  I see a few seemingly related helpers
> in wrapper.c, but none looks useful in this context X-<.
> 
>     if (unlink_or_warn(ref_path))
>     	return -1;
> 
> is close enough, but it still lets the caller fallback to textual
> symref.

I don't think the original is _wrong_; it's meant to be "unlink if needed", and the symlink call is what we really care about (if our unlink failed for anything but ENOENT, the symlink will, too). But I agree unlink_or_warn should do that and give us a nice warning (and cover up ENOENT). To fall through, I think we just want (in the original):

  if (!unlink_or_warn(ref_path) && !symlink(target, ref_path))
	goto done;
and in mine that becomes:
  int ret = -1;
  ...
  if (!unlink_or_warn(ref_path) && !symlink(target, ref_path))
	ret = 0;

I must confess I considered a follow-on patch to drop the prefer_symlink_refs code path completely. I'm surprised it all still works with packed-refs, etc, but resolve_ref does take special care to use readlink().

-Peff
Previous: Junio C HamanoNext: Michael Haggerty
Message 9 of 25 in “improve symbolic-ref robustness”
  1. 0/4 improve symbolic-ref robustnessJeff King, Dec 20, 2015
  2. 1/4 symbolic-ref: propagate error code from create_symref()Jeff King, Dec 20, 2015
  3. 2/4 t1401: test reflog creation for git-symbolic-refJeff King, Dec 20, 2015
  4. 3/4 create_symref: modernize variable namesJeff King, Dec 20, 2015
  5. Michael HaggertyDec 28, 2015
  6. Jeff KingDec 29, 2015
  7. 4/4 create_symref: use existing ref-lock codeJeff King, Dec 20, 2015
  8. Junio C HamanoDec 21, 2015
  9. Jeff KingDec 22, 2015
  10. Michael HaggertyDec 28, 2015
  11. Jeff KingDec 29, 2015
  12. Jeff KingDec 29, 2015
  13. 0/3 improve symbolic-ref robustnessJeff King, Dec 29, 2015
  14. 1/3 create_symref: modernize variable namesJeff King, Dec 29, 2015
  15. 2/3 create_symref: use existing ref-lock codeJeff King, Dec 29, 2015
  16. 3/3 create_symref: write reflog while holding lockJeff King, Dec 29, 2015
  17. 4/3 create_symref: drop support for writing symbolic linksJeff King, Dec 29, 2015
  18. Jeff KingDec 29, 2015
  19. Junio C HamanoDec 29, 2015
  20. Jeff KingDec 30, 2015
  21. Jeff KingDec 30, 2015
  22. Michael HaggertyDec 29, 2015
  23. Junio C HamanoDec 29, 2015
  24. Junio C HamanoDec 29, 2015
  25. Jeff KingDec 30, 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.