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

Re: [PATCH 3/3] Teach "git branch" about --new-workdir

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 23, 2007, 05:14 UTC
Message-ID
<20070723051437.GE32566@spearce.org>
In-Reply-To
<7v1wezohi4.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > I live by new-workdir.  I do everything with it.  And today I just
> > spent over an hour sorting out cases where my many, many workdirs
> > have different refs than their base repositories, because their
> > packed-refs files are different.  Grrrrrrrrrrrrrrrrrr.
> >
> > So we really need to make anyone that edits packed-refs (and
> > maybe also config) resolve the symlink and do the edit in the
> > target directory.  Then we can consider adding this workdir thing
> > to core git.
> 
> This is actually not limited to packed-refs file, but applies to
> other things as well.
Yes, but most other things aren't symlinks, they are in symlinked
directories.  But better to cover it in a single location and have
it Just Work(tm) then to special case things.
 
Show 22 quoted lines
> diff --git a/lockfile.c b/lockfile.c
> index fb8f13b..7fc71d9 100644
> --- a/lockfile.c
> +++ b/lockfile.c
> @@ -28,6 +28,17 @@ static void remove_lock_file_on_signal(int signo)
>  static int lock_file(struct lock_file *lk, const char *path)
>  {
>  	int fd;
> +	struct stat st;
> +
> +	if ((!lstat(path, &st)) && S_ISLNK(st.st_mode)) {
> +		ssize_t sz;
> +		static char target[PATH_MAX];
> +		sz = readlink(path, target, sizeof(target));
> +		if (sz < 0)
> +			warning("Cannot readlink %s", path);
> +		else
> +			path = target;
> +	}
>  	sprintf(lk->filename, "%s.lock", path);
>  	fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
>  	if (0 <= fd) {

Right. But don't you have to resolve target relative to path? If the symlink is an absolute path its fine as-is, but if it was relative its relative to path, not pwd.

-- 
Shawn.
Previous: Junio C HamanoNext: Shawn O. Pearce
Message 14 of 46 in “Teach "git branch" about --new-workdir”
  1. 3/3 Teach "git branch" about --new-workdirJohannes Schindelin, Jul 22, 2007
  2. Daniel BarkalowJul 22, 2007
  3. Johannes SchindelinJul 22, 2007
  4. Julian PhillipsJul 22, 2007
  5. Johannes SchindelinJul 22, 2007
  6. Julian PhillipsJul 22, 2007
  7. Johannes SchindelinJul 22, 2007
  8. Julian PhillipsJul 22, 2007
  9. Jakub NarebskiJul 22, 2007
  10. Johannes SchindelinJul 22, 2007
  11. Johannes SchindelinJul 22, 2007
  12. Shawn O. PearceJul 23, 2007
  13. Junio C HamanoJul 23, 2007
  14. Shawn O. PearceJul 23, 2007
  15. Shawn O. PearceJul 23, 2007
  16. Johannes SchindelinJul 23, 2007
  17. Johannes SchindelinJul 23, 2007
  18. Marius Storm-OlsenJul 24, 2007
  19. Johannes SchindelinJul 24, 2007
  20. Junio C HamanoJul 24, 2007
  21. Johannes SchindelinJul 24, 2007
  22. Marius Storm-OlsenJul 24, 2007
  23. Julian PhillipsJul 24, 2007
  24. Marius Storm-OlsenJul 24, 2007
  25. Johannes SchindelinJul 24, 2007
  26. Josef WeidendorferJul 24, 2007
  27. Johannes SchindelinJul 24, 2007
  28. Josef WeidendorferJul 24, 2007
  29. Jakub NarebskiJul 25, 2007
  30. Johannes SchindelinJul 24, 2007
  31. Marius Storm-OlsenJul 24, 2007
  32. Marius Storm-OlsenJul 24, 2007
  33. Johannes SchindelinJul 24, 2007
  34. Marius Storm-OlsenJul 24, 2007
  35. Johannes SchindelinJul 24, 2007
  36. Marius Storm-OlsenJul 24, 2007
  37. Alex RiesenJul 24, 2007
  38. Marius Storm-OlsenJul 25, 2007
  39. Johannes SchindelinJul 25, 2007
  40. Steven GrimmJul 25, 2007
  41. Andy ParkinsJul 25, 2007
  42. Marius Storm-OlsenJul 25, 2007
  43. Johannes SchindelinJul 25, 2007
  44. Linus TorvaldsJul 25, 2007
  45. Christian MICHONJul 26, 2007
  46. Julian PhillipsJul 23, 2007

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.