Git development
 help / color / mirror / Atom feed
* [ANNOUNCE] git-pasky-0.5
From: Petr Baudis @ 2005-04-18 22:25 UTC (permalink / raw)
  To: git

  Hello,

  so here finally goes git-pasky-0.5, my set of scripts upon Linus
Torvald's git, which aims to provide a humanly usable interface, to a
degree similar to a SCM tool. You can get it at

	http://pasky.or.cz/~pasky/dev/git/

  See the READMEs etc for some introduction.

  This contains plenty of changes, it's difficult to sum it up. It has
been reworked to better support the concept of branches; you can create
local branches which share the GIT object repository by git fork. There
is also git init which will yet you start a new GIT object repository
(possibly seeding it from some rsync URL), git status, better git log,
much cleaner concept of tracking (and consequently simpler yet better
git pull). Of course it contains the latest updates from Linus' branch
too.

  There is also git merge, which does some merging, but note well that
it is vastly inferior to what we _can_ do (and what I will do now).
Expect 0.6 soon where git merge will actually make use of the merging
facilities. I released 0.5 basically only because I have been postponing
it so long that I really feel ashamed of myself. ;-)

  Have fun,

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

^ permalink raw reply

* Re: Add + Status patches
From: Junio C Hamano @ 2005-04-18 22:25 UTC (permalink / raw)
  To: David Greaves; +Cc: Petr Baudis, git
In-Reply-To: <42643224.60407@dgreaves.com>

>>>>> "DG" == David Greaves <david@dgreaves.com> writes:

DG> ... neither
DG> git add .
DG> nor
DG> git add -r .
DG> worked.

These would be much much much nicer than pipe the list of
filenames from stdin which reminds me of cpio ;-).


^ permalink raw reply

* Re: Add + Status patches
From: David Greaves @ 2005-04-18 22:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Petr Baudis, git
In-Reply-To: <7v64yju7er.fsf@assigned-by-dhcp.cox.net>

Junio C Hamano wrote:

>DG> It allows:
>DG>  find src -type f | git add -
>
>I am slow today, but have you considered using xargs?
>
>  
>
yep thanks :)
I know you _could_ do it with xargs - but you _could_ use the raw git 
commands too. This is a "be nice to the user" layer and I was 
'surprised' that neither
git add .
nor
git add -r .
worked.

That meant that I had to fix it so I started with the ability to handle 
a list and, since I got a friendly response, I can hopefully move on to 
help make git nicer to use for mere mortals.

David

^ permalink raw reply

* [PATCH 1/1] add, rm + status patches
From: David Greaves @ 2005-04-18 22:18 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git
In-Reply-To: <20050418204814.GF5554@pasky.ji.cz>

Petr Baudis wrote:

>  Thanks. Could you please send the patches signed off and either with
>  content-disposition: inline or in the mail body?
Is this OK.
Thunderbird isn't the best for attaching patches.
>
>  I think it would be cleaner to do the testing for the dash in the for
>  loop, so that I can do git add foo bar -. Also, don't forget to
>  update git add's documentation at the top. For the usage string, I'd
>  probably prefer (-|FILE)...
>
>  thanks,

Here you are:
* git add and git rm now take (-|FILE)...
* noted some bugs to be fixed
* introduced de-dupe code into add and rm
* git status reports added/removed files (although there are extra entries)
* README, git and command docs updated

I realise as I write this that I should have split these patches up - I 
will do so next time.

Has a decision been reached to _not_ code the cogito part of the git 
suite in perl?

I ask because the code in git status is getting pretty ugly.
I'd be happy to help with a preliminary port to perl.

David

Signed-off-by: David Greaves <david@dgreaves.com>
---
Index: README
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/README (mode:100644 
sha1:798476ad292cc6edf5a2f5782e1de82f6052abe2)
+++ cd5cd7a9272ce1966aca3bfce15f703e33cafc04/README (mode:100644 
sha1:4282af1604e429dd767fe721751b5ac4a87c410e)
@@ -89,6 +89,10 @@
Of course you will want to commit. If you added any new files, do

git add newfile1 newfile2 ...
+
+or even
+
+ find src -type f | git add -

first. Then feel free to commit by

Index: git
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/git (mode:100755 
sha1:b648169640025bd68d1b27a0fcc85b65d85e4440)
+++ cd5cd7a9272ce1966aca3bfce15f703e33cafc04/git (mode:100755 
sha1:2549bc3dc36ec00e747e91edb6e839be0f37ae4a)
@@ -25,7 +25,7 @@
Usage: git COMMAND [ARG]...

Available commands:
- add FILE...
+ add (-|FILE)...
addremote RNAME RSYNC_URL
apply < patch on stdin
cancel
@@ -41,7 +41,7 @@
lsremote
merge -b BASE_ID FROM_ID
pull [RNAME]
- rm FILE...
+ rm (-|FILE)...
seek [COMMIT_ID]
status
tag TNAME [COMMIT_ID]
Index: gitadd.sh
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/gitadd.sh (mode:100755 
sha1:3ed93ea0fcb995673ba9ee1982e0e7abdbe35982)
+++ cd5cd7a9272ce1966aca3bfce15f703e33cafc04/gitadd.sh (mode:100755 
sha1:a3e83ac52abd5a9cdc6abd560f95b2f19646fd99)
@@ -5,14 +5,26 @@
#
# Takes a list of file names at the command line, and schedules them
# for addition to the GIT repository at the next commit.
+# If one of the filenames is '-' then also read a filelist from STDIN
#
# FIXME: Those files are omitted from show-diff output!
+# FIXME: No checking against git-ignore
+# FIXME: No checking against .git/del-queue
+

if [ ! "$1" ]; then
- echo "gitadd.sh: usage: git add FILE..." >&2
+ echo "gitadd.sh: usage: git add (-|FILE)..." >&2
exit 1;
fi

for file in "$@"; do
- echo $file >>.git/add-queue
+ if [ $file = "-" -a ! "$DONE_STDIN" ]; then
+ cat >> .git/add-queue
+ DONE_STDIN=1
+ else
+ echo $file >>.git/add-queue
+ fi
done
+
+# Remove duplicates
+sort < .git/add-queue | uniq > .git/add-queue
\ No newline at end of file
Index: gitrm.sh
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/gitrm.sh (mode:100755 
sha1:5c18c38a890c9fd9ad2b866ee7b529539d2f3f8f)
+++ cd5cd7a9272ce1966aca3bfce15f703e33cafc04/gitrm.sh (mode:100755 
sha1:d76542dd6ad892fbbdc93e475aa9b77dd2922fe5)
@@ -5,15 +5,28 @@
#
# Takes a list of file names at the command line, and schedules them
# for addition to the GIT repository at the next commit.
+# If one of the filenames is '-' then also read a filelist from STDIN
#
# FIXME: Those files are omitted from show-diff output!
+# FIXME: No checking against git-ignore
+# FIXME: No checking against .git/add-queue
+# FIXME: Files read in on stdin aren't validated to exist
+

