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.