# [PATCH] make file merging respect permissions

14 messages from 2005-04-23 to 2005-04-24. Participants: James Bottomley, Linus Torvalds, Petr Baudis, Andreas Gal.
Thread: https://gitlist.dev/t/265

## James Bottomley, 2005-04-23 18:22

Subject: [PATCH] make file merging respect permissions
Message-ID: <1114280570.5068.5.camel@mulgrave>
URL: https://gitlist.dev/e/1114280570.5068.5.camel%40mulgrave

```
I noticed when playing about with merging that executable scripts lose
their permissions after a merge.  This was because unpack-file just
unpacks to whatever the current umask is.

I also noticed that the merge-one-file-script thinks that if the file
has been removed in both branches, then it should simply be removed.
This isn't correct.  The file could have been renamed to something
different in both branches, in which case we have an unflagged rename
conflict.

The attached fixes both issues

James

--- a/git-merge-one-file-script
+++ b/git-merge-one-file-script
@@ -20,23 +20,47 @@ mkdir -p "$dir"
 
 case "${1:-.}${2:-.}${3:-.}" in
 #
-# deleted in both, or deleted in one and unchanged in the other
+# deleted in both
+#
+"$1..")
+	echo "ERROR: $4 is removed in both branches"
+	echo "ERROR: This is a potential rename conflict"
+	exit 1;;
+#
+# deleted in one and unchanged in the other
 #
 "$1.." | "$1.$1" | "$1$1.")
 	rm -f -- "$4"
+	echo "Removing $4"
 	update-cache --remove -- "$4"
 	exit 0
 	;;
 
 #
-# added in one, or added identically in both
+# added in one
 #
-".$2." | "..$3" | ".$2$2")
-	mv $(unpack-file "${2:-$3}") $4
+".$2." | "..$3" )
+	echo "Adding $4 with perm $6$7"
+	mv $(unpack-file "$2$3") $4
+	chmod "$6$7" $4
 	update-cache --add -- $4
 	exit 0
 	;;
-
+#
+# Added in both (check for same permissions)
+#
+".$2$2")
+	if [ "$6" != "$7" ]; then
+		echo "ERROR:"
+		echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
+		echo "ERROR:"
+		exit 1
+	fi
+	echo "Adding $4 with perm $6"
+	mv $(unpack-file "$2") $4
+	chmod "$6" $4
+	update-cache --add -- $4
+	exit 0;;
 #
 # Modified in both, but differently ;(
 #
@@ -46,12 +70,21 @@ case "${1:-.}${2:-.}${3:-.}" in
 	src1=$(unpack-file $2)
 	src2=$(unpack-file $3)
 	merge "$src2" "$orig" "$src1"
-	if [ $? -ne 0 ]; then
-		echo Leaving conflict merge in $src2
+	ret=$?
+	if [ "$6" != "$7" ]; then
+		echo "ERROR: Permissions $5->$6->$7" don't match merging $src2"
+		if [ $ret -ne 0 ]; then
+			echo "ERROR: Leaving conflict merge in $src2"
+		fi
+		exit 1
+	fi
+	chmod -- "$6" "$src2"
+	if [ $ -ne 0 ]; then
+		echo "ERROR: Leaving conflict merge in $src2"
 		exit 1
 	fi
-	cp "$src2" "$4" && update-cache --add -- "$4" && exit 0
+	cp -- "$src2" "$4" && chmod -- "$6" "$4" &&  update-cache --add -- "$4" && exit 0
 	;;
 
 *)
--- a/merge-cache.c
+++ b/merge-cache.c
@@ -4,7 +4,7 @@
 #include "cache.h"
 
 static const char *pgm = NULL;
-static const char *arguments[5];
+static const char *arguments[8];
 
 static void run_program(void)
 {
@@ -18,6 +18,9 @@ static void run_program(void)
 			    arguments[2],
 			    arguments[3],
 			    arguments[4],
+			    arguments[5],
+			    arguments[6],
+			    arguments[7],
 			    NULL);
 		die("unable to execute '%s'", pgm);
 	}
@@ -36,9 +39,13 @@ static int merge_entry(int pos, const ch
 	arguments[2] = "";
 	arguments[3] = "";
 	arguments[4] = path;
+	arguments[5] = "";
+	arguments[6] = "";
+	arguments[7] = "";
 	found = 0;
 	do {
 		static char hexbuf[4][60];
+		static char ownbuf[4][60];
 		struct cache_entry *ce = active_cache[pos];
 		int stage = ce_stage(ce);
 
@@ -46,7 +53,9 @@ static int merge_entry(int pos, const ch
 			break;
 		found++;
 		strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
+		sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
 		arguments[stage] = hexbuf[stage];
+		arguments[stage + 4] = ownbuf[stage];
 	} while (++pos < active_nr);
 	if (!found)
 		die("merge-cache: %s not in the cache", path);



```