if [ ! "$1" ]; then
- echo "gitrm.sh: usage: git rm FILE..." >&2
+ echo "gitrm.sh: usage: git rm (-|FILE)..." >&2
exit 1;
fi

for file in "$@"; do
- [ -e "$file" ] && rm "$file"
- echo $file >>.git/rm-queue
+ if [ $file = "-" -a ! "$DONE_STDIN" ]; then
+ cat >> .git/rm-queue
+ DONE_STDIN=1
+ else
+ [ -e "$file" ] && rm "$file"
+ echo $file >>.git/rm-queue
+ fi
done
+
+# Remove duplicates
+sort < .git/rm-queue | uniq > .git/rm-queue
\ No newline at end of file
Index: gitstatus.sh
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/gitstatus.sh (mode:100755 
sha1:6c33f805ebc2630b14a88a07dfc891a9196d66a5)
+++ cd5cd7a9272ce1966aca3bfce15f703e33cafc04/gitstatus.sh (mode:100755 
sha1:2611d00189e5d03ba8356ec0e4c3af107bae6981)
@@ -3,10 +3,12 @@
# Show status of entries in your working tree.
# Copyright (c) Petr Baudis, 2005

+# FIXME: newly added files show up twice as ? _AND_ A
+
{
show-files -z -t --others --deleted --unmerged
- [ -s .git/add-queue ] && cat .git/add-queue | sed 's/^/A /' | { read 
x; echo -ne $x'\0'; }
- [ -s .git/rm-queue ] && cat .git/rm-queue | sed 's/^/D /' | { read x; 
echo -ne $x'\0'; }
+ [ -s .git/add-queue ] && cat .git/add-queue | sed 's/^/A /' | tr '\n' '\0'
+ [ -s .git/rm-queue ] && cat .git/rm-queue | sed 's/^/D /' | tr '\n' '\0'
} | sort -z -k 2 | xargs -0 sh -c '
while [ "$1" ]; do
tag=$(echo "$1" | cut -d " " -f 1);


^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Russell King @ 2005-04-18 22:16 UTC (permalink / raw)
  To: Linus Torvalds, Petr Baudis; +Cc: Git Mailing List, Peter Anvin
In-Reply-To: <20050417195742.D13233@flint.arm.linux.org.uk>

Ok, since the last one was soo successful, and I'm up for more
punishment, here's another attempt.  The diffstat is rather
interesting in this one, claiming no changes.  It should look
like this:

 arch/arm/lib/bitops.h |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+)

However, it seems that git diff can't handle new files appearing
yet.

The other interesting thing to note is that patches are generated
for '-p0' rather than '-p1' application, which is contary to our
historical requirements.  This is going to confuse people - can
we make it generate -p1 patches please?

Linus - assuming I un-messed-up my tree properly (it appears to
be correct and fsck-cache $(commit-id) is happy) please merge
this.  Thanks.

Linus,

Please incorporate the latest ARM changes, which can
be found at:

	master.kernel.org:/home/rmk/linux-2.6-rmk.git

This will update the following files:

 0 files changed

through these ChangeSets:

From: Russell King: Mon Apr 18 22:50:01 BST 2005
	
	[PATCH] ARM: Add missing new file for bitops patch
	
	Signed-off-by: Russell King


-- 
Russell King


^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Greg KH @ 2005-04-18 22:14 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Russell King, David Woodhouse, Git Mailing List, Peter Anvin
In-Reply-To: <20050418220541.GB19744@kroah.com>

On Mon, Apr 18, 2005 at 03:05:41PM -0700, Greg KH wrote:
> On Mon, Apr 18, 2005 at 08:42:14AM -0700, Linus Torvalds wrote:
> > 
> > 
> > On Mon, 18 Apr 2005, Greg KH wrote:
> > >
> > > On Sun, Apr 17, 2005 at 04:24:24PM -0700, Linus Torvalds wrote:
> > > > 
> > > > Tools absolutely matter. And it will take time for us to build up that 
> > > > kind of helper infrastructure. So being newbie might be part of it, but 
> > > > it's the smaller part, I say. Rough interfaces is a big issue.
> > > 
> > > Speaking of tools, you had a "dotest" program to apply patches in email
> > > form to a bk tree.  And from what I can gather, you've changed that to
> > > handle git archives, right?
> > 
> > Yup.
> > 
> > It's a git archive at 
> > 
> > 	kernel.org:/pub/linux/kernel/people/torvalds/git-tools.git
> > 
> > and it seems to work. It's what I've used for all the kernel patches 
> > (except for the merge), and it's what I use for the git stuff that shows 
> > up as authored by others.
> 
> Hm, have you pushed all of the recent changes public?  I get the
> following when trying to apply a patch:
> $ ../git-tools/dotest < ~/linux/patches/usb/usb-visor-tapwave_zodiac.patch 
>  mailsplit <mbox> <directory>

Doh, you want it as a command line argument now.  Stupid me...

Anyway, I try it this way and get:

$ dotest ~/linux/patches/usb/usb-visor-tapwave_zodiac.patch             

Applying USB: visor Tapwave Zodiac support patch

fatal: preparing to update file 'drivers/usb/serial/visor.c' not uptodate in cache


What did I forget to do?

thanks,

greg k-h

^ permalink raw reply

* Re: [PATCH] fix bug in read-cache.c which loses files when merging a tree
From: Linus Torvalds @ 2005-04-18 22:09 UTC (permalink / raw)
  To: Petr Baudis; +Cc: James Bottomley, Git Mailing List
In-Reply-To: <20050418215819.GH5554@pasky.ji.cz>



On Mon, 18 Apr 2005, Petr Baudis wrote:
> 
> So, I'm confused. Why did you introduce unpack-file instead of doing
> just this?

It was code that I already had (ie the old code from "merge-cache" just
moved over), and thanks to that, I don't have to worry about broken
"mktemp" crap in user space...

		Linus

^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Greg KH @ 2005-04-18 22:05 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Russell King, David Woodhouse, Git Mailing List, Peter Anvin
In-Reply-To: <Pine.LNX.4.58.0504180840370.7211@ppc970.osdl.org>

