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

Re: [RFC PATCH] cogito --- don't overwrite metadata files in place (breaks CoW use)

From
Linus Torvalds <torvalds@osdl.org>
Date
Jul 13, 2005, 21:23 UTC
Message-ID
<Pine.LNX.4.58.0507131410430.17536@g5.osdl.org>
In-Reply-To
<20050713185339.GA9260@taniwha.stupidest.org>
On Wed, 13 Jul 2005, Chris Wedgwood wrote:
Show 11 quoted lines
> 
> How about the following?
> 
>     echo_to_file() {
> 	local DEST="$2"
> 	local count=1
> 	local RET
> 
> 	# follow symlinks until we run out or end up with something
> 	# dangling
> 	while [ -L "$DEST" ] ; do

If you really want to do something like this, then you should do it like this:

	update_head() {
		head="$GIT_DIR/HEAD"
		newvalue=$(git-rev-parse --verify "$1"^0) || exit
		if [ -L "$head" ]; then
			head=$(readlink "$head")
			case "$head" in
			refs/heads/*)
				head="$GIT_DIR"/"$head"
				;;
			*)
				exit 1
				;;
			esac
		fi
		echo $newvalue > "$head.lock" && rename "$head.lock" "$head"
	}
which is at least slightly simpler, and might even work thanks to that.
Your was buggy for several reasons:
 - following multiple links is _wrong_, since the next-level link could 
   actually be a symlink to another tree entirely (if somebody is crazy 
   enough to use "cp -Rl" to copy trees, then why not "cp -Rs"?)
   Ergo: you should only follow a symlink if it points to refs/heads, and 
   anything else would be a BUG.
 - you got relative links wrong.

Now, admittedly the above is totally untested too, so I'll probably have typos etc in there. But the basic point stands: don't go for complexity. Go for one _particular_ case.

		Linus
Previous: Chris WedgwoodNext: Chris Wedgwood
Message 14 of 15 in “cogito --- don't overwrite metadata files in place (breaks CoW use)”
  1. cogito --- don't overwrite metadata files in place (breaks CoW use)Chris Wedgwood, Jul 12, 2005
  2. Junio C HamanoJul 12, 2005
  3. Chris WedgwoodJul 13, 2005
  4. Matthias UrlichsJul 13, 2005
  5. Chris WedgwoodJul 13, 2005
  6. Linus TorvaldsJul 13, 2005
  7. Chris WedgwoodJul 13, 2005
  8. Linus TorvaldsJul 13, 2005
  9. Chris WedgwoodJul 13, 2005
  10. Linus TorvaldsJul 13, 2005
  11. Chris WedgwoodJul 13, 2005
  12. Matthias UrlichsJul 13, 2005
  13. Chris WedgwoodJul 13, 2005
  14. Linus TorvaldsJul 13, 2005
  15. Chris WedgwoodJul 13, 2005

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.