Skip to contentSkip to conversation

Add + Status patches

PATCH In review David Greaves 3 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

README (mode:100644 sha1:4282af1604e429dd767fe721751b5ac4a87c410e) renamed from README (mode:100644 sha1:798476ad292cc6edf5a2f5782e1de82f6052abe2) +4 -0
Index: README
===================================================================
@@ -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
 
git (mode:100755 sha1:5f3d4d04a0adfdc26bfc6aaef5cd29eea6e5c459) renamed from git (mode:100755 sha1:b648169640025bd68d1b27a0fcc85b65d85e4440) +1 -1
Index: git
===================================================================
@@ -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
gitadd.sh (mode:100755 sha1:d010d14c0c14e0ea7a2e448b667d938fe92a3bc2) renamed from gitadd.sh (mode:100755 sha1:3ed93ea0fcb995673ba9ee1982e0e7abdbe35982) +8 -4
Index: gitadd.sh
===================================================================
@@ -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
gitstatus.sh (mode:100755 sha1:e2c7f9d56b6967c529453de675ffffaaeeff3d1c) renamed from gitstatus.sh (mode:100755 sha1:6c33f805ebc2630b14a88a07dfc891a9196d66a5) +2 -2
Index: gitstatus.sh
===================================================================
@@ -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);
#1 lore raw

Dear diary, on Mon, Apr 18, 2005 at 10:39:00PM CEST, I got a letter where David Greaves <[email protected]> told me that...

Quoted 1 line

Hi Petr

Hi,

Quoted 9 lines

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,

Signature · 3 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
#2 lore raw

PATCH 1/1 add, rm + status patches

Quoted 2 lines · Petr Baudis

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.

Quoted 7 lines

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

---

README (mode:100644 sha1:4282af1604e429dd767fe721751b5ac4a87c410e) renamed from README (mode:100644 sha1:798476ad292cc6edf5a2f5782e1de82f6052abe2) +0 -0
Index: README
===================================================================
@@ -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

git (mode:100755 sha1:2549bc3dc36ec00e747e91edb6e839be0f37ae4a) renamed from git (mode:100755 sha1:b648169640025bd68d1b27a0fcc85b65d85e4440) +0 -0
Index: git
===================================================================
@@ -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]

gitadd.sh (mode:100755 sha1:a3e83ac52abd5a9cdc6abd560f95b2f19646fd99) renamed from gitadd.sh (mode:100755 sha1:3ed93ea0fcb995673ba9ee1982e0e7abdbe35982) +0 -0
Index: gitadd.sh
===================================================================
@@ -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

gitrm.sh (mode:100755 sha1:d76542dd6ad892fbbdc93e475aa9b77dd2922fe5) renamed from gitrm.sh (mode:100755 sha1:5c18c38a890c9fd9ad2b866ee7b529539d2f3f8f) +0 -0
Index: gitrm.sh
===================================================================
@@ -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

gitstatus.sh (mode:100755 sha1:2611d00189e5d03ba8356ec0e4c3af107bae6981) renamed from gitstatus.sh (mode:100755 sha1:6c33f805ebc2630b14a88a07dfc891a9196d66a5) +0 -0
Index: gitstatus.sh
===================================================================
@@ -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);

#3 lore raw

Re: [PATCH 1/1] add, rm + status patches

Dear diary, on Tue, Apr 19, 2005 at 12:18:07AM CEST, I got a letter where David Greaves <[email protected]> told me that...

Quoted 6 lines
Quoted 2 lines · Petr Baudis

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.

Yes. The patch you inserted is useless, whitespaces are mangled away.

Quoted 14 lines
Quoted 6 lines

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

Quoted 2 lines

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

Well, I didn't ask you to split the patch the first time since it was quite trivial for me to do, but this is too much. ;-)

Quoted 5 lines

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.

I'm fine with Perl. I chose shell for the very initial implementation since it actually was simplest, but now, I wouldn't have anything against Perl if it makes is simpler. (And as long as your Perl is nice. I'm harsh reviewer. ;-)

Quoted 7 lines

Index: gitadd.sh
===================================================================
--- c0aff9b98c4242ab8965c428241df1d8f7a1d4bb/gitadd.sh (mode:100755 sha1:3ed93ea0fcb995673ba9ee1982e0e7abdbe35982)
+++ cd5cd7a9272ce1966aca3bfce15f703e33cafc04/gitadd.sh (mode:100755 sha1:a3e83ac52abd5a9cdc6abd560f95b2f19646fd99)
\ No newline at end of file

Note this. Something is wrong with your text editor, too.

Kind regards,

Signature · 3 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
#4 lore raw
In reply to David Greaves
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"DG" == David Greaves <[email protected]> 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?

#5 lore raw
Quoted 7 lines · Junio C Hamano

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

#6 lore raw

Dear diary, on Tue, Apr 19, 2005 at 12:18:12AM CEST, I got a letter where David Greaves <[email protected]> told me that...

Quoted 9 lines
Quoted 7 lines · Junio C Hamano

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

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

Quoted 8 lines

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.

Actually, when I saw your patch, the xargs solution rushed through my mind but I thought that '-' might be practical too. Thinking about it, I couldn't come up with anything. So, what about instead making git add . to work? ;-)

Signature · 3 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
#7 lore raw
In reply to David Greaves
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"DG" == David Greaves <[email protected]> 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 ;-).