On Mon, Apr 18, 2005 at 08:42:14AM -0700, Linus Torvalds wrote:
> 
> 
> On Mon, 18 Apr 2005, Greg KH wrote:
> >
> > On Sun, Apr 17, 2005 at 04:24:24PM -0700, Linus Torvalds wrote:
> > > 
> > > Tools absolutely matter. And it will take time for us to build up that 
> > > kind of helper infrastructure. So being newbie might be part of it, but 
> > > it's the smaller part, I say. Rough interfaces is a big issue.
> > 
> > Speaking of tools, you had a "dotest" program to apply patches in email
> > form to a bk tree.  And from what I can gather, you've changed that to
> > handle git archives, right?
> 
> Yup.
> 
> It's a git archive at 
> 
> 	kernel.org:/pub/linux/kernel/people/torvalds/git-tools.git
> 
> and it seems to work. It's what I've used for all the kernel patches 
> (except for the merge), and it's what I use for the git stuff that shows 
> up as authored by others.

Hm, have you pushed all of the recent changes public?  I get the
following when trying to apply a patch:
$ ../git-tools/dotest < ~/linux/patches/usb/usb-visor-tapwave_zodiac.patch 
 mailsplit <mbox> <directory>
$ 

I set my PATH to point to the git-tools/ directory:
$ which mailsplit
/home/greg/linux/git/git-tools/mailsplit

Any thoughts?

thanks,

greg k-h

^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Linus Torvalds @ 2005-04-18 22:01 UTC (permalink / raw)
  To: Russell King; +Cc: Petr Baudis, Git Mailing List
In-Reply-To: <20050418225356.B16789@flint.arm.linux.org.uk>



On Mon, 18 Apr 2005, Russell King wrote:
> > 
> > 	# Get the trees associated with those commits
> > 	common_tree=tree=$(cat-file commit $common | sed 's/tree //;q')
> > 	head_tree=tree=$(cat-file commit $head | sed 's/tree //;q')
> > 	merge_tree=tree=$(cat-file commit $merge | sed 's/tree //;q')
> 
> This wants to be:
> 
> 	common_tree=$(cat-file commit $common | sed 's/tree //;q')
> 	head_tree=$(cat-file commit $head | sed 's/tree //;q')
> 	merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')

Yup, I already fixed that in the current git version.

> > 		read-tree $merge_tree && checkout-cache -f -a
> 
> Don't we want to do an update-cache --refresh here?

Yes. Thanks, added.

		Linus

^ permalink raw reply

* Re: [PATCH] fix bug in read-cache.c which loses files when merging a tree
From: Petr Baudis @ 2005-04-18 21:58 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: James Bottomley, Git Mailing List
In-Reply-To: <Pine.LNX.4.58.0504181330450.15725@ppc970.osdl.org>

Dear diary, on Mon, Apr 18, 2005 at 11:19:46PM CEST, I got a letter
where Linus Torvalds <torvalds@osdl.org> told me that...
> I suspect that I should just pass in the SHA1 of the files to the
> "merge-one-file-script" from "merge-cache", rather than unpacking it.  
> After all, the merging script can do the unpacking itself with a simple
> "cat-file blob $sha1".

So, I'm confused. Why did you introduce unpack-file instead of doing
just this?

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Linus Torvalds @ 2005-04-18 21:56 UTC (permalink / raw)
  To: Russell King; +Cc: Petr Baudis, Git Mailing List
In-Reply-To: <20050418223359.A16789@flint.arm.linux.org.uk>



On Mon, 18 Apr 2005, Russell King wrote:
> 
> Since this happened, I've been working out what state my tree is in,
> and I restored it back to a state where I had one dangling commit head,
> which was _my_ head.

For the future, if your tree gets messed up to the point where you say 
"screw it" and just want to go back in time, you can do this (it's 
equivalent to "undo" in BK speak):

	git log | less -S

	.. find which HEAD it was that you trusted..

In this case your HEAD before I merged with it was this one:

	df4449813c900973841d0fa5a9e9bc7186956e1e

So to get back to that one, you can do

	echo df4449813c900973841d0fa5a9e9bc7186956e1e > .git/HEAD

and now

	cat-file commit $(cat .git/HEAD) | head -1

gives you

	tree a43c4447b2edc9fb01a6369f10c1165de4494c88

so you can restore your checked-out state with

	read-tree a43c4447b2edc9fb01a6369f10c1165de4494c88
	checkout-cache -f -a
	update-cache --refresh

and your tree should be valid again.

Now, to remove any bogus objects, you can then run my "git-prune-script"
(look at it carefully first to make sure you realize what you are doing).

NOTE NOTE NOTE! This will _revert_ everything you had done after the 
"trusted" point. So you may not actually want to do this. Instead:

> It's very much like I somehow committed against the _parent_ of the
> head, rather than the head itself.

That's very common if you just forget to update your new ".git/HEAD" when 
you do a commit.

Again, it's the tools that make it a bit too easy to mess up. The 
"commit-tree" thing is supposed to really only be used from scripts (which 
would do something like

	result=$(commit-tree ...) && echo $result > .git/HEAD

but when doing things by hand, if you forget to update your HEAD, your 
next commit will be done against the wrong head, and you get dangling 
commits.

The good news is that this is not that hard to fix up. The _trees_ are all
correct, and the objects are all correct, so what you can do is just
generate a few new (proper) commit objects, with the right parents. Then
you can do the "git-prune-script" thing that will throw away the old
broken commits, since they won't be reachable from your new commits (even
though their _trees_ will be there and be the same).

So in this case:

	b4a9a5114b3c6da131a832a8e2cd1941161eb348
	+- e7905b2f22eb5d5308c9122b9c06c2d02473dd4f
	   +- dc90c0db0dd5214aca5304fd17ccd741031e5493 <-- extra dangling head
	   +- 488faba31f59c5960aabbb2a5877a0f2923937a3

you can do

	cat-file commit dc90c0db0dd5214aca5304fd17ccd741031e5493

to remind you what your old tree and commit message was, and then just 
re-commit that tree with the same message but with the proper parent:

	commit-tree xxxx -p 488faba31f59c5960aabbb2a5877a0f2923937a3

and then you need to do the same thing for the other commits (which will 
now need to be re-based to have the new commit-chain as their parents).

Then, when you fixed up the final one, remember to update .git/HEAD with 
its commit ID, and now the prune-thing will get rid of the old dangling 
commits that you just created new duplicates of.

		Linus

^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Russell King @ 2005-04-18 21:53 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Petr Baudis, Git Mailing List
In-Reply-To: <Pine.LNX.4.58.0504180802060.7211@ppc970.osdl.org>

On Mon, Apr 18, 2005 at 08:23:16AM -0700, Linus Torvalds wrote:
> NOTE NOTE NOTE! This is untested! I'm writing this within the email 
> editor, so do _not_ do this on a tree that you care about.

