threads / discuss / 3945

make update-index --chmod work with multiple files and --stdin

Subject: make update-index --chmod work with multiple files and --stdin

## tl;dr

4 messages between Apr 22, 2006 and Apr 23, 2006.

replies: 3people: 2as markdown or json

Alex Riesen· Apr 22, 2006, 20:46 UTC · lore

I had a project where lots of files were "accidentally" marked +x, and doing plain "git-update-index --chmod=-x" for each file was too slow. Besides, it's somewhat inconsistent, that --chmod does work only for one subsequent file.

---
Yes, windows again.
 update-index.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
5c7b9c2d187f36ba8b5632d2125f2bd19abb3564
diff --git a/update-index.c b/update-index.c
index 1efac27..c3c2000 100644
--- a/update-index.c
+++ b/update-index.c
@@ -350,6 +350,7 @@ static int chmod_path(int flip, const ch
 		return -1;
 	}
 	active_cache_changed = 1;
+	report("chmod %cx '%s'", flip, path);
 	return 0;
 }
 
@@ -478,6 +479,7 @@ int main(int argc, const char **argv)
 	int read_from_stdin = 0;
 	const char *prefix = setup_git_directory();
 	int prefix_length = prefix ? strlen(prefix) : 0;
+	char chmod_mode = 0;
 
 	git_config(git_default_config);
 
@@ -544,8 +546,7 @@ int main(int argc, const char **argv)
 			    !strcmp(path, "--chmod=+x")) {
 				if (argc <= i+1)
 					die("git-update-index: %s <path>", path);
-				if (chmod_path(path[8], argv[++i]))
-					die("git-update-index: %s cannot chmod %s", path, argv[i]);
+				chmod_mode = path[8];
 				continue;
 			}
 			if (!strcmp(path, "--assume-unchanged")) {
@@ -594,6 +595,11 @@ int main(int argc, const char **argv)
 			die("unknown option %s", path);
 		}
 		update_one(path, prefix, prefix_length);
+		if ( chmod_mode ) {
+			if (chmod_path(chmod_mode, path))
+				die("git-update-index: cannot chmod %cx %s",
+				    chmod_mode, path);
+		}
 	}
 	if (read_from_stdin) {
 		struct strbuf buf;
@@ -608,6 +614,12 @@ int main(int argc, const char **argv)
 			else
 				path_name = buf.buf;
 			update_one(path_name, prefix, prefix_length);
+			if ( chmod_mode ) {
+				const char *p = prefix_path(prefix, prefix_length, path_name);
+				if (chmod_path(chmod_mode, p))
+					die("git-update-index: cannot chmod %cx %s",
+					    chmod_mode, p);
+			}
 			if (path_name != buf.buf)
 				free(path_name);
 		}
-- 
1.3.0.gc2941
Junio C Hamano· Apr 23, 2006, 00:54 UTC · re: Alex Riesen · lore

Re: make update-index --chmod work with multiple files and --stdin

Alex Riesen <raa.lkml@gmail.com> writes:
> I had a project where lots of files were "accidentally" marked +x, and
> doing plain "git-update-index --chmod=-x" for each file was too slow.
> Besides, it's somewhat inconsistent, that --chmod does work only for
> one subsequent file.

If you are doing that on the command line, people may want to have a way to mean "from here on do not do chmod, just do normal update-index and nothing else" by resetting the chmod_mode thing back to zero. Nothing major, and we do not do that to allow_add and allow_remove either, but just a thought.

> +	char chmod_mode = 0;
Perhaps "set_executable_bit"?
> +		if ( chmod_mode ) {
Please lose ( extra ) whitespaces around parentheses.
> +			if ( chmod_mode ) {
Likewise.
> +				if (chmod_path(chmod_mode, p))
> +					die("git-update-index: cannot chmod %cx %s",
> +					    chmod_mode, p);
> +			}

Might make sense to die inside chmod_path() instead of repeating the if () { die() } sequence twice? I dunno.

Alex Riesen· Apr 23, 2006, 07:01 UTC · re: Junio C Hamano · lore

Re: make update-index --chmod work with multiple files and --stdin

Junio C Hamano, Sun, Apr 23, 2006 02:54:51 +0200:
Show 10 quoted lines
> > I had a project where lots of files were "accidentally" marked +x, and
> > doing plain "git-update-index --chmod=-x" for each file was too slow.
> > Besides, it's somewhat inconsistent, that --chmod does work only for
> > one subsequent file.
> 
> If you are doing that on the command line, people may want to
> have a way to mean "from here on do not do chmod, just do normal
> update-index and nothing else" by resetting the chmod_mode thing
> back to zero.  Nothing major, and we do not do that to allow_add
> and allow_remove either, but just a thought.
Not sure about that, but did it anyway (as separate patches).

I updated the patch with the other remarks regarding set_executable_bit, whitespaces and die in chmod_path (thought about this one myself, but was lazy).

---
 update-index.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
92d1372fd0358811a5f2670b99a6a304dadb7864
diff --git a/update-index.c b/update-index.c
index 1efac27..a8582ea 100644
--- a/update-index.c
+++ b/update-index.c
@@ -328,7 +328,7 @@ static int add_cacheinfo(unsigned int mo
 	return 0;
 }
 
-static int chmod_path(int flip, const char *path)
+static void chmod_path(int flip, const char *path)
 {
 	int pos;
 	struct cache_entry *ce;
@@ -336,21 +336,24 @@ static int chmod_path(int flip, const ch
 
 	pos = cache_name_pos(path, strlen(path));
 	if (pos < 0)
-		return -1;
+		goto _fail;
 	ce = active_cache[pos];
 	mode = ntohl(ce->ce_mode);
 	if (!S_ISREG(mode))
-		return -1;
+		goto _fail;
 	switch (flip) {
 	case '+':
 		ce->ce_mode |= htonl(0111); break;
 	case '-':
 		ce->ce_mode &= htonl(~0111); break;
 	default:
-		return -1;
+		goto _fail;
 	}
 	active_cache_changed = 1;
-	return 0;
+	report("chmod %cx '%s'", flip, path);
+	return;
+_fail:
+	die("git-update-index: cannot chmod %cx '%s'", flip, path);
 }
 
 static struct cache_file cache_file;
@@ -478,6 +481,7 @@ int main(int argc, const char **argv)
 	int read_from_stdin = 0;
 	const char *prefix = setup_git_directory();
 	int prefix_length = prefix ? strlen(prefix) : 0;
+	char set_executable_bit = 0;
 
 	git_config(git_default_config);
 
@@ -544,8 +548,7 @@ int main(int argc, const char **argv)
 			    !strcmp(path, "--chmod=+x")) {
 				if (argc <= i+1)
 					die("git-update-index: %s <path>", path);
-				if (chmod_path(path[8], argv[++i]))
-					die("git-update-index: %s cannot chmod %s", path, argv[i]);
+				set_executable_bit = path[8];
 				continue;
 			}
 			if (!strcmp(path, "--assume-unchanged")) {
@@ -594,6 +597,8 @@ int main(int argc, const char **argv)
 			die("unknown option %s", path);
 		}
 		update_one(path, prefix, prefix_length);
+		if (set_executable_bit)
+			chmod_path(set_executable_bit, path);
 	}
 	if (read_from_stdin) {
 		struct strbuf buf;
@@ -608,6 +613,10 @@ int main(int argc, const char **argv)
 			else
 				path_name = buf.buf;
 			update_one(path_name, prefix, prefix_length);
+			if (set_executable_bit) {
+				const char *p = prefix_path(prefix, prefix_length, path_name);
+				chmod_path(set_executable_bit, p);
+			}
 			if (path_name != buf.buf)
 				free(path_name);
 		}
-- 
1.3.0.gc2941
Alex Riesen· Apr 23, 2006, 07:08 UTC · re: Junio C Hamano · lore

Re: make update-index --chmod work with multiple files and --stdin

