All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: David Tweed <david.tweed@gmail.com>
Cc: git@vger.kernel.org, jonsmirl@gmail.com
Subject: Re: [ANNOUNCE] chronoversion: chronological archiving script with temporary commits
Date: Tue, 13 Mar 2007 11:45:11 -0400	[thread overview]
Message-ID: <20070313154511.GA18890@spearce.org> (raw)
In-Reply-To: <e1dab3980703130526t4b573f18h793a065d54c9369@mail.gmail.com>

David Tweed <david.tweed@gmail.com> wrote:
> A question for those who understand things: I stash the last written
> _tree_'s hash in a tag and then when a new "commit's" directory tree
> is written starts look to see if it's the same SHA value. If it is I
> know I can avoid the commit. At the moment I'm using
> 
>    if os.path.exists(lastTreeFile) and
> tree==open(lastTreeFile,"r").read()[:40]:
> 
> to be safe just in case a user, eg, goes mad and manually deletes that
> record. Clearly this is going to hit trouble if git ever decides to
> put this tag into a packed refs file.
> Is there any neat way of using builtin stuff like git-rev-parse to ask
> if a ref has a given SHA1 value and return an easily parsed yes/no
> answer?

The common idiom if you want to compare trees to see if you
need to make a commit is:

	oldc=`git rev-parse $tagname^{commit}`
	oldt=`git rev-parse $oldc^{tree}`
	newt`git write-tree`
	if [ X$oldt = X$newt ]; then
		: nothing to save
	else
		newc=`git commit-tree $newt -p $oldc`
		git update-ref $tagname $newc $oldc
	fi

Yes, a little ugly.  But its safe; if another program were to
alter the value of $tagname (e.g. "git branch -f", "git tag -f")
while your script is running the update-ref in the else will fail,
letting you know that $tagname changed in the process.

-- 
Shawn.

  parent reply	other threads:[~2007-03-13 15:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-13 12:26 [ANNOUNCE] chronoversion: chronological archiving script with temporary commits David Tweed
2007-03-13 15:42 ` Jakub Narebski
2007-03-13 15:45 ` Shawn O. Pearce [this message]
2007-03-13 15:49   ` Johannes Schindelin
2007-03-13 15:54     ` Johannes Schindelin

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=20070313154511.GA18890@spearce.org \
    --to=spearce@spearce.org \
    --cc=david.tweed@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jonsmirl@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.