It did the right thing for me at least!

> 	#!/bin/sh
> 	#
> 	# use "$1" or something in a real script, this 
> 	# just hard-codes it.
> 	#
> 	merge_repo=master.kernel.org:/pub/linux/kernel/people/torvalds/linux-2.6.git
> 
> 	echo "Getting object database"
> 	rsync -avz --ignore-existing $merge_repo/ .git/
> 
> 	echo "Getting remote head"
> 	rsync -avz $merge_repo/HEAD .git/MERGE_HEAD
> 
> 	head=$(cat .git/HEAD)
> 	merge_head=$(cat .git/MERGE-HEAD)
> 	common=$(merge-base $head $merge_head)
> 	if [ -z "$common" ]; then
> 		echo "Unable to find common commit between" $merge_head $head
> 		exit 1
> 	fi
> 
> 	# Get the trees associated with those commits
> 	common_tree=tree=$(cat-file commit $common | sed 's/tree //;q')
> 	head_tree=tree=$(cat-file commit $head | sed 's/tree //;q')
> 	merge_tree=tree=$(cat-file commit $merge | sed 's/tree //;q')

This wants to be:

	common_tree=$(cat-file commit $common | sed 's/tree //;q')
	head_tree=$(cat-file commit $head | sed 's/tree //;q')
	merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')

> 	if [ "$common" == "$merge_head" ]; then
> 		echo "Already up-to-date. Yeeah!"
> 		exit 0
> 	fi
> 	if [ "$common" == "$head" ]; then
> 		echo "Updating from $head to $merge_head."
> 		echo "Destroying all noncommitted data!"
> 		echo "Kill me within 3 seconds.."
> 		sleep 3
> 		read-tree $merge_tree && checkout-cache -f -a

Don't we want to do an update-cache --refresh here?

> 		echo $merge_head > .git/HEAD
> 		exit 0
> 	fi
> 	echo "Trying to merge $merge_head into $head"
> 	read-tree -m $common_tree $head_tree $merge_tree
> 	result_tree=$(write-tree) || exit 1
> 	result_commit=$(echo "Merge $merge_repo" | commit-tree $result_tree -p $head -p $merge_head)
> 	echo "Committed merge $result_commit"
> 	echo $result_commit > .git/HEAD
> 	read-tree $result_tree && checkout-cache -f -a
> 
> The above looks like it might work, but I also warn you: it's not only
> untested, but it's pretty fragile in that if something breaks, you are
> probably left with a mess. I _tried_ to do the right thing, but... So it
> obviously will need testing, tweaking and just general tender loving care.

Maybe Petr can improve the error handling, and incorporate it (or at
least some of it) into git-pasky

> You shouldn't hit the "merge" case at all right now, you should hit the 
> "Updating from $head to $merge_head" thing.

Exactly what happened.  Thanks.

-- 
Russell King


^ permalink raw reply

* Re: SCSI trees, merges and git status
From: Linus Torvalds @ 2005-04-18 21:39 UTC (permalink / raw)
  To: James Bottomley; +Cc: git, SCSI Mailing List
In-Reply-To: <1113856118.4998.70.camel@mulgrave>



On Mon, 18 Apr 2005, James Bottomley wrote:
>
> As of today, I have two SCSI git trees operational:
> 
> rsync://www.parisc-linux.org/~jejb/scsi-rc-fixes-2.6.git

Merged. Here's the command line history:

	~/git/git-pull-script rsync://www.parisc-linux.org/~jejb/scsi-rc-fixes-2.6.git
	merge-cache ~/git/git-merge-one-file-script -a
	write-tree 
	commit-tree 2c8de70faf92af971667a26a6a397052fc572add -p $(cat .git/HEAD) -p $(cat .git/MERGE_HEAD)

ie the "git-pull-script" failed due to the content merge (I didn't trust 
the merge-cache stuff enough to put that into it), but then doing the 
automated merge was successful without any editing, so I just wrote the 
tree and committed it.

Again, if anybody wants to reproduce this, you'll need to then do the

	checkout-cache -f -a
	update-cace --refresh

afterwards to make your working area match the merged tree.

> Linus, the rc-fixes repo is ready for applying ... it's the same one I
> announced on linux-scsi and lkml a while ago just with the git date
> information updated to be correct (the misc one should wait until after
> 2.6.12 is final).

