threads / patch / 7596

patchallow git-update-index work on subprojects

Subject: [PATCH] allow git-update-index work on subprojects

## tl;dr

3 messages between Apr 10, 2007 and Apr 11, 2007. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Alex Riesen· Apr 10, 2007, 13:39 UTC · lore
On 4/10/07, Linus Torvalds <torvalds@linux-foundation.org> wrote:
Show 26 quoted lines
>
>
> On Mon, 9 Apr 2007, Linus Torvalds wrote:
> >
> > NOTE! This series of six patches does not actually contain everything you
> > need to do that - in particular, this series will not actually connect up
> > the magic to make "git add" (and thus "git commit") actually create the
> > gitlink entries for subprojects. That's another (quite small) patch, but I
> > haven't cleaned it up enough to be submittable yet.
>
> Here is, for your enjoyment, the last patch I used to actually test this
> all. I do *not* submit it as a patch for actual inclusion - the other
> patches in the series are, I think, ready to actually be merged. This one
> is not.
>
> It's broken for a few reasons:
>
>  - it allows you to do "git add subproject" to add the subproject to the
>    index (and then use "git commit" to commit it), but even something as
>    simple as "git commit -a" doesn't work right, because the sequence that
>    "git commit -a" uses to update the index doesn't work with the current
>    state of the plumbing (ie the
>
>         git-diff-files --name-only -z |
>                 git-update-index --remove -z --stdin
>
At least git-update-index should work.
---
 builtin-update-index.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
Show changes to builtin-update-index.c +3 −5
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 47d42ed..55c9f93 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -94,12 +94,10 @@ static int process_file(const char *path)
 				             path);
 			}
 		}
-		if (0 == status)
-			return error("%s: is a directory - add files inside instead",
-			             path);
-		else
+		if (status)
 			return error("lstat(\"%s\"): %s", path,
 				     strerror(errno));
+		/* could be a subproject */
 	}

 	namelen = strlen(path);
@@ -211,7 +209,7 @@ static void update_one(const char *path, const
char *prefix, int prefix_length)
 		goto free_return;
 	}
 	if (process_file(p))
-		die("Unable to process file %s", path);
+		die("Unable to process \"%s\"", path);
 	report("add '%s'", path);
  free_return:
 	if (p < path || p > path + strlen(path))
-- 
1.5.1.147.gbaa5


From 252adc55f9a8a7ee36be1abf76d8511d6f12d4f3 Mon Sep 17 00:00:00 2001
From: Alex Riesen <ariesen@harmanbecker.com>
Date: Tue, 10 Apr 2007 15:19:30 +0200
Subject: [PATCH] allow git-update-index work on subprojects

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

diff --git a/builtin-update-index.c b/builtin-update-index.c
index 47d42ed..55c9f93 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -94,12 +94,10 @@ static int process_file(const char *path)
 				             path);
 			}
 		}
-		if (0 == status)
-			return error("%s: is a directory - add files inside instead",
-			             path);
-		else
+		if (status)
 			return error("lstat(\"%s\"): %s", path,
 				     strerror(errno));
+		/* could be a subproject */
 	}
 
 	namelen = strlen(path);
@@ -211,7 +209,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
 		goto free_return;
 	}
 	if (process_file(p))
-		die("Unable to process file %s", path);
+		die("Unable to process \"%s\"", path);
 	report("add '%s'", path);
  free_return:
 	if (p < path || p > path + strlen(path))
-- 
1.5.1.147.gbaa5
Alex Riesen· Apr 10, 2007, 23:19 UTC · re: Alex Riesen · lore

[PATCH] Allow git-update-index work on subprojects

Also, make "git commit -a" work with modifications of subproject HEADs.
---

This one works with update-index --remove (which is what git-commit -a uses). It is ugly. I tried to keep the "F -> D/F" behaviour of update-index. Still have to check if "F -> Subproject" works.

 builtin-update-index.c |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