## Linus Torvalds, 2005-04-23 20:17

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <Pine.LNX.4.58.0504231311300.2344@ppc970.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0504231311300.2344%40ppc970.osdl.org
In-Reply-To: <1114280570.5068.5.camel@mulgrave>

```


On Sat, 23 Apr 2005, James Bottomley wrote:
>
> The attached fixes both issues

The attached patch was seriously corrupt. Did you edit it by hand? The 
second chunk of the git-merge-one-file-script patch claims to have 12 
source lines, but only has 11, causing patch no end of confusion.

I fixed up the line counts by hand, and the end result looked almost sane,
but when looking closer, I noticed the

	+       if [ $ -ne 0 ]; then
	+               echo "ERROR: Leaving conflict merge in $src2"
	                exit 1

which just can't be right either ("$" never equals 0, so the above will 
always report an error), so I assume that whatever editing you did was 
really quite corrupt. Yeah, yeah, you obviously meant "$?", but the fact 
is, your patch is bogus, and I don't trust it. Can you re-send a valid one 
(and sign off on it).

		Linus

```

## James Bottomley, 2005-04-23 20:37

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114288622.5228.1.camel@mulgrave>
URL: https://gitlist.dev/e/1114288622.5228.1.camel%40mulgrave
In-Reply-To: <Pine.LNX.4.58.0504231311300.2344@ppc970.osdl.org>

```
On Sat, 2005-04-23 at 13:17 -0700, Linus Torvalds wrote:
> The attached patch was seriously corrupt. Did you edit it by hand? The 
> second chunk of the git-merge-one-file-script patch claims to have 12 
> source lines, but only has 11, causing patch no end of confusion.

OK ... yes I admit it ... the shame ... I noticed a problem after I
generated it and then edited it in source

> I fixed up the line counts by hand, and the end result looked almost sane,
> but when looking closer, I noticed the
> 
> 	+       if [ $ -ne 0 ]; then
> 	+               echo "ERROR: Leaving conflict merge in $src2"
> 	                exit 1
> 
> which just can't be right either ("$" never equals 0, so the above will 
> always report an error), so I assume that whatever editing you did was 
> really quite corrupt. Yeah, yeah, you obviously meant "$?", but the fact 
> is, your patch is bogus, and I don't trust it. Can you re-send a valid one 
> (and sign off on it).

Yes boss ... Just getting on a 'plane now.  Should be able to send it
out in an hour or so.

James



```

## James Bottomley, 2005-04-23 21:44

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114292680.4799.4.camel@mulgrave>
URL: https://gitlist.dev/e/1114292680.4799.4.camel%40mulgrave
In-Reply-To: <Pine.LNX.4.58.0504231311300.2344@ppc970.osdl.org>