Ok. Can you verify? I did a "git diff" between your old head and my new
head, and it did not show any SCSI files (only the expected arm etc stuff
that you didn't have in your), so it all _looks_ good. But hey, just to
make sure that I didn't do anything stupid..

		Linus

^ permalink raw reply

* Re: Re-done kernel archive - real one?
From: Russell King @ 2005-04-18 21:33 UTC (permalink / raw)
  To: Linus Torvalds, Petr Baudis; +Cc: Git Mailing List
In-Reply-To: <20050418102332.A21081@flint.arm.linux.org.uk>

On Mon, Apr 18, 2005 at 10:23:32AM +0100, Russell King wrote:
> On Sun, Apr 17, 2005 at 04:24:24PM -0700, Linus Torvalds wrote:
> > On Sun, 17 Apr 2005, Russell King wrote:
> > > I pulled it tonight into a pristine tree (which of course worked.)
> > 
> > Goodie.
> 
> Note the "pristine".  Now comes the real test...
> 
> > > In doing so, I noticed that I'd messed up one of the commits - there's
> > > a missing new file.  Grr.  I'll put that down to being a newbie git.
> > 
> > Actually, you should put that down to horribly bad interface tools.  With
> > BK, we had these nice tools that pointed out that there were files that
> > you might want to commit (ie "bk citool"), and made this very obvious.
> > 
> > Tools absolutely matter. And it will take time for us to build up that 
> > kind of helper infrastructure. So being newbie might be part of it, but 
> > it's the smaller part, I say. Rough interfaces is a big issue.
> 
> Ok, I just tried pulling your tree into the tree you pulled from, and
> got this:
>...

Since this happened, I've been working out what state my tree is in,
and I restored it back to a state where I had one dangling commit head,
which was _my_ head.

I then checked whether my objects matched the objects which I uploaded
to master.kernel.org, and discovered I'd removed some extra ones.  With
them restored, I have an additional dangling commit.

Now, I'm pretty sure that I had an up to date tree when I did the
original commits, so I'm a little confused.

What I'm seeing is:

b4a9a5114b3c6da131a832a8e2cd1941161eb348
+- e7905b2f22eb5d5308c9122b9c06c2d02473dd4f
   +- dc90c0db0dd5214aca5304fd17ccd741031e5493 <-- extra dangling head
   +- 488faba31f59c5960aabbb2a5877a0f2923937a3
      +- 5d9a545981893629c8f95e2b8b50d15d18c6ddbc
         +- d5922e9c35d21f0b6b82d1fd8b1444cfce57ca34
            +- ff219d69be01af1fd04ada305b5fe7cd4c563cc6
               +- df4449813c900973841d0fa5a9e9bc7186956e1e <-- my head

It's very much like I somehow committed against the _parent_ of the
head, rather than the head itself.

However, I've lost the state that this tree was in when I did the initial
commit, so who knows why this happened...  I think it's something to
keep an eye out for though.

-- 
Russell King


^ permalink raw reply

* Re: [PATCH] fix bug in read-cache.c which loses files when merging a tree
From: Linus Torvalds @ 2005-04-18 21:19 UTC (permalink / raw)
  To: James Bottomley; +Cc: Git Mailing List
In-Reply-To: <1113854941.4998.61.camel@mulgrave>



On Mon, 18 Apr 2005, James Bottomley wrote:
> 
> I had a problem with the SCSI tree in that there's a file removal in one
> branch.  Your git-merge-one-file-script wouldn't have handled this
> correctly: It seems to think that the file must be removed in both
> branches, which is wrong.

Yes, I agree. My current "merge-one-file-script" doesn't actually look at 
what the original file was in this situation, and clearly it should. I 
think I'll leave it for the user to decide what happens when somebody has 
modified the deleted file, but clearly we should delete it if the other 
branch has not touched it.

I suspect that I should just pass in the SHA1 of the files to the
"merge-one-file-script" from "merge-cache", rather than unpacking it.  
After all, the merging script can do the unpacking itself with a simple
"cat-file blob $sha1".

And the fact is, many of the trivial merges should be handled by just
looking at the content, and doing a "cmp" on the files seems to be a
stupid way to do that when we had the sha1 earlier.

Done, and pushed out. Does the new merge infrastructure work for you?

		Linus

^ permalink raw reply

* Re: Add + Status patches
From: Junio C Hamano @ 2005-04-18 21:00 UTC (permalink / raw)
  To: David Greaves; +Cc: Petr Baudis, git
In-Reply-To: <42641AE4.9050700@dgreaves.com>

>>>>> "DG" == David Greaves <david@dgreaves.com> writes:

DG> Hi Petr
DG> Thankyou for the help earlier - problem resolved.

DG> I have a trivial patch (attached).

DG> It allows:
DG>  find src -type f | git add -

I am slow today, but have you considered using xargs?



^ permalink raw reply

* Re: [PATCH] Get commits from remote repositories by HTTP
From: tony.luck @ 2005-04-18 20:48 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git
In-Reply-To: <20050418184750.GD5554@pasky.ji.cz>

> ...and this is precisely why ls-tree actually outputs those "blob" and
> "tree" tags. ;-)

Doh!

Here's a fresh copy with "if [ $tag = tree ]".  I just used it to pull
from Linus into an "empty" directory (just ran init-db to make the .git
.git/objects and .git/objects/xx directories).

-Tony


#!/bin/bash

# Copyright (C) 2005 Tony Luck

REMOTE=http://www.kernel.org/pub/linux/kernel/people/torvalds/linux-2.6.git/

rm -rf .gittmp
# set up a temp git repository so that we can use cat-file and ls-tree on the
# objects we pull without installing them into our tree. This allows us to
# restart if the download is interrupted
mkdir .gittmp
cd .gittmp
init-db

wget -q $REMOTE/HEAD

if cmp -s ../.git/HEAD HEAD
then
	echo Already have HEAD = `cat ../.git/HEAD`
	cd ..
	rm -rf .gittmp
	exit 0
fi

sha1=`cat HEAD`
sha1file=${sha1:0:2}/${sha1:2}

if [ -f ../.git/objects/$sha1file ]
then
	echo Already have most recent commit. Update HEAD to $sha1
	cd ..
	rm -rf .gittmp
	exit 0
fi

wget -q $REMOTE/objects/$sha1file -O .git/objects/$sha1file

treesha1=`cat-file commit $sha1 | (read tag tree ; echo $tree)`

get_tree()
{
	treesha1file=${1:0:2}/${1:2}
	if [ -f ../.git/objects/$treesha1file ]
	then
		return
	fi
	wget -q $REMOTE/objects/$treesha1file -O .git/objects/$treesha1file
	ls-tree $1 | while read mode tag sha1 name
	do
		subsha1file=${sha1:0:2}/${sha1:2}
		if [  -f ../.git/objects/$subsha1file ]
		then
			continue
		fi
		if [ $tag = tree ]
		then
			get_tree $sha1 `expr $2 + 1`
		else
			echo objects/$subsha1file >> needbloblist
		fi
	done
}

# get all the tree objects to our .gittmp area, and create list of needed blobs
get_tree $treesha1

# now get the blobs
cd ../.git
if [ -s ../.gittmp/needbloblist ]
then
	wget -q -r -nH  --cut-dirs=6 --base=$REMOTE -i ../.gittmp/needbloblist
fi

# Now we have the blobs, move the trees and commit from .gitttmp
cd ../.gittmp/.git/objects
find ?? -type f -print | while read f
do
	mv $f ../../../.git/objects/$f
done

# update HEAD
cd ../..
mv HEAD ../.git

cd ..
rm -rf .gittmp

^ permalink raw reply

* Re: Add + Status patches
From: Petr Baudis @ 2005-04-18 20:48 UTC (permalink / raw)
  To: David Greaves; +Cc: git
In-Reply-To: <42641AE4.9050700@dgreaves.com>

Dear diary, on Mon, Apr 18, 2005 at 10:39:00PM CEST, I got a letter
where David Greaves <david@dgreaves.com> told me that...
> Hi Petr

Hi,

> Thankyou for the help earlier - problem resolved.
> 
> I have a trivial patch (attached).
> 
> It allows:
> find src -type f | git add -
> 
> and fixes git status not reporting added files properly (on my debian 
> system it only reported the first file in .git/add-queue)

Thanks. Could you please send the patches signed off and either with
content-disposition: inline or in the mail body?

I think it would be cleaner to do the testing for the dash in the for
loop, so that I can do git add foo bar -.  Also, don't forget to update
git add's documentation at the top. For the usage string, I'd probably
prefer (-|FILE)...

thanks,

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

^ permalink raw reply

* Add + Status patches
From: David Greaves @ 2005-04-18 20:39 UTC (permalink / raw)
  To: Petr Baudis, git

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

Hi Petr

Thankyou for the help earlier - problem resolved.

I have a trivial patch (attached).

It allows:
 find src -type f | git add -

and fixes git status not reporting added files properly (on my debian 
system it only reported the first file in .git/add-queue)