Junio C Hamano, Sun, Apr 23, 2006 02:54:51 +0200:
Show 12 quoted lines
> Alex Riesen <raa.lkml@gmail.com> writes:
> 
> > I had a project where lots of files were "accidentally" marked +x, and
> > doing plain "git-update-index --chmod=-x" for each file was too slow.
> > Besides, it's somewhat inconsistent, that --chmod does work only for
> > one subsequent file.
> 
> If you are doing that on the command line, people may want to
> have a way to mean "from here on do not do chmod, just do normal
> update-index and nothing else" by resetting the chmod_mode thing
> back to zero.  Nothing major, and we do not do that to allow_add
> and allow_remove either, but just a thought.

I am unsure about this. I'm even attaching instead of inlining the patches, to make it clear how unsure I am :)

I have a feeling that it's more understandable to just use two separate commands. Besides, the reset switch makes it impossible to use pathname disambiguation ("--"). Unsure...

>From nobody Mon Sep 17 00:00:00 2001
From: Junio C Hamano <junkio@cox.net>
Date: Sun Apr 23 08:38:04 2006 +0200
Subject: git-update-index --no-chmod
Message-ID: <7v1wvpi010.fsf@assigned-by-dhcp.cox.net>
Alex Riesen <raa.lkml@gmail.com> writes:
> I had a project where lots of files were "accidentally" marked +x, and
> doing plain "git-update-index --chmod=-x" for each file was too slow.
> Besides, it's somewhat inconsistent, that --chmod does work only for
> one subsequent file.

If you are doing that on the command line, people may want to have a way to mean "from here on do not do chmod, just do normal update-index and nothing else" by resetting the chmod_mode thing back to zero. Nothing major, and we do not do that to allow_add and allow_remove either, but just a thought.

---
 update-index.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
2972ef33fa4b04f07d4f4dbb9e13d5b9b2d593b4
diff --git a/update-index.c b/update-index.c
index a8582ea..1ed36fa 100644
--- a/update-index.c
+++ b/update-index.c
@@ -551,6 +551,10 @@ int main(int argc, const char **argv)
 				set_executable_bit = path[8];
 				continue;
 			}
+			if (!strcmp(path, "--no-chmod")) {
+				set_executable_bit = 0;
+				continue;
+			}
 			if (!strcmp(path, "--assume-unchanged")) {
 				mark_valid_only = MARK_VALID;
 				continue;
-- 
1.3.0.gc2941



>From nobody Mon Sep 17 00:00:00 2001
From: Junio C Hamano <junkio@cox.net>
Date: Sun Apr 23 08:43:42 2006 +0200
Subject: git-update-index: add --no-add and --no-remove

Message-ID: <7v1wvpi010.fsf@assigned-by-dhcp.cox.net>

Alex Riesen <raa.lkml@gmail.com> writes:

> I had a project where lots of files were "accidentally" marked +x, and
> doing plain "git-update-index --chmod=-x" for each file was too slow.
> Besides, it's somewhat inconsistent, that --chmod does work only for
> one subsequent file.

If you are doing that on the command line, people may want to
have a way to mean "from here on do not do chmod, just do normal
update-index and nothing else" by resetting the chmod_mode thing
back to zero.  Nothing major, and we do not do that to allow_add
and allow_remove either, but just a thought.

---

 update-index.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

89bceee48996f366a779b0c95ba230ec24fea340
diff --git a/update-index.c b/update-index.c
index 1ed36fa..cbee859 100644
--- a/update-index.c
+++ b/update-index.c
@@ -509,6 +509,10 @@ int main(int argc, const char **argv)
 				allow_add = 1;
 				continue;
 			}
+			if (!strcmp(path, "--no-add")) {
+				allow_add = 0;
+				continue;
+			}
 			if (!strcmp(path, "--replace")) {
 				allow_replace = 1;
 				continue;
@@ -517,6 +521,10 @@ int main(int argc, const char **argv)
 				allow_remove = 1;
 				continue;
 			}
+			if (!strcmp(path, "--no-remove")) {
+				allow_remove = 0;
+				continue;
+			}
 			if (!strcmp(path, "--unmerged")) {
 				allow_unmerged = 1;
 				continue;
-- 
1.3.0.gc2941

← back to recent threads