```
On Sat, 2005-04-23 at 13:17 -0700, Linus Torvalds wrote:
> Yeah, yeah, you obviously meant "$?", but the fact 
> is, your patch is bogus, and I don't trust it. Can you re-send a valid
> one 
> (and sign off on it).]

OK, here it is  .. I have an excuse, honest ... and a note from my mum.

---

This patch fixes two problems

1) permissions aren't respected in the merge script (primarily because
they're never passed in to it in the first place).  Fix that and also
check for permission conflicts in the merge

2) the delete of a file in both branches may indeed be just that, but it
could also be the indicator of a rename conflict (file moved to
different locations in both branches), so error out and ask the
committer for guidance.

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

--- a/git-merge-one-file-script
+++ b/git-merge-one-file-script
@@ -20,23 +20,47 @@ mkdir -p "$dir"
 
 case "${1:-.}${2:-.}${3:-.}" in
 #
-# deleted in both, or deleted in one and unchanged in the other
+# deleted in both
+#
+"$1..")
+	echo "ERROR: $4 is removed in both branches"
+	echo "ERROR: This is a potential rename conflict"
+	exit 1;;
+#
+# deleted in one and unchanged in the other
 #
 "$1.." | "$1.$1" | "$1$1.")
 	rm -f -- "$4"
+	echo "Removing $4"
 	update-cache --remove -- "$4"
 	exit 0
 	;;
 
 #
-# added in one, or added identically in both
+# added in one
 #
-".$2." | "..$3" | ".$2$2")
-	mv $(unpack-file "${2:-$3}") $4
+".$2." | "..$3" )
+	echo "Adding $4 with perm $6$7"
+	mv $(unpack-file "$2$3") $4
+	chmod "$6$7" $4
 	update-cache --add -- $4
 	exit 0
 	;;
-
+#
+# Added in both (check for same permissions)
+#
+".$2$2")
+	if [ "$6" != "$7" ]; then
+		echo "ERROR:"
+		echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
+		echo "ERROR:"
+		exit 1
+	fi
+	echo "Adding $4 with perm $6"
+	mv $(unpack-file "$2") $4
+	chmod "$6" $4
+	update-cache --add -- $4
+	exit 0;;
 #
 # Modified in both, but differently ;(
 #
@@ -46,12 +70,21 @@ case "${1:-.}${2:-.}${3:-.}" in
 	src1=$(unpack-file $2)
 	src2=$(unpack-file $3)
 	merge "$src2" "$orig" "$src1"
-	if [ $? -ne 0 ]; then
-		echo Leaving conflict merge in $src2
+	ret=$?
+	if [ "$6" != "$7" ]; then
+		echo "ERROR: Permissions $5->$6->$7 don't match merging $src2"
+		if [ $ret -ne 0 ]; then
+			echo "ERROR: Leaving conflict merge in $src2"
+		fi
+		exit 1
+	fi
+	chmod -- "$6" "$src2"
+	if [ $ -ne 0 ]; then
+		echo "ERROR: Leaving conflict merge in $src2"
 		exit 1
 	fi
-	cp "$src2" "$4" && update-cache --add -- "$4" && exit 0
+	cp -- "$src2" "$4" && chmod -- "$6" "$4" &&  update-cache --add -- "$4" && exit 0
 	;;
 
 *)
--- a/merge-cache.c
+++ b/merge-cache.c
@@ -4,7 +4,7 @@
 #include "cache.h"
 
 static const char *pgm = NULL;
-static const char *arguments[5];
+static const char *arguments[8];
 
 static void run_program(void)
 {
@@ -18,6 +18,9 @@ static void run_program(void)
 			    arguments[2],
 			    arguments[3],
 			    arguments[4],
+			    arguments[5],
+			    arguments[6],
+			    arguments[7],
 			    NULL);
 		die("unable to execute '%s'", pgm);
 	}
@@ -36,9 +39,13 @@ static int merge_entry(int pos, const ch
 	arguments[2] = "";
 	arguments[3] = "";
 	arguments[4] = path;
+	arguments[5] = "";
+	arguments[6] = "";
+	arguments[7] = "";
 	found = 0;
 	do {
 		static char hexbuf[4][60];
+		static char ownbuf[4][60];
 		struct cache_entry *ce = active_cache[pos];
 		int stage = ce_stage(ce);
 
@@ -46,7 +53,9 @@ static int merge_entry(int pos, const ch
 			break;
 		found++;
 		strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
+		sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
 		arguments[stage] = hexbuf[stage];
+		arguments[stage + 4] = ownbuf[stage];
 	} while (++pos < active_nr);
 	if (!found)
 		die("merge-cache: %s not in the cache", path);



```

## Petr Baudis, 2005-04-23 23:02

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <20050423230238.GD13222@pasky.ji.cz>
URL: https://gitlist.dev/e/20050423230238.GD13222%40pasky.ji.cz
In-Reply-To: <1114292680.4799.4.camel@mulgrave>