Show changes to builtin-update-index.c +25 −20
diff --git a/builtin-update-index.c b/builtin-update-index.c
index eba756d..d075d50 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -62,7 +62,7 @@ static int mark_valid(const char *path)
 
 static int process_file(const char *path)
 {
-	int size, namelen, option, status;
+	int size, namelen = -1, option, status;
 	struct cache_entry *ce;
 	struct stat st;
 
@@ -73,7 +73,7 @@ static int process_file(const char *path)
 	 */
 	cache_tree_invalidate_path(active_cache_tree, path);
 
-	if (status < 0 || S_ISDIR(st.st_mode)) {
+	if (!status && S_ISDIR(st.st_mode)) {
 		/* When we used to have "path" and now we want to add
 		 * "path/file", we need a way to remove "path" before
 		 * being able to add "path/file".  However,
@@ -82,27 +82,32 @@ static int process_file(const char *path)
 		 * friendly, especially since we can do the opposite
 		 * case just fine without --force-remove.
 		 */
-		if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) {
-			if (allow_remove) {
-				if (remove_file_from_cache(path))
-					return error("%s: cannot remove from the index",
-					             path);
-				else
-					return 0;
-			} else if (status < 0) {
+		namelen = strlen(path);
+		int pos = cache_name_pos(path, namelen);
+		if (0 <= pos && S_ISREG(ntohl(active_cache[pos]->ce_mode)) &&
+		    allow_remove) {
+			if (remove_file_from_cache(path))
+				return error("%s: cannot remove from the index", path);
+			else
+				return 0;
+		}
+	}
+
+	if (status < 0) {
+		if (errno == ENOENT || errno == ENOTDIR) {
+			if (!allow_remove)
 				return error("%s: does not exist and --remove not passed",
-				             path);
-			}
+					     path);
+			if (remove_file_from_cache(path))
+				return error("%s: cannot remove from the index",
+					     path);
+			return 0;
 		}
-		if (0 == status)
-			return error("%s: is a directory - add files inside instead",
-			             path);
-		else
-			return error("lstat(\"%s\"): %s", path,
-				     strerror(errno));
+		return error("lstat(\"%s\"): %s", path, strerror(errno));
 	}
 
-	namelen = strlen(path);
+	if (namelen < 0)
+		namelen = strlen(path);
 	size = cache_entry_size(namelen);
 	ce = xcalloc(1, size);
 	memcpy(ce->name, path, namelen);
@@ -211,7 +216,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
 		goto free_return;
 	}
 	if (process_file(p))
-		die("Unable to process file %s", path);
+		die("Unable to process \"%s\"", path);
 	report("add '%s'", path);
  free_return:
 	if (p < path || p > path + strlen(path))
-- 
1.5.1.135.g19a57-dirty
Junio C Hamano· Apr 11, 2007, 02:55 UTC · re: Alex Riesen · lore

Re: [PATCH] Allow git-update-index work on subprojects

Alex Riesen <raa.lkml@gmail.com> writes:
Show 46 quoted lines
> Also, make "git commit -a" work with modifications of subproject HEADs.
>
> ---
>
> This one works with update-index --remove (which is what git-commit -a
> uses). It is ugly. I tried to keep the "F -> D/F" behaviour of
> update-index. Still have to check if "F -> Subproject" works.
>
>  builtin-update-index.c |   45 +++++++++++++++++++++++++--------------------
>  1 files changed, 25 insertions(+), 20 deletions(-)
>
> diff --git a/builtin-update-index.c b/builtin-update-index.c
> index eba756d..d075d50 100644
> --- a/builtin-update-index.c
> +++ b/builtin-update-index.c
> @@ -62,7 +62,7 @@ static int mark_valid(const char *path)
>  
>  static int process_file(const char *path)
>  {
> -	int size, namelen, option, status;
> +	int size, namelen = -1, option, status;
>  	struct cache_entry *ce;
>  	struct stat st;
>  
> @@ -73,7 +73,7 @@ static int process_file(const char *path)
>  	 */
>  	cache_tree_invalidate_path(active_cache_tree, path);
>  
> +	if (!status && S_ISDIR(st.st_mode)) {
>  		/* When we used to have "path" and now we want to add
>  		 * "path/file", we need a way to remove "path" before
>  		 * being able to add "path/file".  However,
> @@ -82,27 +82,32 @@ static int process_file(const char *path)
>  		 * friendly, especially since we can do the opposite
>  		 * case just fine without --force-remove.
>  		 */
> +		namelen = strlen(path);
> +		int pos = cache_name_pos(path, namelen);
> +		if (0 <= pos && S_ISREG(ntohl(active_cache[pos]->ce_mode)) &&
> +		    allow_remove) {
> +			if (remove_file_from_cache(path))
> +				return error("%s: cannot remove from the index", path);
> +			else
> +				return 0;
> +		}
> +	}

If I used to have a symlink S and now the filesystem has a file S/F which I am running "update-index --add --remove" on, what happens?

If I have a subproject at path P, and mistakenly try to add path P/F with "update-index --add --remove P/F", it should be refused, shouldn't it?

← back to recent threads