Git development
 help / color / mirror / Atom feed
From: Chris Wedgwood <cw@f00f.org>
To: Matthias Urlichs <smurf@smurf.noris.de>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH] cogito --- don't overwrite metadata files in place (breaks CoW use)
Date: Wed, 13 Jul 2005 11:53:39 -0700	[thread overview]
Message-ID: <20050713185339.GA9260@taniwha.stupidest.org> (raw)
In-Reply-To: <pan.2005.07.13.07.03.26.398212@smurf.noris.de>

On Wed, Jul 13, 2005 at 09:03:26AM +0200, Matthias Urlichs wrote:

> You are ;-) the tree itsels is no symlinked, but HEAD points to
> refs/heads/<branch> by default.

Thanks for pointing that out.  I honestly never noticed that.

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
	    local NLINK=`readlink "$DEST"`

	    if [ ! -e "$NLINK" ] ; then
		# dangling link, just poke as-is
		echo "$1" > "$DEST"
		return $?
	    fi

	    # follow link
	    if [ -L "$NLINK" ] ; then
		count=$(("$count" + 1))
		if [ "$count" -gt 5 ] ; then
		    echo "Too many symlinks when resolving $2" 1>&2
		    return 1
		fi
		DEST="$NLINK"
	    fi
	done

	# end up with a regular file
	local TMPFILE=`mktemp "$DEST.tmp-XXXXXXX"`
	echo "$1" > "$TMPFILE"
	RET="$?"
	mv -f "$TMPFILE" "$DEST"
	return "$RET"
    }


Obvious changes from last time are:

  - mark things local

  - follow links, bailing out if it takes too long

  - if the link is dangling, just use as-is

  - when doing the 'replace' at the end use -f because it's quite
    possible someone will have done cp -Rl ~otheruser/tree here and mv
    *might* bitch if the UID is different?

  - return (some) errors (just because, it's not like cogito checks
    for these)

  reply	other threads:[~2005-07-13 18:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-12 19:05 [RFC PATCH] cogito --- don't overwrite metadata files in place (breaks CoW use) Chris Wedgwood
2005-07-12 21:37 ` Junio C Hamano
2005-07-13  4:53   ` Chris Wedgwood
2005-07-13  7:03     ` Matthias Urlichs
2005-07-13 18:53       ` Chris Wedgwood [this message]
2005-07-13 20:05         ` Linus Torvalds
2005-07-13 20:44           ` Chris Wedgwood
2005-07-13 21:05             ` Linus Torvalds
2005-07-13 21:11               ` Chris Wedgwood
2005-07-13 21:33                 ` Linus Torvalds
2005-07-13 21:50                   ` Chris Wedgwood
2005-07-13 20:07         ` Matthias Urlichs
2005-07-13 20:36           ` Chris Wedgwood
2005-07-13 21:23         ` Linus Torvalds
2005-07-13 21:54           ` Chris Wedgwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050713185339.GA9260@taniwha.stupidest.org \
    --to=cw@f00f.org \
    --cc=git@vger.kernel.org \
    --cc=smurf@smurf.noris.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox