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

[patch pasky 1/2] fix various issues in gitapply.sh (basically did not handle add/del/cm at all)

From
MSMartin Schlemmer <azarah@nosferatu.za.org>
Date
Apr 15, 2005, 09:28 UTC
Message-ID
<1113557318.23299.165.camel@nosferatu.lan>
Hi,

The egrep regex should not escape the '{' and '}', and also add a check for ' \t' so that we do not pickup stuff like '+----', etc. Fix typo in assignment. Check if file exists in new tree before adding/removing (might add support for this lowlevel to increase speed?). Fix typo in line removing temp files.

Signed-off-by: Martin Schlemmer <azarah@gentoo.org>

gitapply.sh: 47b9346d2679b1bf34220fe4502f15c7d0737b0c --- 47b9346d2679b1bf34220fe4502f15c7d0737b0c/gitapply.sh +++ uncommitted/gitapply.sh

@@ -19,15 +19,22 @@
 # just handle it all ourselves.
 patch -p1 -N <$patchfifo &

-tee $patchfifo | egrep '^[+-]\{3\}' | {
+exits_in_cache() {
+       for x in $(ls-tree "$1"); do
+               [ "$x" = "$2" ] && return 0
+       done
+       return 1
+}
+
+tee $patchfifo | egrep '^[+-]{3}[ \t]' | {
        victim=
        origmode=

        while read sign file attrs; do
-               echo $sign $file $attrs ... >&2
+#              echo $sign $file $attrs ... >&2
                case $sign in
                "---")
-                       victim=file
+                       victim=$file
                        mode=$(echo $attrs | sed 's/.*mode:[0-7]*\([0-7]\{3\}\).*/\1/')
                        origmode=
                        [ "$mode" != "$attrs" ] && origmode=$mode
@@ -35,14 +42,19 @@
                "+++")
                        if [ "$file" = "/dev/null" ]; then
                                torm=$(echo "$victim" | sed 's/[^\/]*\///') #-p1
-                               echo -ne "rm\0$torm\0"
+                               tree=$(echo $attrs | sed 's/.*tree:\([0-9a-f]\{40\}\).*/\1/')
+                               exits_in_cache "$tree" "$torm" && echo -ne "rm\0$torm\0"
                                continue
                        elif [ "$victim" = "/dev/null" ]; then
-                               echo -ne "add\0$file\0"
+                               toadd=$(echo "$file" | sed 's/[^\/]*\///') #-p1
+                               tree=$(echo "$file" | sed -e 's/\([^\/]*\)\/.*/\1/')
+                               exits_in_cache "$tree" "$toadd" || echo -ne "add\0$toadd\0"
                        fi
                        mode=$(echo $attrs | sed 's/.*mode:[0-7]*\([0-7]\{3\}\).*/\1/')
                        if [ "$mode" ] && [ "$mode" != "$attrs" ] && [ "$origmode" != "$mode" ]; then
-                               echo -ne "cm\0$mode\0$file\0"
+                               tochmod=$(echo "$file" | sed 's/[^\/]*\///') #-p1
+                               # need a space else numbers gets converted
+                               echo -ne "cm\0 $mode\0$tochmod\0"
                        fi
                        ;;
                *)
@@ -74,4 +86,4 @@
 done
 ' padding

-rm $pathfifo $todo $gonefile
+rm $patchfifo $todo $gonefile
-- 
Martin Schlemmer



gitapply.sh:  47b9346d2679b1bf34220fe4502f15c7d0737b0c
--- 47b9346d2679b1bf34220fe4502f15c7d0737b0c/gitapply.sh
+++ uncommitted/gitapply.sh
@@ -19,15 +19,22 @@
 # just handle it all ourselves.
 patch -p1 -N <$patchfifo &
 
-tee $patchfifo | egrep '^[+-]\{3\}' | {
+exits_in_cache() {
+	for x in $(ls-tree "$1"); do
+		[ "$x" = "$2" ] && return 0
+	done
+	return 1
+}
+
+tee $patchfifo | egrep '^[+-]{3}[ \t]' | {
 	victim=
 	origmode=
 
 	while read sign file attrs; do
-		echo $sign $file $attrs ... >&2
+#		echo $sign $file $attrs ... >&2
 		case $sign in
 		"---")
-			victim=file
+			victim=$file
 			mode=$(echo $attrs | sed 's/.*mode:[0-7]*\([0-7]\{3\}\).*/\1/')
 			origmode=
 			[ "$mode" != "$attrs" ] && origmode=$mode
@@ -35,14 +42,19 @@
 		"+++")
 			if [ "$file" = "/dev/null" ]; then
 				torm=$(echo "$victim" | sed 's/[^\/]*\///') #-p1
-				echo -ne "rm\0$torm\0"
+				tree=$(echo $attrs | sed 's/.*tree:\([0-9a-f]\{40\}\).*/\1/')
+				exits_in_cache "$tree" "$torm" && echo -ne "rm\0$torm\0"
 				continue
 			elif [ "$victim" = "/dev/null" ]; then
-				echo -ne "add\0$file\0"
+				toadd=$(echo "$file" | sed 's/[^\/]*\///') #-p1
+				tree=$(echo "$file" | sed -e 's/\([^\/]*\)\/.*/\1/')
+				exits_in_cache "$tree" "$toadd" || echo -ne "add\0$toadd\0"
 			fi
 			mode=$(echo $attrs | sed 's/.*mode:[0-7]*\([0-7]\{3\}\).*/\1/')
 			if [ "$mode" ] && [ "$mode" != "$attrs" ] && [ "$origmode" != "$mode" ]; then
-				echo -ne "cm\0$mode\0$file\0"
+				tochmod=$(echo "$file" | sed 's/[^\/]*\///') #-p1
+				# need a space else numbers gets converted
+				echo -ne "cm\0 $mode\0$tochmod\0"
 			fi
 			;;
 		*)
@@ -74,4 +86,4 @@
 done
 ' padding
 
-rm $pathfifo $todo $gonefile
+rm $patchfifo $todo $gonefile
Next: Martin Schlemmer
Message 1 of 4 in “fix various issues in gitapply.sh (basically did not handle add/del/cm at all)”
  1. 1/2 fix various issues in gitapply.sh (basically did not handle add/del/cm at all)Martin Schlemmer, Apr 15, 2005
  2. Martin SchlemmerApr 15, 2005
  3. Petr BaudisApr 15, 2005
  4. Martin SchlemmerApr 15, 2005

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.