```
Dear diary, on Sat, Apr 23, 2005 at 11:44:40PM CEST, I got a letter
where James Bottomley <James.Bottomley@SteelEye.com> told me that...
> On Sat, 2005-04-23 at 13:17 -0700, Linus Torvalds wrote:
> > Yeah, yeah, you obviously meant "$?", but the fact 
> > is, your patch is bogus, and I don't trust it. Can you re-send a valid
> > one 
> > (and sign off on it).]
> 
> OK, here it is  .. I have an excuse, honest ... and a note from my mum.
> 
> +	ret=$?
> +	if [ "$6" != "$7" ]; then
> +		echo "ERROR: Permissions $5->$6->$7 don't match merging $src2"
> +		if [ $ret -ne 0 ]; then
> +			echo "ERROR: Leaving conflict merge in $src2"
> +		fi
> +		exit 1
> +	fi
> +	chmod -- "$6" "$src2"
> +	if [ $ -ne 0 ]; then

*cough*

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

```

## James Bottomley, 2005-04-23 23:09

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114297749.5264.3.camel@mulgrave>
URL: https://gitlist.dev/e/1114297749.5264.3.camel%40mulgrave
In-Reply-To: <20050423230238.GD13222@pasky.ji.cz>

```
On Sun, 2005-04-24 at 01:02 +0200, Petr Baudis wrote:
> > +	if [ $ -ne 0 ]; then
> 
> *cough*

You're kidding me?

Well ... it's correct in my repository ... I'll investigate my diff
script

James



```

## James Bottomley, 2005-04-23 23:21

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114298490.5264.10.camel@mulgrave>
URL: https://gitlist.dev/e/1114298490.5264.10.camel%40mulgrave
In-Reply-To: <20050423230238.GD13222@pasky.ji.cz>

```
On Sun, 2005-04-24 at 01:02 +0200, Petr Baudis wrote:
> *cough*

OK, dirty file in the local tree, sorry.

This is the actual diff

---

1) permissions aren't respected in the merge script (primarily because
they're never passed in to it in the first place).  Fix that and also
check for permission conflicts in the merge

2) the delete of a file in both branches may indeed be just that, but it
could also be the indicator of a rename conflict (file moved to
different locations in both branches), so error out and ask the
committer for guidance.

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

--- a/git-merge-one-file-script
+++ b/git-merge-one-file-script
@@ -20,23 +20,45 @@ mkdir -p "$dir"
 
 case "${1:-.}${2:-.}${3:-.}" in
 #
-# deleted in both, or deleted in one and unchanged in the other
+# deleted in both
+#
+"$1..")
+	echo "ERROR: $4 is removed in both branches"
+	echo "ERROR: This is a potential rename conflict"
+	exit 1;;
+#
+# deleted in one and unchanged in the other
 #
 "$1.." | "$1.$1" | "$1$1.")
 	rm -f -- "$4"
+	echo "Removing $4"
 	update-cache --remove -- "$4"
 	exit 0
 	;;
 
 #
-# added in one, or added identically in both
+# added in one
 #
-".$2." | "..$3" | ".$2$2")
-	mv $(unpack-file "${2:-$3}") $4
+".$2." | "..$3" )
+	echo "Adding $4 with perm $6$7"
+	mv $(unpack-file "$2$3") $4
+	chmod "$6$7" $4
 	update-cache --add -- $4
 	exit 0
 	;;
-
+#
+# Added in both (check for same permissions)
+#
+".$2$2")
+	if [ "$6" != "$7" ]; then
+		echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
+		exit 1
+	fi
+	echo "Adding $4 with perm $6"
+	mv $(unpack-file "$2") $4
+	chmod "$6" $4
+	update-cache --add -- $4
+	exit 0;;
 #
 # Modified in both, but differently ;(
 #
@@ -46,12 +68,21 @@ case "${1:-.}${2:-.}${3:-.}" in
 	src1=$(unpack-file $2)
 	src2=$(unpack-file $3)
 	merge "$src2" "$orig" "$src1"
-	if [ $? -ne 0 ]; then
-		echo Leaving conflict merge in $src2
+	ret=$?
+	if [ "$6" != "$7" ]; then
+		echo "ERROR: Permissions $5->$6->$7 don't match merging $src2"
+		if [ $ret -ne 0 ]; then
+			echo "ERROR: Leaving conflict merge in $src2"
+		fi
+		exit 1
+	fi
+	chmod -- "$6" "$src2"
+	if [ $ret -ne 0 ]; then
+		echo "ERROR: Leaving conflict merge in $src2"
 		exit 1
 	fi
-	cp "$src2" "$4" && update-cache --add -- "$4" && exit 0
+	cp -- "$src2" "$4" && chmod -- "$6" "$4" &&  update-cache --add -- "$4" && exit 0
 	;;
 
 *)
--- a/merge-cache.c
+++ b/merge-cache.c
@@ -4,7 +4,7 @@
 #include "cache.h"
 
 static const char *pgm = NULL;
-static const char *arguments[5];
+static const char *arguments[8];
 
 static void run_program(void)
 {
@@ -18,6 +18,9 @@ static void run_program(void)
 			    arguments[2],
 			    arguments[3],
 			    arguments[4],
+			    arguments[5],
+			    arguments[6],
+			    arguments[7],
 			    NULL);
 		die("unable to execute '%s'", pgm);
 	}
@@ -36,9 +39,13 @@ static int merge_entry(int pos, const ch
 	arguments[2] = "";
 	arguments[3] = "";
 	arguments[4] = path;
+	arguments[5] = "";
+	arguments[6] = "";
+	arguments[7] = "";
 	found = 0;
 	do {
 		static char hexbuf[4][60];
+		static char ownbuf[4][60];
 		struct cache_entry *ce = active_cache[pos];
 		int stage = ce_stage(ce);
 
@@ -46,7 +53,9 @@ static int merge_entry(int pos, const ch
 			break;
 		found++;
 		strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
+		sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
 		arguments[stage] = hexbuf[stage];
+		arguments[stage + 4] = ownbuf[stage];
 	} while (++pos < active_nr);
 	if (!found)
 		die("merge-cache: %s not in the cache", path);



```

