threads / discuss / 140

[script] ge: export commits as patches

Subject: [script] ge: export commits as patches

## tl;dr

8 messages between Apr 19, 2005 and Apr 20, 2005.

replies: 7people: 5as markdown or json

Ingo Molnar· Apr 19, 2005, 13:48 UTC · lore

is there any 'export commit as patch' support in git-pasky? I didnt find any such command (maybe it got added meanwhile), so i'm using the 'ge' hack below.

e.g. i typically look at commits via 'git log', and then when i see something interesting, i look at the commit via the 'ge' script. E.g. "ge 834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree will output a particular commit's header and the patch.

	Ingo
#!/bin/bash
if [ $# != 1 ]; then
 echo 'ge <commit-ID>'
 exit -1
fi
TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2)
if [ "$TREE1" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
PARENT=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^parent | cut -d' ' -f2)
if [ "$PARENT" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
TREE2=$(cat-file commit 2>/dev/null $PARENT | head -4 | grep ^tree | cut -d' ' -f2)
if [ "$TREE2" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi

cat-file commit $1 echo git diff -r $TREE2:$TREE1

Petr Baudis· Apr 19, 2005, 17:03 UTC · re: Ingo Molnar · lore

Re: [script] ge: export commits as patches

Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter where Ingo Molnar <mingo@elte.hu> told me that...

Show 8 quoted lines
> is there any 'export commit as patch' support in git-pasky? I didnt find 
> any such command (maybe it got added meanwhile), so i'm using the 'ge' 
> hack below.
> 
> e.g. i typically look at commits via 'git log', and then when i see 
> something interesting, i look at the commit via the 'ge' script. E.g.  
> "ge 834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree 
> will output a particular commit's header and the patch.
Nice idea. I will add it, probably as 'git patch'.
Show 6 quoted lines
> TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2)
> if [ "$TREE1" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
> PARENT=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^parent | cut -d' ' -f2)
> if [ "$PARENT" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
> TREE2=$(cat-file commit 2>/dev/null $PARENT | head -4 | grep ^tree | cut -d' ' -f2)
> if [ "$TREE2" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
commit-id and parent-id tools might be useful. ;-)
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Ingo Molnar· Apr 19, 2005, 18:56 UTC · re: Petr Baudis · lore

Re: [script] ge: export commits as patches

* Petr Baudis <pasky@ucw.cz> wrote:
Show 21 quoted lines
> Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter
> where Ingo Molnar <mingo@elte.hu> told me that...
> > is there any 'export commit as patch' support in git-pasky? I didnt find 
> > any such command (maybe it got added meanwhile), so i'm using the 'ge' 
> > hack below.
> > 
> > e.g. i typically look at commits via 'git log', and then when i see 
> > something interesting, i look at the commit via the 'ge' script. E.g.  
> > "ge 834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree 
> > will output a particular commit's header and the patch.
> 
> Nice idea. I will add it, probably as 'git patch'.
> 
> > TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2)
> > if [ "$TREE1" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
> > PARENT=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^parent | cut -d' ' -f2)
> > if [ "$PARENT" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
> > TREE2=$(cat-file commit 2>/dev/null $PARENT | head -4 | grep ^tree | cut -d' ' -f2)
> > if [ "$TREE2" = "" ]; then echo 'ge <commit-ID>'; exit -1; fi
> 
> commit-id and parent-id tools might be useful. ;-)
find a cleaned up 'ge' script below.

and please fix gitXnormid.sh to simply echo nothing and return with a -1 exit value when a nonsensical ID is passed to it. Right now the output is quite ugly if you do 'ge blah'.

	Ingo
#!/bin/bash
usage ()
{
 echo 'usage: ge <commit-ID>'
 exit -1
}
if [ $# != 1 ]; then
 usage
fi

ME= $(commit-id $1); [ "$ME" = "" ] && usage PARENT=$(parent-id $ME); [ "$PARENT" = "" ] && usage TREE1= $(tree-id $ME); [ "$TREE1" = "" ] && usage TREE2= $(tree-id $PARENT); [ "$TREE2" = "" ] && usage

cat-file commit $ME echo git diff -r $TREE2:$TREE1

Petr Baudis· Apr 19, 2005, 19:41 UTC · re: Ingo Molnar · lore

Re: [script] ge: export commits as patches

Dear diary, on Tue, Apr 19, 2005 at 08:56:07PM CEST, I got a letter where Ingo Molnar <mingo@elte.hu> told me that...

> and please fix gitXnormid.sh to simply echo nothing and return with a -1 
> exit value when a nonsensical ID is passed to it. Right now the output 
> is quite ugly if you do 'ge blah'.

That's a feature; you can do || exit 1. Put its stderr to /dev/null if you want your own error reporting.

BTW, I still think my gitpatch.sh is nicer. ;-)
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
David A. Wheeler· Apr 20, 2005, 02:34 UTC · re: Petr Baudis · lore

Re: [script] ge: export commits as patches

Forget my earlier "aspatch" proposal, that's a lousy name.

How about "mkpatch"? Seems like a reasonable name for a command that makes a patch. GNU Arch uses that command name. CVS & Subversion basically do this as part of "diff" (which is another possibility).

--- David A. Wheeler
Greg KH· Apr 19, 2005, 19:11 UTC · re: Petr Baudis · lore

Re: [script] ge: export commits as patches

On Tue, Apr 19, 2005 at 07:03:20PM +0200, Petr Baudis wrote:
Show 12 quoted lines
> Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter
> where Ingo Molnar <mingo@elte.hu> told me that...
> > is there any 'export commit as patch' support in git-pasky? I didnt find 
> > any such command (maybe it got added meanwhile), so i'm using the 'ge' 
> > hack below.
> > 
> > e.g. i typically look at commits via 'git log', and then when i see 
> > something interesting, i look at the commit via the 'ge' script. E.g.  
> > "ge 834f6209b22af2941a8640f1e32b0f123c833061" done in the kernel tree 
> > will output a particular commit's header and the patch.
> 
> Nice idea. I will add it, probably as 'git patch'.

Ah, thanks for doing this. 'git patch' works great (but you might want to mention in the 'help' that you can give the commit id for the patch, if you don't want to see the HEAD patch.)

thanks,
greg k-h
David A. Wheeler· Apr 19, 2005, 22:56 UTC · re: Petr Baudis · lore

Re: [script] ge: export commits as patches

Petr Baudis wrote:
Show 12 quoted lines
>Dear diary, on Tue, Apr 19, 2005 at 03:48:43PM CEST, I got a letter
>where Ingo Molnar <mingo@elte.hu> told me that...
>  
>
>>is there any 'export commit as patch' support in git-pasky?
>>    
>>
>
>Nice idea. I will add it, probably as 'git patch'.
>
>  
>
Eek!

It's a nice idea, and it'd be great as a subcommand. But PLEASE don't name it "patch". I already know what "patch" does, "patch" ACCEPTS a patch... it doesn't create one ;-).

How about naming it "aspatch" or "asdiff" instead? Or something else (good names, anyone?).

<soapbox_to_choir>Good externally-viewed names are critical... good command names that are similar to what people "already know" can really help make the tool a joy to use.</soapbox_to_choir>

--- David A. Wheeler
Zlatko Calusic· Apr 20, 2005, 17:21 UTC · re: Ingo Molnar · lore

Re: [script] ge: export commits as patches

Ingo Molnar <mingo@elte.hu> writes:
> TREE1=$(cat-file commit 2>/dev/null $1 | head -4 | grep ^tree | cut -d' ' -f2)
                                         --------------------------------------

And to make it easier on your eyes, you can always rewrite stuff like that (mentioned everywhere these days :)) like:

TREE1=$(cat-file commit 2>/dev/null $1 | awk '/^tree/ {print $2}'
                                         ------------------------

No, I'm definitely not trying to save some CPU cycles, CPU cycles are cheap, eyes are expensive! :)

-- 
Zlatko

← back to recent threads