From: Carl Baldwin <cnb@fc.hp.com>
To: git@vger.kernel.org
Subject: [RFC] undo and redo
Date: Wed, 24 Aug 2005 11:23:39 -0600 [thread overview]
Message-ID: <20050824172339.GA7083@hpsvcnb.fc.hp.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1408 bytes --]
Hello,
So, one thing that I liked about GNU Arch when I tried it out was the
ability to undo and redo changes in the local working copy. I decided
to try to do this with git. What I have is preliminary. I'm sure it
could use some work.
So, I started with the assumption that all changes in the working copy
have been updated to the cache. My scripts check this (with
git-diff-files) and abort if this is not the case.
Undo calls git-write-tree to write the changes to the object store. It
stores that tree's hash and the current HEAD's tree's hash in a file.
Then it reverts the working copy to HEAD.
Redo grabs these two trees from the file, does git-write-tree to produce
a third tree and merges the three using the old HEAD's tree as the base
of the merge. This way, new commits can happen and the local copy can
be modified since the undo and it should still work assuming no
conflicts emerge.
Attached are the two scripts. Comments and criticism are welcome.
Cheers,
Carl
--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Carl Baldwin Systems VLSI Laboratory
Hewlett Packard Company
MS 88 work: 970 898-1523
3404 E. Harmony Rd. work: Carl.N.Baldwin@hp.com
Fort Collins, CO 80525 home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[-- Attachment #2: git-redo-script --]
[-- Type: text/plain, Size: 675 bytes --]
#!/bin/sh
. git-sh-setup-script || die "Not a git archive"
if [ -n "$(git-diff-files)" ]; then
echo The following files should be updated!
echo
git-diff-files | awk '{print $6}'
fi
undostack=$GIT_DIR/undostack
if [ ! -s $undostack ]; then
echo "No undo information in $undostack"
else
# Read the top of the stack
basetree=$(cat $undostack | tail -n 2 | head -n 1)
redotree=$(cat $undostack | tail -n 1)
# Pop the stack
cat $undostack | head -n -2 > $undostack.tmp
mv $undostack{.tmp,}
currenttree=$(git-write-tree)
git-read-tree -u -m $basetree $currenttree $redotree
git-merge-cache git-merge-one-file-script -a
fi
[-- Attachment #3: git-undo-script --]
[-- Type: text/plain, Size: 611 bytes --]
#!/bin/sh
. git-sh-setup-script || die "Not a git archive"
if [ -n "$(git-diff-files)" ]; then
echo The following files should be updated!
echo
git-diff-files | awk '{print $6}'
fi
undostack=$GIT_DIR/undostack
headtree=$(git-cat-file commit $(cat $GIT_DIR/HEAD) | head -n 1 | sed -e 's/tree //')
undotree=$(git-write-tree)
if [ $headtree == $undotree ]; then
echo There are no changes to undo.
else
{
echo $headtree
echo $undotree
} >> $undostack
echo Saved current state as tree $undotree.
echo Reverting to HEAD, $headtree...
git-checkout-script -f
fi
next reply other threads:[~2005-08-24 17:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-24 17:23 Carl Baldwin [this message]
2005-08-24 18:10 ` [RFC] undo and redo Carl Baldwin
2005-08-24 18:51 ` Linus Torvalds
2005-08-24 19:56 ` Carl Baldwin
2005-08-24 20:44 ` Daniel Barkalow
2005-08-24 20:47 ` Carl Baldwin
2005-08-24 21:04 ` Daniel Barkalow
2005-08-24 22:48 ` Junio C Hamano
2005-08-25 2:41 ` Carl Baldwin
2005-08-25 5:06 ` Junio C Hamano
2005-08-25 16:32 ` Carl Baldwin
2005-08-25 17:39 ` Kalle Valo
2005-08-25 19:59 ` Kirby C. Bohling
2005-08-25 20:19 ` Junio C Hamano
2005-08-25 20:49 ` Kirby C. Bohling
2005-08-25 21:28 ` Carl Baldwin
2005-08-25 20:37 ` Carl Baldwin
2005-08-25 21:09 ` Kirby C. Bohling
2005-08-25 21:42 ` Carl Baldwin
2005-08-24 18:18 ` Junio C Hamano
2005-08-24 20:01 ` Carl Baldwin
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=20050824172339.GA7083@hpsvcnb.fc.hp.com \
--to=cnb@fc.hp.com \
--cc=git@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).