git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] make file merging respect permissions
@ 2005-04-23 18:22 James Bottomley
  2005-04-23 20:17 ` Linus Torvalds
  0 siblings, 1 reply; 14+ messages in thread
From: James Bottomley @ 2005-04-23 18:22 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

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);



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 18:22 [PATCH] make file merging respect permissions James Bottomley
@ 2005-04-23 20:17 ` Linus Torvalds
  2005-04-23 20:37   ` James Bottomley
  2005-04-23 21:44   ` James Bottomley
  0 siblings, 2 replies; 14+ messages in thread
From: Linus Torvalds @ 2005-04-23 20:17 UTC (permalink / raw)
  To: James Bottomley; +Cc: Git Mailing List



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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 20:17 ` Linus Torvalds
@ 2005-04-23 20:37   ` James Bottomley
  2005-04-23 21:44   ` James Bottomley
  1 sibling, 0 replies; 14+ messages in thread
From: James Bottomley @ 2005-04-23 20:37 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Git Mailing List

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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 20:17 ` Linus Torvalds
  2005-04-23 20:37   ` James Bottomley
@ 2005-04-23 21:44   ` James Bottomley
  2005-04-23 23:02     ` Petr Baudis
  1 sibling, 1 reply; 14+ messages in thread
From: James Bottomley @ 2005-04-23 21:44 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Git Mailing List

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);



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 21:44   ` James Bottomley
@ 2005-04-23 23:02     ` Petr Baudis
  2005-04-23 23:09       ` James Bottomley
  2005-04-23 23:21       ` James Bottomley
  0 siblings, 2 replies; 14+ messages in thread
From: Petr Baudis @ 2005-04-23 23:02 UTC (permalink / raw)
  To: James Bottomley; +Cc: Linus Torvalds, Git Mailing List

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 23:02     ` Petr Baudis
@ 2005-04-23 23:09       ` James Bottomley
  2005-04-23 23:21       ` James Bottomley
  1 sibling, 0 replies; 14+ messages in thread
From: James Bottomley @ 2005-04-23 23:09 UTC (permalink / raw)
  To: Petr Baudis; +Cc: Linus Torvalds, Git Mailing List

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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 23:02     ` Petr Baudis
  2005-04-23 23:09       ` James Bottomley
@ 2005-04-23 23:21       ` James Bottomley
  2005-04-24  1:01         ` Linus Torvalds
  1 sibling, 1 reply; 14+ messages in thread
From: James Bottomley @ 2005-04-23 23:21 UTC (permalink / raw)
  To: Petr Baudis; +Cc: Linus Torvalds, Git Mailing List

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);



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-23 23:21       ` James Bottomley
@ 2005-04-24  1:01         ` Linus Torvalds
  2005-04-24  4:42           ` James Bottomley
  0 siblings, 1 reply; 14+ messages in thread
From: Linus Torvalds @ 2005-04-24  1:01 UTC (permalink / raw)
  To: James Bottomley; +Cc: Petr Baudis, Git Mailing List



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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-24  1:01         ` Linus Torvalds
@ 2005-04-24  4:42           ` James Bottomley
  2005-04-24  4:55             ` Linus Torvalds
  0 siblings, 1 reply; 14+ messages in thread
From: James Bottomley @ 2005-04-24  4:42 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Petr Baudis, Git Mailing List

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);



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-24  4:42           ` James Bottomley
@ 2005-04-24  4:55             ` Linus Torvalds
  2005-04-24  5:03               ` James Bottomley
                                 ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Linus Torvalds @ 2005-04-24  4:55 UTC (permalink / raw)
  To: James Bottomley; +Cc: Petr Baudis, Git Mailing List



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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-24  4:55             ` Linus Torvalds
@ 2005-04-24  5:03               ` James Bottomley
  2005-04-24  5:05               ` [PATH] fix segfault in fsck-cache Andreas Gal
  2005-04-24 12:46               ` [PATCH] make file merging respect permissions James Bottomley
  2 siblings, 0 replies; 14+ messages in thread
From: James Bottomley @ 2005-04-24  5:03 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Petr Baudis, Git Mailing List

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



^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATH] fix segfault in fsck-cache
  2005-04-24  4:55             ` Linus Torvalds
  2005-04-24  5:03               ` James Bottomley
@ 2005-04-24  5:05               ` Andreas Gal
  2005-04-24  5:24                 ` Andreas Gal
  2005-04-24 12:46               ` [PATCH] make file merging respect permissions James Bottomley
  2 siblings, 1 reply; 14+ messages in thread
From: Andreas Gal @ 2005-04-24  5:05 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Git Mailing List


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;
 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATH] fix segfault in fsck-cache
  2005-04-24  5:05               ` [PATH] fix segfault in fsck-cache Andreas Gal
@ 2005-04-24  5:24                 ` Andreas Gal
  0 siblings, 0 replies; 14+ messages in thread
From: Andreas Gal @ 2005-04-24  5:24 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Git Mailing List


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
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] make file merging respect permissions
  2005-04-24  4:55             ` Linus Torvalds
  2005-04-24  5:03               ` James Bottomley
  2005-04-24  5:05               ` [PATH] fix segfault in fsck-cache Andreas Gal
@ 2005-04-24 12:46               ` James Bottomley
  2 siblings, 0 replies; 14+ messages in thread
From: James Bottomley @ 2005-04-24 12:46 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Petr Baudis, Git Mailing List

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



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-04-24 12:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-23 18:22 [PATCH] make file merging respect permissions James Bottomley
2005-04-23 20:17 ` Linus Torvalds
2005-04-23 20:37   ` James Bottomley
2005-04-23 21:44   ` James Bottomley
2005-04-23 23:02     ` Petr Baudis
2005-04-23 23:09       ` James Bottomley
2005-04-23 23:21       ` James Bottomley
2005-04-24  1:01         ` Linus Torvalds
2005-04-24  4:42           ` James Bottomley
2005-04-24  4:55             ` Linus Torvalds
2005-04-24  5:03               ` James Bottomley
2005-04-24  5:05               ` [PATH] fix segfault in fsck-cache Andreas Gal
2005-04-24  5:24                 ` Andreas Gal
2005-04-24 12:46               ` [PATCH] make file merging respect permissions James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).