Should I send this as a patch or as some kind of git object?
(I'm still trying to figure out git workflow)

David

-- 


[-- Attachment #2: add_status.patch --]
[-- Type: text/x-patch, Size: 2537 bytes --]

Index: README
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/README  (mode:100644 sha1:798476ad292cc6edf5a2f5782e1de82f6052abe2)
+++ 1c3349b813d463ce194be06f14ccfbcc3fc2ba30/README  (mode:100644 sha1:4282af1604e429dd767fe721751b5ac4a87c410e)
@@ -89,6 +89,10 @@
 Of course you will want to commit. If you added any new files, do
 
 	git add newfile1 newfile2 ...
+	
+or even
+
+	find src -type f | git add -
 
 first. Then feel free to commit by
 
Index: git
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/git  (mode:100755 sha1:b648169640025bd68d1b27a0fcc85b65d85e4440)
+++ 1c3349b813d463ce194be06f14ccfbcc3fc2ba30/git  (mode:100755 sha1:5f3d4d04a0adfdc26bfc6aaef5cd29eea6e5c459)
@@ -25,7 +25,7 @@
 Usage: git COMMAND [ARG]...
 
 Available commands:
-	add		FILE...
+	add		FILE...  | -    < files on stdin
 	addremote	RNAME RSYNC_URL
 	apply				< patch on stdin
 	cancel
Index: gitadd.sh
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/gitadd.sh  (mode:100755 sha1:3ed93ea0fcb995673ba9ee1982e0e7abdbe35982)
+++ 1c3349b813d463ce194be06f14ccfbcc3fc2ba30/gitadd.sh  (mode:100755 sha1:d010d14c0c14e0ea7a2e448b667d938fe92a3bc2)
@@ -9,10 +9,14 @@
 # FIXME: Those files are omitted from show-diff output!
 
 if [ ! "$1" ]; then
-	echo "gitadd.sh: usage: git add FILE..." >&2
+	echo "gitadd.sh: usage: git add - | FILE..." >&2
 	exit 1;
 fi
 
-for file in "$@"; do
-	echo $file >>.git/add-queue
-done
+if [ $1 == "-" ]; then
+	cat - >> .git/add-queue
+else
+	for file in "$@"; do
+		echo $file >>.git/add-queue
+	done
+fi
Index: gitstatus.sh
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/gitstatus.sh  (mode:100755 sha1:6c33f805ebc2630b14a88a07dfc891a9196d66a5)
+++ 1c3349b813d463ce194be06f14ccfbcc3fc2ba30/gitstatus.sh  (mode:100755 sha1:e2c7f9d56b6967c529453de675ffffaaeeff3d1c)
@@ -5,8 +5,8 @@
 
 {
 	show-files -z -t --others --deleted --unmerged
-	[ -s .git/add-queue ] && cat .git/add-queue | sed 's/^/A /' | { read x; echo -ne $x'\0'; }
-	[ -s .git/rm-queue ] && cat .git/rm-queue | sed 's/^/D /' | { read x; echo -ne $x'\0'; }
+	[ -s .git/add-queue ] && cat .git/add-queue | sed 's/^/A /' | tr '\n' '\0'
+	[ -s .git/rm-queue ] && cat .git/rm-queue | sed 's/^/D /' | tr '\n' '\0'
 } | sort -z -k 2 | xargs -0 sh -c '
 while [ "$1" ]; do
 	tag=$(echo "$1" | cut -d " " -f 1);

^ permalink raw reply

* [PATCH 6/6] show-diff.c: -R option for reverse diff.
From: Junio C Hamano @ 2005-04-18 20:36 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

This patch is optional.  It adds -R option to obtain reverse diff.

It may be useful in the merge workflow.  After the base of the working
directory is merged and commited, in the working directory:

    $ read-tree <tree-id-of-merged-tree>
    $ show-diff -R

to re-validate if upstream changes make sense, and/or revert or
conflict with local changes you have in the working files.

To be applied on top of:

    [PATCH 1/6] show-diff.c: clean up private buffer use.
    [PATCH 2/6] show-diff.c: check unreadbale blob.
    [PATCH 3/6] show-diff.c: simplify show_diff_empty.
    [PATCH 4/6] show-diff.c: adjust default format for the Linux kernel.
    [PATCH 5/6] show-diff.c: make diff options customizable.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 show-diff.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

--- a/show-diff.c
+++ b/show-diff.c
@@ -7,6 +7,8 @@
 
 static char *diff_cmd = "diff -L 'a/%s' -L 'b/%s' ";
 static char *diff_opts = "-p -u";
+static char *diff_arg_forward  = " - '%s'";
+static char *diff_arg_reverse  = " '%s' -";
 
 static void prepare_diff_cmd(void)
 {
@@ -63,12 +65,12 @@ static char *sq_expand(char *src)
 }
 
 static void show_differences(char *name, char *label, void *old_contents,
-			     unsigned long long old_size)
+			     unsigned long long old_size, int reverse)
 {
-	static char *diff_arg = " - '%s'";
 	FILE *f;
 	char *name_sq = sq_expand(name);
 	char *label_sq = (name != label) ? sq_expand(label) : name_sq;
+	char *diff_arg = reverse ? diff_arg_reverse : diff_arg_forward;
 	int cmd_size = strlen(name_sq) + strlen(label_sq) * 2 +
 		strlen(diff_cmd) + strlen(diff_opts) + strlen(diff_arg);
 	char *cmd = malloc(cmd_size);
@@ -88,7 +90,7 @@ static void show_differences(char *name,
 	free(cmd);
 }
 
-static void show_diff_empty(struct cache_entry *ce)
+static void show_diff_empty(struct cache_entry *ce, int reverse)
 {
 	char *old;
 	unsigned long int size;
@@ -100,7 +102,7 @@ static void show_diff_empty(struct cache
 		      sha1_to_hex(ce->sha1));
 		return;
 	}
-	show_differences("/dev/null", ce->name, old, size);
+	show_differences("/dev/null", ce->name, old, size, reverse);
 }
 
 static const char *show_diff_usage = "show-diff [-q] [-s] [-z] [paths...]";
@@ -125,11 +127,14 @@ int main(int argc, char **argv)
 	int silent = 0;
 	int silent_on_nonexisting_files = 0;
 	int machine_readable = 0;
+	int reverse = 0;
 	int entries = read_cache();
 	int i;
 
 	while (1 < argc && argv[1][0] == '-') {
-		if (!strcmp(argv[1], "-s"))
+		if  (!strcmp(argv[1], "-R"))
+			reverse = 1;
+		else if (!strcmp(argv[1], "-s"))
 			silent_on_nonexisting_files = silent = 1;
 		else if (!strcmp(argv[1], "-q"))
 			silent_on_nonexisting_files = 1;
@@ -181,7 +186,7 @@ int main(int argc, char **argv)
 			else {
 				printf("%s: %s\n", ce->name, strerror(errno));
 				if (errno == ENOENT)
-					show_diff_empty(ce);
+					show_diff_empty(ce, reverse);
 			}
 			continue;
 		}
@@ -202,7 +207,8 @@ int main(int argc, char **argv)
 			error("unable to read blob object for %s (%s)",
 			      ce->name, sha1_to_hex(ce->sha1));
 		else
-			show_differences(ce->name, ce->name, old, size);
+			show_differences(ce->name, ce->name, old, size,
+					 reverse);
 		free(old);
 	}
 	return 0;