## Linus Torvalds, 2005-04-24 01:01

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <Pine.LNX.4.58.0504231759010.2344@ppc970.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0504231759010.2344%40ppc970.osdl.org
In-Reply-To: <1114298490.5264.10.camel@mulgrave>

```


On Sat, 23 Apr 2005, James Bottomley wrote:
> 
> This is the actual diff

This is _still_ corrupted. 

Are you editing your diffs by hand without understanding how the diffs 
work?

The second chunk of the "git-merge-one-file" diff _still_ claims to change 
twelve lines, and that diff _still_ only changes eleven lines. My "patch" 
isn't happy, and I can count the lines in the diff myself and verify that 
it's not patch that is wrong, it's your diff.

Please please _please_ don't edit diffs by hand if you don't know what 
you're doing. Generate the diff from a clean source instead. Or ask me to 
fix it up, I'm so used to editing diffs that I can do it in my sleep.

		Linus

```

## James Bottomley, 2005-04-24 04:42

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114317771.4980.7.camel@mulgrave>
URL: https://gitlist.dev/e/1114317771.4980.7.camel%40mulgrave
In-Reply-To: <Pine.LNX.4.58.0504231759010.2344@ppc970.osdl.org>

```
On Sat, 2005-04-23 at 18:01 -0700, Linus Torvalds wrote:
> 
> On Sat, 23 Apr 2005, James Bottomley wrote:
> > 
> > This is the actual diff
> 
> This is _still_ corrupted. 
> 
> Are you editing your diffs by hand without understanding how the diffs 
> work?

Sort of: I'm taking a diff between my tree and yours but stripping out
the extraneous pieces (which are whole file diffs, nothing in the actual
diffs I send you).

> The second chunk of the "git-merge-one-file" diff _still_ claims to change 
> twelve lines, and that diff _still_ only changes eleven lines. My "patch" 
> isn't happy, and I can count the lines in the diff myself and verify that 
> it's not patch that is wrong, it's your diff.
> 
> Please please _please_ don't edit diffs by hand if you don't know what 
> you're doing. Generate the diff from a clean source instead. Or ask me to 
> fix it up, I'm so used to editing diffs that I can do it in my sleep.

OK ... this is done by reapplying to the top of your git tree and then
doing a show-diff.  I've checked that it actually applies without
rejections to a pristine git tree.

James

git-merge-one-file-script: b2adc5fc4583e6089f4b38a47e1a73caad183f20
--- a/git-merge-one-file-script
+++ b/git-merge-one-file-script
@@ -20,23 +20,45 @@ mkdir -p "$dir"
 
 case "${1:-.}${2:-.}${3:-.}" in
 #
-# deleted in both, or deleted in one and unchanged in the other
+# deleted in both
+#
+"$1..")
+	echo "ERROR: $4 is removed in both branches"
+	echo "ERROR: This is a potential rename conflict"
+	exit 1;;
+#
+# deleted in one and unchanged in the other
 #
 "$1.." | "$1.$1" | "$1$1.")
 	rm -f -- "$4"
+	echo "Removing $4"
 	update-cache --remove -- "$4"
 	exit 0
 	;;
 
 #
-# added in one, or added identically in both
+# added in one
 #
-".$2." | "..$3" | ".$2$2")
-	mv $(unpack-file "${2:-$3}") $4
+".$2." | "..$3" )
+	echo "Adding $4 with perm $6$7"
+	mv $(unpack-file "$2$3") $4
+	chmod "$6$7" $4
 	update-cache --add -- $4
 	exit 0
 	;;
-
+#
+# Added in both (check for same permissions)
+#
+".$2$2")
+	if [ "$6" != "$7" ]; then
+		echo "ERROR: File $4 added in both branches, permissions conflict $6->$7"
+		exit 1
+	fi
+	echo "Adding $4 with perm $6"
+	mv $(unpack-file "$2") $4
+	chmod "$6" $4
+	update-cache --add -- $4
+	exit 0;;
 #
 # Modified in both, but differently ;(
 #
@@ -46,11 +68,20 @@ case "${1:-.}${2:-.}${3:-.}" in
 	src1=$(unpack-file $2)
 	src2=$(unpack-file $3)
 	merge "$src2" "$orig" "$src1"
-	if [ $? -ne 0 ]; then
-		echo Leaving conflict merge in $src2
+	ret=$?
+	if [ "$6" != "$7" ]; then
+		echo "ERROR: Permissions $5->$6->$7 don't match merging $src2"
+		if [ $ret -ne 0 ]; then
+			echo "ERROR: Leaving conflict merge in $src2"
+		fi
+		exit 1
+	fi
+	chmod -- "$6" "$src2"
+	if [ $ret -ne 0 ]; then
+		echo "ERROR: Leaving conflict merge in $src2"
 		exit 1
 	fi
-	cp "$src2" "$4" && update-cache --add -- "$4" && exit 0
+	cp -- "$src2" "$4" && chmod -- "$6" "$4" &&  update-cache --add -- "$4" && exit 0
 	;;
 
 *)
merge-cache.c: 68ac4ab2d926005a5a729017c1bcb70a30634bd8
--- a/merge-cache.c
+++ b/merge-cache.c
@@ -4,7 +4,7 @@
 #include "cache.h"
 
 static const char *pgm = NULL;
-static const char *arguments[5];
+static const char *arguments[8];
 
 static void run_program(void)
 {
@@ -18,6 +18,9 @@ static void run_program(void)
 			    arguments[2],
 			    arguments[3],
 			    arguments[4],
+			    arguments[5],
+			    arguments[6],
+			    arguments[7],
 			    NULL);
 		die("unable to execute '%s'", pgm);
 	}
@@ -36,9 +39,13 @@ static int merge_entry(int pos, const ch
 	arguments[2] = "";
 	arguments[3] = "";
 	arguments[4] = path;
+	arguments[5] = "";
+	arguments[6] = "";
+	arguments[7] = "";
 	found = 0;
 	do {
 		static char hexbuf[4][60];
+		static char ownbuf[4][60];
 		struct cache_entry *ce = active_cache[pos];
 		int stage = ce_stage(ce);
 
@@ -46,7 +53,9 @@ static int merge_entry(int pos, const ch
 			break;
 		found++;
 		strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
+		sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode) & (~S_IFMT));
 		arguments[stage] = hexbuf[stage];
+		arguments[stage + 4] = ownbuf[stage];
 	} while (++pos < active_nr);
 	if (!found)
 		die("merge-cache: %s not in the cache", path);



```

