{"thread":{"id":"7596","subject":"[PATCH] allow git-update-index work on subprojects","startedAt":"2007-04-10T13:39:07Z","lastAt":"2007-04-11T02:55:51Z","messageCount":3,"participants":["Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"39005","messageId":"81b0412b0704100639y331864f9ne0306aa4bf8de663@mail.gmail.com","threadId":"7596","inReplyTo":null,"subject":"[PATCH] allow git-update-index work on subprojects","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-04-10T13:39:07Z","receivedAt":"2007-04-10T13:39:07Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 4/10/07, Linus Torvalds <torvalds@linux-foundation.org> wrote:\n>\n>\n> On Mon, 9 Apr 2007, Linus Torvalds wrote:\n> >\n> > NOTE! This series of six patches does not actually contain everything you\n> > need to do that - in particular, this series will not actually connect up\n> > the magic to make \"git add\" (and thus \"git commit\") actually create the\n> > gitlink entries for subprojects. That's another (quite small) patch, but I\n> > haven't cleaned it up enough to be submittable yet.\n>\n> Here is, for your enjoyment, the last patch I used to actually test this\n> all. I do *not* submit it as a patch for actual inclusion - the other\n> patches in the series are, I think, ready to actually be merged. This one\n> is not.\n>\n> It's broken for a few reasons:\n>\n>  - it allows you to do \"git add subproject\" to add the subproject to the\n>    index (and then use \"git commit\" to commit it), but even something as\n>    simple as \"git commit -a\" doesn't work right, because the sequence that\n>    \"git commit -a\" uses to update the index doesn't work with the current\n>    state of the plumbing (ie the\n>\n>         git-diff-files --name-only -z |\n>                 git-update-index --remove -z --stdin\n>\n\nAt least git-update-index should work.\n\n---\n builtin-update-index.c |    8 +++-----\n 1 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex 47d42ed..55c9f93 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -94,12 +94,10 @@ static int process_file(const char *path)\n \t\t\t\t             path);\n \t\t\t}\n \t\t}\n-\t\tif (0 == status)\n-\t\t\treturn error(\"%s: is a directory - add files inside instead\",\n-\t\t\t             path);\n-\t\telse\n+\t\tif (status)\n \t\t\treturn error(\"lstat(\\\"%s\\\"): %s\", path,\n \t\t\t\t     strerror(errno));\n+\t\t/* could be a subproject */\n \t}\n\n \tnamelen = strlen(path);\n@@ -211,7 +209,7 @@ static void update_one(const char *path, const\nchar *prefix, int prefix_length)\n \t\tgoto free_return;\n \t}\n \tif (process_file(p))\n-\t\tdie(\"Unable to process file %s\", path);\n+\t\tdie(\"Unable to process \\\"%s\\\"\", path);\n \treport(\"add '%s'\", path);\n  free_return:\n \tif (p < path || p > path + strlen(path))\n-- \n1.5.1.147.gbaa5\n\n\nFrom 252adc55f9a8a7ee36be1abf76d8511d6f12d4f3 Mon Sep 17 00:00:00 2001\nFrom: Alex Riesen <ariesen@harmanbecker.com>\nDate: Tue, 10 Apr 2007 15:19:30 +0200\nSubject: [PATCH] allow git-update-index work on subprojects\n\n---\n builtin-update-index.c |    8 +++-----\n 1 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex 47d42ed..55c9f93 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -94,12 +94,10 @@ static int process_file(const char *path)\n \t\t\t\t             path);\n \t\t\t}\n \t\t}\n-\t\tif (0 == status)\n-\t\t\treturn error(\"%s: is a directory - add files inside instead\",\n-\t\t\t             path);\n-\t\telse\n+\t\tif (status)\n \t\t\treturn error(\"lstat(\\\"%s\\\"): %s\", path,\n \t\t\t\t     strerror(errno));\n+\t\t/* could be a subproject */\n \t}\n \n \tnamelen = strlen(path);\n@@ -211,7 +209,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)\n \t\tgoto free_return;\n \t}\n \tif (process_file(p))\n-\t\tdie(\"Unable to process file %s\", path);\n+\t\tdie(\"Unable to process \\\"%s\\\"\", path);\n \treport(\"add '%s'\", path);\n  free_return:\n \tif (p < path || p > path + strlen(path))\n-- \n1.5.1.147.gbaa5\n\n"},{"id":"39074","messageId":"20070410231900.GA4243@steel.home","threadId":"7596","inReplyTo":"81b0412b0704100639y331864f9ne0306aa4bf8de663@mail.gmail.com","subject":"[PATCH] Allow git-update-index work on subprojects","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-04-10T23:19:00Z","receivedAt":"2007-04-10T23:19:00Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Also, make \"git commit -a\" work with modifications of subproject HEADs.\n\n---\n\nThis one works with update-index --remove (which is what git-commit -a\nuses). It is ugly. I tried to keep the \"F -> D/F\" behaviour of\nupdate-index. Still have to check if \"F -> Subproject\" works.\n\n builtin-update-index.c |   45 +++++++++++++++++++++++++--------------------\n 1 files changed, 25 insertions(+), 20 deletions(-)\n\ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex eba756d..d075d50 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -62,7 +62,7 @@ static int mark_valid(const char *path)\n \n static int process_file(const char *path)\n {\n-\tint size, namelen, option, status;\n+\tint size, namelen = -1, option, status;\n \tstruct cache_entry *ce;\n \tstruct stat st;\n \n@@ -73,7 +73,7 @@ static int process_file(const char *path)\n \t */\n \tcache_tree_invalidate_path(active_cache_tree, path);\n \n-\tif (status < 0 || S_ISDIR(st.st_mode)) {\n+\tif (!status && S_ISDIR(st.st_mode)) {\n \t\t/* When we used to have \"path\" and now we want to add\n \t\t * \"path/file\", we need a way to remove \"path\" before\n \t\t * being able to add \"path/file\".  However,\n@@ -82,27 +82,32 @@ static int process_file(const char *path)\n \t\t * friendly, especially since we can do the opposite\n \t\t * case just fine without --force-remove.\n \t\t */\n-\t\tif (status == 0 || (errno == ENOENT || errno == ENOTDIR)) {\n-\t\t\tif (allow_remove) {\n-\t\t\t\tif (remove_file_from_cache(path))\n-\t\t\t\t\treturn error(\"%s: cannot remove from the index\",\n-\t\t\t\t\t             path);\n-\t\t\t\telse\n-\t\t\t\t\treturn 0;\n-\t\t\t} else if (status < 0) {\n+\t\tnamelen = strlen(path);\n+\t\tint pos = cache_name_pos(path, namelen);\n+\t\tif (0 <= pos && S_ISREG(ntohl(active_cache[pos]->ce_mode)) &&\n+\t\t    allow_remove) {\n+\t\t\tif (remove_file_from_cache(path))\n+\t\t\t\treturn error(\"%s: cannot remove from the index\", path);\n+\t\t\telse\n+\t\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\tif (status < 0) {\n+\t\tif (errno == ENOENT || errno == ENOTDIR) {\n+\t\t\tif (!allow_remove)\n \t\t\t\treturn error(\"%s: does not exist and --remove not passed\",\n-\t\t\t\t             path);\n-\t\t\t}\n+\t\t\t\t\t     path);\n+\t\t\tif (remove_file_from_cache(path))\n+\t\t\t\treturn error(\"%s: cannot remove from the index\",\n+\t\t\t\t\t     path);\n+\t\t\treturn 0;\n \t\t}\n-\t\tif (0 == status)\n-\t\t\treturn error(\"%s: is a directory - add files inside instead\",\n-\t\t\t             path);\n-\t\telse\n-\t\t\treturn error(\"lstat(\\\"%s\\\"): %s\", path,\n-\t\t\t\t     strerror(errno));\n+\t\treturn error(\"lstat(\\\"%s\\\"): %s\", path, strerror(errno));\n \t}\n \n-\tnamelen = strlen(path);\n+\tif (namelen < 0)\n+\t\tnamelen = strlen(path);\n \tsize = cache_entry_size(namelen);\n \tce = xcalloc(1, size);\n \tmemcpy(ce->name, path, namelen);\n@@ -211,7 +216,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)\n \t\tgoto free_return;\n \t}\n \tif (process_file(p))\n-\t\tdie(\"Unable to process file %s\", path);\n+\t\tdie(\"Unable to process \\\"%s\\\"\", path);\n \treport(\"add '%s'\", path);\n  free_return:\n \tif (p < path || p > path + strlen(path))\n-- \n1.5.1.135.g19a57-dirty\n"},{"id":"39079","messageId":"7vveg3r554.fsf@assigned-by-dhcp.cox.net","threadId":"7596","inReplyTo":"20070410231900.GA4243@steel.home","subject":"Re: [PATCH] Allow git-update-index work on subprojects","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-11T02:55:51Z","receivedAt":"2007-04-11T02:55:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> Also, make \"git commit -a\" work with modifications of subproject HEADs.\n>\n> ---\n>\n> This one works with update-index --remove (which is what git-commit -a\n> uses). It is ugly. I tried to keep the \"F -> D/F\" behaviour of\n> update-index. Still have to check if \"F -> Subproject\" works.\n>\n>  builtin-update-index.c |   45 +++++++++++++++++++++++++--------------------\n>  1 files changed, 25 insertions(+), 20 deletions(-)\n>\n> diff --git a/builtin-update-index.c b/builtin-update-index.c\n> index eba756d..d075d50 100644\n> --- a/builtin-update-index.c\n> +++ b/builtin-update-index.c\n> @@ -62,7 +62,7 @@ static int mark_valid(const char *path)\n>  \n>  static int process_file(const char *path)\n>  {\n> -\tint size, namelen, option, status;\n> +\tint size, namelen = -1, option, status;\n>  \tstruct cache_entry *ce;\n>  \tstruct stat st;\n>  \n> @@ -73,7 +73,7 @@ static int process_file(const char *path)\n>  \t */\n>  \tcache_tree_invalidate_path(active_cache_tree, path);\n>  \n> +\tif (!status && S_ISDIR(st.st_mode)) {\n>  \t\t/* When we used to have \"path\" and now we want to add\n>  \t\t * \"path/file\", we need a way to remove \"path\" before\n>  \t\t * being able to add \"path/file\".  However,\n> @@ -82,27 +82,32 @@ static int process_file(const char *path)\n>  \t\t * friendly, especially since we can do the opposite\n>  \t\t * case just fine without --force-remove.\n>  \t\t */\n> +\t\tnamelen = strlen(path);\n> +\t\tint pos = cache_name_pos(path, namelen);\n> +\t\tif (0 <= pos && S_ISREG(ntohl(active_cache[pos]->ce_mode)) &&\n> +\t\t    allow_remove) {\n> +\t\t\tif (remove_file_from_cache(path))\n> +\t\t\t\treturn error(\"%s: cannot remove from the index\", path);\n> +\t\t\telse\n> +\t\t\t\treturn 0;\n> +\t\t}\n> +\t}\n\nIf I used to have a symlink S and now the filesystem has a file\nS/F which I am running \"update-index --add --remove\" on, what\nhappens?\n\nIf I have a subproject at path P, and mistakenly try to add path\nP/F with \"update-index --add --remove P/F\", it should be\nrefused, shouldn't it?\n"}]}