^ permalink raw reply

* [PATCH 5/6] show-diff.c: make diff options customizable.
From: Junio C Hamano @ 2005-04-18 20:36 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

This patch is optional.  If makes the diff output formatting
options customizable via the environment variables.  The default
is still the Linux kernel style.

To be applied on top of:

    [PATCH 1/6] show-diff.c: clean up private buffer use.
    [PATCH 2/6] show-diff.c: check unreadbale blob.
    [PATCH 3/6] show-diff.c: simplify show_diff_empty.
    [PATCH 4/6] show-diff.c: adjust default format for the Linux kernel.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 show-diff.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

--- a/show-diff.c
+++ b/show-diff.c
@@ -5,7 +5,23 @@
  */
 #include "cache.h"
 
-static char *diff_cmd = "diff -L 'a/%s' -L 'b/%s' -p -u - '%s'";
+static char *diff_cmd = "diff -L 'a/%s' -L 'b/%s' ";
+static char *diff_opts = "-p -u";
+
+static void prepare_diff_cmd(void)
+{
+	/*
+	 * Default values above are meant to match the
+	 * Linux kernel development style.  Examples of
+	 * alternative styles you can specify via environment
+	 * variables are:
+	 *
+	 * GIT_DIFF_CMD="diff -L '%s' -L '%s'"
+	 * GIT_DIFF_OPTS="-c";
+	 */
+	diff_cmd = getenv("GIT_DIFF_CMD") ? : diff_cmd;
+	diff_opts = getenv("GIT_DIFF_OPTS") ? : diff_opts;
+}
 
 /* Help to copy the thing properly quoted for the shell safety.
  * any single quote is replaced with '\'', and the caller is
@@ -49,15 +65,19 @@ static char *sq_expand(char *src)
 static void show_differences(char *name, char *label, void *old_contents,
 			     unsigned long long old_size)
 {
+	static char *diff_arg = " - '%s'";
 	FILE *f;
 	char *name_sq = sq_expand(name);
 	char *label_sq = (name != label) ? sq_expand(label) : name_sq;
-	int cmd_size = strlen(name_sq) +
-		strlen(label_sq) * 2 + strlen(diff_cmd);
+	int cmd_size = strlen(name_sq) + strlen(label_sq) * 2 +
+		strlen(diff_cmd) + strlen(diff_opts) + strlen(diff_arg);
 	char *cmd = malloc(cmd_size);
+	int next_at;
 
 	fflush(stdout);
-	snprintf(cmd, cmd_size, diff_cmd, label_sq, label_sq, name_sq);
+	next_at = snprintf(cmd, cmd_size, diff_cmd, label_sq, label_sq);
+	next_at += snprintf(cmd+next_at, cmd_size-next_at, "%s", diff_opts);
+	next_at += snprintf(cmd+next_at, cmd_size-next_at, diff_arg, name_sq);
 	f = popen(cmd, "w");
 	if (old_size)
 		fwrite(old_contents, old_size, 1, f);
@@ -127,6 +147,7 @@ int main(int argc, char **argv)
 		perror("read_cache");
 		exit(1);
 	}
+	prepare_diff_cmd();
 	for (i = 0; i < entries; i++) {
 		struct stat st;
 		struct cache_entry *ce = active_cache[i];


^ permalink raw reply

* [PATCH 4/6] show-diff.c: adjust default format for the Linux kernel.
From: Junio C Hamano @ 2005-04-18 20:35 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

[PATCH 4/6] show-diff.c: adjust default format for the Linux kernel.

This patch adjusts the default output format of show-diff to match
the Linux kernel style, recommended in Documentation/SubmittingPatches.

To be applied on top of:

    [PATCH 1/6] show-diff.c: clean up private buffer use.
    [PATCH 2/6] show-diff.c: check unreadbale blob.
    [PATCH 3/6] show-diff.c: simplify show_diff_empty.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 show-diff.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

--- a/show-diff.c
+++ b/show-diff.c
@@ -5,7 +5,7 @@
  */
 #include "cache.h"
 