## Linus Torvalds, 2005-04-24 04:55

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <Pine.LNX.4.58.0504232153500.15879@ppc970.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0504232153500.15879%40ppc970.osdl.org
In-Reply-To: <1114317771.4980.7.camel@mulgrave>

```


On Sat, 23 Apr 2005, James Bottomley wrote:
> 
> OK ... this is done by reapplying to the top of your git tree and then
> doing a show-diff.  I've checked that it actually applies without
> rejections to a pristine git tree.

Well, I actually ended up editing the line numbers manually and already 
pushed out the previous one, so you might want to double-check that my 
current tree matches yours.

		Linus

```

## James Bottomley, 2005-04-24 05:03

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114318981.4980.14.camel@mulgrave>
URL: https://gitlist.dev/e/1114318981.4980.14.camel%40mulgrave
In-Reply-To: <Pine.LNX.4.58.0504232153500.15879@ppc970.osdl.org>

```
On Sat, 2005-04-23 at 21:55 -0700, Linus Torvalds wrote:
> Well, I actually ended up editing the line numbers manually and already 
> pushed out the previous one, so you might want to double-check that my 
> current tree matches yours.

Yes, the sha1 of my changed file and the one you merged match, so
everything looks sane.

Sorry for the confusion,

James



```

## Andreas Gal, 2005-04-24 05:05

