{"thread":{"id":"8313","subject":"[PATCH 1/3] run-command: optionally clear git environment","startedAt":"2007-05-25T21:07:11Z","lastAt":"2007-05-25T23:06:19Z","messageCount":7,"participants":["skimo@liacs.nl","Martin Waitz","Sven Verdoolaege","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"43290","messageId":"1180127233729-git-send-email-skimo@liacs.nl","threadId":"8313","inReplyTo":null,"subject":"[PATCH 1/3] run-command: optionally clear git environment","fromName":"","fromEmail":"skimo@liacs.nl","sentAt":"2007-05-25T21:07:11Z","receivedAt":"2007-05-25T21:07:11Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"From: Sven Verdoolaege <skimo@kotnet.org>\n\nSigned-off-by: Sven Verdoolaege <skimo@kotnet.org>\n---\n run-command.c |    6 ++++++\n run-command.h |    1 +\n 2 files changed, 7 insertions(+), 0 deletions(-)\n\ndiff --git a/run-command.c b/run-command.c\nindex 7e779d3..5c47f45 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -2,6 +2,10 @@\n #include \"run-command.h\"\n #include \"exec_cmd.h\"\n \n+static const char* git_env_list[] = { ALTERNATE_DB_ENVIRONMENT, DB_ENVIRONMENT,\n+\t\t\tCONFIG_ENVIRONMENT, GIT_DIR_ENVIRONMENT,\n+\t\t\tGRAFT_ENVIRONMENT, INDEX_ENVIRONMENT, NULL };\n+\n static inline void close_pair(int fd[2])\n {\n \tclose(fd[0]);\n@@ -153,6 +157,8 @@ static void prepare_run_command_v_opt(struct child_process *cmd,\n \tcmd->no_stdin = opt & RUN_COMMAND_NO_STDIN ? 1 : 0;\n \tcmd->git_cmd = opt & RUN_GIT_CMD ? 1 : 0;\n \tcmd->stdout_to_stderr = opt & RUN_COMMAND_STDOUT_TO_STDERR ? 1 : 0;\n+\tif (opt & RUN_COMMAND_CLEAR_GIT_ENV)\n+\t\tcmd->env = git_env_list;\n }\n \n int run_command_v_opt(const char **argv, int opt)\ndiff --git a/run-command.h b/run-command.h\nindex 7958eb1..a5374cc 100644\n--- a/run-command.h\n+++ b/run-command.h\n@@ -33,6 +33,7 @@ int run_command(struct child_process *);\n #define RUN_COMMAND_NO_STDIN 1\n #define RUN_GIT_CMD\t     2\t/*If this is to be git sub-command */\n #define RUN_COMMAND_STDOUT_TO_STDERR 4\n+#define RUN_COMMAND_CLEAR_GIT_ENV\t(1 << 3)\n int run_command_v_opt(const char **argv, int opt);\n int run_command_v_opt_cd(const char **argv, int opt, const char *dir);\n \n-- \n1.5.2.838.gbeec\n"},{"id":"43292","messageId":"1180127233893-git-send-email-skimo@liacs.nl","threadId":"8313","inReplyTo":"1180127233729-git-send-email-skimo@liacs.nl","subject":"[PATCH 2/3] entry.c: checkout available submodules","fromName":"","fromEmail":"skimo@liacs.nl","sentAt":"2007-05-25T21:07:12Z","receivedAt":"2007-05-25T21:07:12Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"From: Sven Verdoolaege <skimo@kotnet.org>\n\nThat is, checkout any submodule that has a valid HEAD in it.\n\nSigned-off-by: Sven Verdoolaege <skimo@kotnet.org>\n---\n Makefile     |    5 +++--\n entry.c      |   30 ++++++++++++++++++++++++++++--\n submodules.c |    8 ++++++++\n submodules.h |    6 ++++++\n 4 files changed, 45 insertions(+), 4 deletions(-)\n create mode 100644 submodules.c\n create mode 100644 submodules.h\n\ndiff --git a/Makefile b/Makefile\nindex c79a6da..6d24048 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -297,7 +297,7 @@ LIB_H = \\\n \trun-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \\\n \ttree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \\\n \tutf8.h reflog-walk.h patch-ids.h attr.h decorate.h progress.h \\\n-\tmailmap.h remote.h\n+\tmailmap.h remote.h submodules.h\n \n DIFF_OBJS = \\\n \tdiff.o diff-lib.o diffcore-break.o diffcore-order.o \\\n@@ -319,7 +319,8 @@ LIB_OBJS = \\\n \twrite_or_die.o trace.o list-objects.o grep.o match-trees.o \\\n \talloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \\\n \tcolor.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \\\n-\tconvert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o\n+\tconvert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \\\n+\tsubmodules.o\n \n BUILTIN_OBJS = \\\n \tbuiltin-add.o \\\ndiff --git a/entry.c b/entry.c\nindex ae64764..97f95c6 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -1,5 +1,7 @@\n #include \"cache.h\"\n #include \"blob.h\"\n+#include \"run-command.h\"\n+#include \"submodules.h\"\n \n static void create_directories(const char *path, const struct checkout *state)\n {\n@@ -75,6 +77,31 @@ static void *read_blob_entry(struct cache_entry *ce, const char *path, unsigned\n \treturn NULL;\n }\n \n+static int checkout_submodule(struct cache_entry *ce, const char *path, const struct checkout *state)\n+{\n+\tconst char *args[10];\n+\tint argc;\n+\tint err;\n+\n+\tif (!is_checkedout_submodule(ce->name))\n+\t\treturn 0;\n+\n+\targc = 0;\n+\targs[argc++] = \"checkout\";\n+\tif (state->force)\n+\t    args[argc++] = \"-f\";\n+\targs[argc++] = sha1_to_hex(ce->sha1);\n+\targs[argc] = NULL;\n+\n+\terr = run_command_v_opt_cd(args, RUN_GIT_CMD|RUN_COMMAND_CLEAR_GIT_ENV,\n+\t\t\t\t   path);\n+\n+\tif (err)\n+\t\treturn error(\"failed to run git-checkout in submodule '%s'\", path);\n+\n+\treturn 0;\n+}\n+\n static int write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile)\n {\n \tint fd;\n@@ -193,9 +220,8 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t\n \t\t */\n \t\tunlink(path);\n \t\tif (S_ISDIR(st.st_mode)) {\n-\t\t\t/* If it is a gitlink, leave it alone! */\n \t\t\tif (S_ISGITLINK(ntohl(ce->ce_mode)))\n-\t\t\t\treturn 0;\n+\t\t\t\treturn checkout_submodule(ce, path, state);\n \t\t\tif (!state->force)\n \t\t\t\treturn error(\"%s is a directory\", path);\n \t\t\tremove_subtree(path);\ndiff --git a/submodules.c b/submodules.c\nnew file mode 100644\nindex 0000000..5baf90a\n--- /dev/null\n+++ b/submodules.c\n@@ -0,0 +1,8 @@\n+#include \"cache.h\"\n+#include \"refs.h\"\n+\n+int is_checkedout_submodule(const char *path)\n+{\n+\tunsigned char sha1[20];\n+\treturn resolve_gitlink_ref(path, \"HEAD\", sha1) == 0;\n+}\ndiff --git a/submodules.h b/submodules.h\nnew file mode 100644\nindex 0000000..099c4c3\n--- /dev/null\n+++ b/submodules.h\n@@ -0,0 +1,6 @@\n+#ifndef SUBMODULES_H\n+#define SUBMODULES_H\n+\n+int is_checkedout_submodule(const char *path);\n+\n+#endif\n-- \n1.5.2.838.gbeec\n"},{"id":"43291","messageId":"1180127233176-git-send-email-skimo@liacs.nl","threadId":"8313","inReplyTo":"1180127233729-git-send-email-skimo@liacs.nl","subject":"[PATCH 3/3] test for simple submodule checkout support","fromName":"","fromEmail":"skimo@liacs.nl","sentAt":"2007-05-25T21:07:13Z","receivedAt":"2007-05-25T21:07:13Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"From: Martin Waitz <tali@admingilde.org>\n\nSigned-off-by: Martin Waitz <tali@admingilde.org>\nSigned-off-by: Sven Verdoolaege <skimo@kotnet.org>\n---\n t/t3041-subprojects-checkout.sh |   39 +++++++++++++++++++++++++++++++++++++++\n 1 files changed, 39 insertions(+), 0 deletions(-)\n create mode 100755 t/t3041-subprojects-checkout.sh\n\ndiff --git a/t/t3041-subprojects-checkout.sh b/t/t3041-subprojects-checkout.sh\nnew file mode 100755\nindex 0000000..4b3cea9\n--- /dev/null\n+++ b/t/t3041-subprojects-checkout.sh\n@@ -0,0 +1,39 @@\n+#!/bin/sh\n+\n+test_description='submodule checkout'\n+. ./test-lib.sh\n+\n+test_expect_success 'submodule creation' \\\n+    '(mkdir A && cd A &&\n+      git init &&\n+      echo 1 > a &&\n+      git add a &&\n+      git commit -m \"create submodule\" || exit $? )'\n+\n+test_expect_success 'Super module creation' \\\n+    'git add A &&\n+     git commit -m \"supermodule creation\" &&\n+     git branch one'\n+\n+test_expect_success 'submodule change' \\\n+    '(cd A &&\n+      echo 2 > a &&\n+      git add a &&\n+      git commit -m \"create submodule\" || exit $? )'\n+\n+test_expect_success 'supermodule change' \\\n+    'git add A &&\n+     git commit -m \"supermodule creation\"'\n+\n+test_expect_success 'supermodule switching branch' \\\n+    'git checkout one &&\n+     echo 1 > expected &&\n+     git diff expected A/a'\n+\n+test_expect_success 'supermodule reset' \\\n+    'git reset --hard master &&\n+     echo 2 > expected &&\n+     git diff expected A/a'\n+\n+\n+test_done\n-- \n1.5.2.838.gbeec\n"},{"id":"43295","messageId":"20070525213103.GA8361@admingilde.org","threadId":"8313","inReplyTo":"1180127233893-git-send-email-skimo@liacs.nl","subject":"Re: [PATCH 2/3] entry.c: checkout available submodules","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2007-05-25T21:31:03Z","receivedAt":"2007-05-25T21:31:03Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Fri, May 25, 2007 at 11:07:12PM +0200, skimo@liacs.nl wrote:\n>  create mode 100644 submodules.c\n>  create mode 100644 submodules.h\n\nI think the list tends to prefer subproject over submodule.\n\n> @@ -193,9 +220,8 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t\n>  \t\t */\n>  \t\tunlink(path);\n>  \t\tif (S_ISDIR(st.st_mode)) {\n> -\t\t\t/* If it is a gitlink, leave it alone! */\n>  \t\t\tif (S_ISGITLINK(ntohl(ce->ce_mode)))\n> -\t\t\t\treturn 0;\n> +\t\t\t\treturn checkout_submodule(ce, path, state);\n>  \t\t\tif (!state->force)\n>  \t\t\t\treturn error(\"%s is a directory\", path);\n>  \t\t\tremove_subtree(path);\n\nI think the call to checkout_submodule should be moved to write_entry,\nto keep it in line with the other mode types.\n\nAside from that I really like it :-)\n\n-- \nMartin Waitz\n"},{"id":"43298","messageId":"20070525214205.GJ942MdfPADPa@greensroom.kotnet.org","threadId":"8313","inReplyTo":"20070525213103.GA8361@admingilde.org","subject":"Re: [PATCH 2/3] entry.c: checkout available submodules","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-05-25T21:42:05Z","receivedAt":"2007-05-25T21:42:05Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Fri, May 25, 2007 at 11:31:03PM +0200, Martin Waitz wrote:\n> I think the list tends to prefer subproject over submodule.\n\nDoes it?  It seems that everyone writing code is use submodule\ninstead of subproject.  Either way, I don't really care.\n\n> > @@ -193,9 +220,8 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t\n> >  \t\t */\n> >  \t\tunlink(path);\n> >  \t\tif (S_ISDIR(st.st_mode)) {\n> > -\t\t\t/* If it is a gitlink, leave it alone! */\n> >  \t\t\tif (S_ISGITLINK(ntohl(ce->ce_mode)))\n> > -\t\t\t\treturn 0;\n> > +\t\t\t\treturn checkout_submodule(ce, path, state);\n> >  \t\t\tif (!state->force)\n> >  \t\t\t\treturn error(\"%s is a directory\", path);\n> >  \t\t\tremove_subtree(path);\n> \n> I think the call to checkout_submodule should be moved to write_entry,\n> to keep it in line with the other mode types.\n\nWell, like your patch, this only deals with cases where the submodule\nis already available.  In write_entry you could potentially clone\nsubmodules based on some criteria, but I'm not doing this just yet\nsince some people apparently prefer to get these things in pieces.\n\nAlso, it seems that some people would like this to be a step\nthat is separated from git-checkout (see Lars' patch).\n\nskimo\n"},{"id":"43301","messageId":"20070525221913.GB8361@admingilde.org","threadId":"8313","inReplyTo":"20070525214205.GJ942MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH 2/3] entry.c: checkout available submodules","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2007-05-25T22:19:14Z","receivedAt":"2007-05-25T22:19:14Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Fri, May 25, 2007 at 11:42:05PM +0200, Sven Verdoolaege wrote:\n> On Fri, May 25, 2007 at 11:31:03PM +0200, Martin Waitz wrote:\n> > I think the list tends to prefer subproject over submodule.\n> \n> Does it?  It seems that everyone writing code is use submodule\n> instead of subproject.  Either way, I don't really care.\n\nI got that impression from my small poll.\n\n> > > @@ -193,9 +220,8 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t\n> > >  \t\t */\n> > >  \t\tunlink(path);\n> > >  \t\tif (S_ISDIR(st.st_mode)) {\n> > > -\t\t\t/* If it is a gitlink, leave it alone! */\n> > >  \t\t\tif (S_ISGITLINK(ntohl(ce->ce_mode)))\n> > > -\t\t\t\treturn 0;\n> > > +\t\t\t\treturn checkout_submodule(ce, path, state);\n> > >  \t\t\tif (!state->force)\n> > >  \t\t\t\treturn error(\"%s is a directory\", path);\n> > >  \t\t\tremove_subtree(path);\n> > \n> > I think the call to checkout_submodule should be moved to write_entry,\n> > to keep it in line with the other mode types.\n> \n> Well, like your patch, this only deals with cases where the submodule\n> is already available.  In write_entry you could potentially clone\n> submodules based on some criteria, but I'm not doing this just yet\n> since some people apparently prefer to get these things in pieces.\n\nyes, first we need checkout and then can add more building blocks on\ntop.\n\nUp to now the quoted code block above only handles cleaning the\ntree from conflicting / old entries and write_entry creates the\nreal content.\n\nFor subprojects we first have to remove any non-subproject content\nin that location and then later call write_subproject or similiar\nin write_entry to update the subproject (or create some empty dummy\ndirectory).\n\nBut we can also leave those details for later when we are clear about\nthe complete semantics.  At the moment it is important to reach a\ncommon base everybody agrees on and which is enough to experiment with\nall the high level tools.\n\n-- \nMartin Waitz\n"},{"id":"43306","messageId":"7vfy5kpkpg.fsf@assigned-by-dhcp.cox.net","threadId":"8313","inReplyTo":"20070525221913.GB8361@admingilde.org","subject":"Re: [PATCH 2/3] entry.c: checkout available submodules","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-25T23:06:19Z","receivedAt":"2007-05-25T23:06:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Waitz <tali@admingilde.org> writes:\n\n> But we can also leave those details for later when we are clear about\n> the complete semantics.  At the moment it is important to reach a\n> common base everybody agrees on and which is enough to experiment with\n> all the high level tools.\n\nOverall I am reasonably happy with the direction these \"smaller\"\npatches take us, although I suspect the semantics implemented by\nthis series _might_ need to be scrapped when we start talking\nabout switching between branches that has and does not have a\nsubproject at that path, and other corner cases we do not forsee\nright now.\n\nI think we are Ok, as long as we make it is clear that we\ncurrently do not support switching from a commit that has a\nsubmodule at one path to another commit that does not (in which\ncase with a naive implementation we would end up having to nuke\nthe submodule, and we need to have a way to save it, which we\ndiscussed yesterday, with .git/subproject/$name.git/ being the\nstashed away mirror to either quick-clone from, or symlink to).\nAnd more importantly, we would need to make it crystal clear\nthat the superproject support by the Porcelain layer is still\nexperimental and is subject to change in potentially backward\nincompatible way.  We haven't had enough experience to decide\nthe best semantics from day one, and experience cannot be gained\nwithout playing with something small like this series anyway.\n\nWe may come up with a much superior design after gaining the\nexperience, and if that is incompatible with the layout this\nseries assumes, so be it.  We'd have a big feature release that\nchanges the semantics and that will incur some transition pain,\nbut overall we would be better off with the final result.\n\nA clear separation of the superproject and the projects it uses\nas its submodules helps us here.  At the worst case, migrating\nto the updated layout in the future would involve moving .git\ndirectories around in the checked out tree and perhaps making\nsymlinks and/or setting up various .git/config files by hand to\nimitate what the final toolset would have done for the user,\nwhich should be manageable.\n"}]}