-static char *diff_cmd = "diff -L '%s' -u -N  - '%s'";
+static char *diff_cmd = "diff -L 'a/%s' -L 'b/%s' -p -u - '%s'";
 
 /* Help to copy the thing properly quoted for the shell safety.
  * any single quote is replaced with '\'', and the caller is
@@ -52,11 +52,12 @@ static void show_differences(char *name,
 	FILE *f;
 	char *name_sq = sq_expand(name);
 	char *label_sq = (name != label) ? sq_expand(label) : name_sq;
-	int cmd_size = strlen(name_sq) + strlen(label_sq) + strlen(diff_cmd);
+	int cmd_size = strlen(name_sq) +
+		strlen(label_sq) * 2 + strlen(diff_cmd);
 	char *cmd = malloc(cmd_size);
 
 	fflush(stdout);
-	snprintf(cmd, cmd_size, diff_cmd, label_sq, name_sq);
+	snprintf(cmd, cmd_size, diff_cmd, label_sq, label_sq, name_sq);
 	f = popen(cmd, "w");
 	if (old_size)
 		fwrite(old_contents, old_size, 1, f);


^ permalink raw reply

* [PATCH 3/6] show-diff.c: simplify show_diff_empty.
From: Junio C Hamano @ 2005-04-18 20:34 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

[PATCH 3/6] show-diff.c: simplify show_diff_empty.

This patch removes the custom diff generation code from the
show_diff_empty() function.  Instead, just use show_differences().

This reduces the code size; but more importantly, it is needed for
the later patch to give diff options.

To be applied on top of:

    [PATCH 1/6] show-diff.c: clean up private buffer use.
    [PATCH 2/6] show-diff.c: check unreadbale blob.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 show-diff.c |   44 ++++++++++----------------------------------
 1 files changed, 10 insertions(+), 34 deletions(-)

--- a/show-diff.c
+++ b/show-diff.c
@@ -46,19 +46,23 @@ static char *sq_expand(char *src)
 	return buf;
 }
 
-static void show_differences(char *name, void *old_contents,
+static void show_differences(char *name, char *label, void *old_contents,
 			     unsigned long long old_size)
 {
 	FILE *f;
 	char *name_sq = sq_expand(name);
-	int cmd_size = strlen(name_sq) * 2 + strlen(diff_cmd);
+	char *label_sq = (name != label) ? sq_expand(label) : name_sq;
+	int cmd_size = strlen(name_sq) + strlen(label_sq) + strlen(diff_cmd);
 	char *cmd = malloc(cmd_size);
 
-	snprintf(cmd, cmd_size, diff_cmd, name_sq, name_sq);
+	fflush(stdout);
+	snprintf(cmd, cmd_size, diff_cmd, label_sq, name_sq);
 	f = popen(cmd, "w");
 	if (old_size)
 		fwrite(old_contents, old_size, 1, f);
 	pclose(f);
+	if (label_sq != name_sq)
+		free(label_sq);
 	free(name_sq);
 	free(cmd);
 }
@@ -67,8 +71,7 @@ static void show_diff_empty(struct cache
 {
 	char *old;
 	unsigned long int size;
-	int lines=0;
-	unsigned char type[20], *p, *end;
+	unsigned char type[20];
 
 	old = read_sha1_file(ce->sha1, type, &size);
 	if (! old) {
@@ -76,33 +79,7 @@ static void show_diff_empty(struct cache
 		      sha1_to_hex(ce->sha1));
 		return;
 	}
-	if (size > 0) {
-		int startline = 1;
-		int c = 0;
-
-		printf("--- %s\n", ce->name);
-		printf("+++ /dev/null\n");
-		p = old;
-		end = old + size;
-		while (p < end)
-			if (*p++ == '\n')
-				lines ++;
-		printf("@@ -1,%d +0,0 @@\n", lines);
-		p = old;
-		while (p < end) {
-			c = *p++;
-			if (startline) {
-				putchar('-');
-				startline = 0;
-			}
-			putchar(c);
-			if (c == '\n')
-				startline = 1;
-		}
-		if (c!='\n')
-			printf("\n");
-		fflush(stdout);
-	}
+	show_differences("/dev/null", ce->name, old, size);
 }
 
 static const char *show_diff_usage = "show-diff [-q] [-s] [-z] [paths...]";
@@ -195,7 +172,6 @@ int main(int argc, char **argv)
 			printf("%s %s%c", sha1_to_hex(ce->sha1), ce->name, 0);
 			continue;
 		}
-		fflush(stdout);
 		if (silent)
 			continue;
 
@@ -204,7 +180,7 @@ int main(int argc, char **argv)
 			error("unable to read blob object for %s (%s)",
 			      ce->name, sha1_to_hex(ce->sha1));
 		else
-			show_differences(ce->name, old, size);
+			show_differences(ce->name, ce->name, old, size);
 		free(old);
 	}
 	return 0;


^ permalink raw reply

* [PATCH 2/6] show-diff.c: check unreadbale blob.
From: Junio C Hamano @ 2005-04-18 20:34 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

[PATCH 2/6] show-diff.c: check unreadbale blob.

This patch fixes show-diff to detect unreadable blob and warn
instead of going ahead and crashing.

To be applied on top of:

    [PATCH 1/6] show-diff.c: clean up private buffer use.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 show-diff.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletion(-)

--- a/show-diff.c
+++ b/show-diff.c
@@ -71,6 +71,11 @@ static void show_diff_empty(struct cache
 	unsigned char type[20], *p, *end;
 
 	old = read_sha1_file(ce->sha1, type, &size);
+	if (! old) {
+		error("unable to read blob object for %s (%s)", ce->name,
+		      sha1_to_hex(ce->sha1));
+		return;
+	}
 	if (size > 0) {
 		int startline = 1;
 		int c = 0;
@@ -195,7 +200,11 @@ int main(int argc, char **argv)
 			continue;
 
 		old = read_sha1_file(ce->sha1, type, &size);
-		show_differences(ce->name, old, size);
+		if (! old)
+			error("unable to read blob object for %s (%s)",
+			      ce->name, sha1_to_hex(ce->sha1));
+		else
+			show_differences(ce->name, old, size);
 		free(old);
 	}
 	return 0;


^ permalink raw reply

* [PATCH 1/6] show-diff.c: clean up private buffer use.
From: Junio C Hamano @ 2005-04-18 20:33 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

[PATCH 1/6] show-diff.c: clean up private buffer use.

This patch fixes sq_expand() and show_differences() not to use and
hold onto its privately allocated buffer, which was a misguided
attempt to reduce calls to malloc but made later changes harder.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

 show-diff.c |   22 ++++++----------------
 1 files changed, 6 insertions(+), 16 deletions(-)

show-diff.c: 1342b3c9848a7675665594a6bc19d95e3b7ff358
--- a/show-diff.c
+++ b/show-diff.c
@@ -23,7 +23,6 @@ static char *diff_cmd = "diff -L '%s' -u
 static char *sq_expand(char *src)
 {
 	static char *buf = NULL;
-	static int buf_size = -1;
 	int cnt, c;
 	char *cp;
 
@@ -32,12 +31,8 @@ static char *sq_expand(char *src)
 		if (*cp == '\'')
 			cnt += 3;
 
-	if (buf_size < cnt) {
-		free(buf);
-		buf_size = cnt;
-		buf = malloc(cnt);
-	}
-
+	if (! (buf = malloc(cnt)))
+	    return buf;
 	cp = buf;
 	while ((c = *src++)) {
 		if (c != '\'')
@@ -55,22 +50,17 @@ static void show_differences(char *name,
 			     unsigned long long old_size)
 {
 	FILE *f;
-	static char *cmd = NULL;
-	static int cmd_size = -1;
-
 	char *name_sq = sq_expand(name);
-	int cmd_required_length = strlen(name_sq) * 2 + strlen(diff_cmd);
+	int cmd_size = strlen(name_sq) * 2 + strlen(diff_cmd);
+	char *cmd = malloc(cmd_size);
 
-	if (cmd_size < cmd_required_length) {
-		free(cmd);
-		cmd_size = cmd_required_length;
-		cmd = malloc(cmd_required_length);
-	}
 	snprintf(cmd, cmd_size, diff_cmd, name_sq, name_sq);
 	f = popen(cmd, "w");
 	if (old_size)
 		fwrite(old_contents, old_size, 1, f);
 	pclose(f);
+	free(name_sq);
+	free(cmd);
 }
 
 static void show_diff_empty(struct cache_entry *ce)


^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox