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

Re: [ANNOUNCE] chronoversion: chronological archiving script with temporary commits

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 13, 2007, 15:49 UTC
Message-ID
<Pine.LNX.4.63.0703131648440.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<20070313154511.GA18890@spearce.org>
Hi,
On Tue, 13 Mar 2007, Shawn O. Pearce wrote:
Show 22 quoted lines
> 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`
	new=`git write-tree`
Show 11 quoted lines
> 	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.

Ciao, Dscho

Previous: Shawn O. PearceNext: Johannes Schindelin
Message 4 of 5 in “[ANNOUNCE] chronoversion: chronological archiving script with temporary commits”
  1. David TweedMar 13, 2007
  2. Jakub NarebskiMar 13, 2007
  3. Shawn O. PearceMar 13, 2007
  4. Johannes SchindelinMar 13, 2007
  5. Johannes SchindelinMar 13, 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.