Subject: [PATH] fix segfault in fsck-cache
Message-ID: <Pine.LNX.4.58.0504232202380.7195@sam.ics.uci.edu>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0504232202380.7195%40sam.ics.uci.edu
In-Reply-To: <Pine.LNX.4.58.0504232153500.15879@ppc970.osdl.org>

```

I somehow got some corrupted object files in my repository that zlib 
refuses to decompress. This patch makes sure we abort early before the 
memcpy a few lines downtream segfaults (due to total_out == 0).

Andreas

Signed-off-by: Andreas Gal <gal@uci.edu>

--- 66308ede85c2dad6b184fb74a7215b06a173d8f7/sha1_file.c
+++ sha1_file.c
@@ -155,6 +155,8 @@
 
 	inflateInit(&stream);
 	ret = inflate(&stream, 0);
+	if (ret != Z_OK)
+		return NULL;
 	if (sscanf(buffer, "%10s %lu", type, size) != 2)
 		return NULL;
 


```

## Andreas Gal, 2005-04-24 05:24

Subject: Re: [PATH] fix segfault in fsck-cache
Message-ID: <Pine.LNX.4.58.0504232223570.8755@sam.ics.uci.edu>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0504232223570.8755%40sam.ics.uci.edu
In-Reply-To: <Pine.LNX.4.58.0504232202380.7195@sam.ics.uci.edu>

```

This isn't working right either, depending on your ZLIB version. Do not 
apply. 

Andreas

On Sat, 23 Apr 2005, Andreas Gal wrote:

> 
> I somehow got some corrupted object files in my repository that zlib 
> refuses to decompress. This patch makes sure we abort early before the 
> memcpy a few lines downtream segfaults (due to total_out == 0).
> 
> Andreas
> 
> Signed-off-by: Andreas Gal <gal@uci.edu>
> 
> --- 66308ede85c2dad6b184fb74a7215b06a173d8f7/sha1_file.c
> +++ sha1_file.c
> @@ -155,6 +155,8 @@
>  
>  	inflateInit(&stream);
>  	ret = inflate(&stream, 0);
> +	if (ret != Z_OK)
> +		return NULL;
>  	if (sscanf(buffer, "%10s %lu", type, size) != 2)
>  		return NULL;
>  
> 
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

```

## James Bottomley, 2005-04-24 12:46

Subject: Re: [PATCH] make file merging respect permissions
Message-ID: <1114346767.4997.2.camel@mulgrave>
URL: https://gitlist.dev/e/1114346767.4997.2.camel%40mulgrave
In-Reply-To: <Pine.LNX.4.58.0504232153500.15879@ppc970.osdl.org>

```
On Sat, 2005-04-23 at 21:55 -0700, Linus Torvalds wrote:
> Well, I actually ended up editing the line numbers manually and already 
> pushed out the previous one, so you might want to double-check that my 
> current tree matches yours.

Just to get closure on this, I went over all the parts of patch
generation, and the culprit turns out to be emacs.  Apparently its diff
mode (which I never thought to investigate how to use) does these re-
writes ... no idea why, but the problem goes away if I strip out the
extraneous pieces in fundamental-mode.  It's never given me this trouble
before ... I think the diff I'm producing must be confusing it somehow.

James



```
