git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Brandon Williams <bmwill@google.com>
To: Stefan Beller <sbeller@google.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Martin Fick <mogulguy10@gmail.com>,
	David Turner <David.Turner@twosigma.com>
Subject: Re: [PATCH 08/16] update submodules: add depopulate_submodule
Date: Fri, 18 Nov 2016 09:46:07 -0800	[thread overview]
Message-ID: <20161118174607.GP66382@google.com> (raw)
In-Reply-To: <CAGZ79kYE1JooyKMDsEM5=6OWxbCOL3q2=Et3nL7mMcayxtLZxA@mail.gmail.com>

On 11/17, Stefan Beller wrote:
> On Thu, Nov 17, 2016 at 2:42 PM, Stefan Beller <sbeller@google.com> wrote:
> >
> > I think I'll just write this functionality in C and optionally expose
> > it via the submodule--helper,
> > such that the user facing git-submodule.sh only has to call that helper.
> 
> I think it will roughly look like this:
> (white space mangled)
> 
> 
> commit e72ef244c667920c874247aa32aa55845500aac8
> Author: Stefan Beller <sbeller@google.com>
> Date:   Thu Nov 17 16:14:46 2016 -0800
> 
>     submodule--helper: add intern-git-dir function
> 
>     When a submodule has its git dir inside the working dir, the submodule
>     support for checkout that we plan to add in a later patch will fail.
> 
>     Add functionality to migrate the git directory to be embedded
>     into the superprojects git directory.
> 
>     Signed-off-by: Stefan Beller <sbeller@google.com>
> 
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 4beeda5..4f31100 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1076,6 +1076,21 @@ static int resolve_remote_submodule_branch(int
> argc, const char **argv,
>         return 0;
>  }
> 
> +static int intern_git_dir(int argc, const char **argv, const char *prefix)
> +{
> +       int i;
> +       struct pathspec pathspec;
> +       struct module_list list = MODULE_LIST_INIT;
> +
> +       if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
> +               return 1;
> +
> +       for (i = 0; i < list.nr; i++)
> +               migrate_submodule_gitdir(list.entries[i]->name);
> +
> +       return 0;
> +}
> +
>  struct cmd_struct {
>         const char *cmd;
>         int (*fn)(int, const char **, const char *);
> @@ -1090,7 +1105,8 @@ static struct cmd_struct commands[] = {
>         {"resolve-relative-url", resolve_relative_url},
>         {"resolve-relative-url-test", resolve_relative_url_test},
>         {"init", module_init},
> -       {"remote-branch", resolve_remote_submodule_branch}
> +       {"remote-branch", resolve_remote_submodule_branch},
> +       {"intern-git-dir", intern_git_dir}
>  };
> 
>  int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
> diff --git a/submodule.c b/submodule.c
> index 45b9060..e513bba 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1335,3 +1335,42 @@ void prepare_submodule_repo_env(struct argv_array *out)
>         }
>         argv_array_push(out, "GIT_DIR=.git");
>  }
> +
> +/*
> + * Migrate the given submodule (and all its submodules recursively) from
> + * having its git directory within the working tree to the git dir nested
> + * in its superprojects git dir under modules/.
> + */
> +void migrate_submodule_gitdir(const char *path)
> +{
> +       char *old_git_dir;
> +       const char *new_git_dir;
> +       const struct submodule *sub;
> +
> +       struct child_process cp = CHILD_PROCESS_INIT;
> +       cp.git_cmd = 1;
> +       cp.no_stdin = 1;
> +       cp.dir = path;
> +       argv_array_pushl(&cp.args, "submodule", "foreach", "--recursive",
> +                       "git", "submodule--helper" "intern-git-dir", NULL);
> +
> +       if (run_command(&cp))
> +               die(_("Could not migrate git directory in submodule '%s'"),
> +                   path);
> +
> +       old_git_dir = xstrfmt("%s/.git", path);
> +       if (read_gitfile(old_git_dir))
> +               /* If it is an actual gitfile, it doesn't need migration. */
> +               goto out;
> +
> +       sub = submodule_from_path(null_sha1, path);

This should probably be checked to see if sub not NULL before
dereferencing it right?

> +       new_git_dir = git_common_path("modules/%s", sub->name);
> +
> +       if (rename(old_git_dir, new_git_dir) < 0)
> +               die_errno(_("Could not migrate git directory from %s to %s"),
> +                       old_git_dir, new_git_dir);
> +
> +       connect_work_tree_and_git_dir(path, new_git_dir);
> +out:
> +       free(old_git_dir);
> +}
> diff --git a/submodule.h b/submodule.h
> index aac202c..143ec18 100644
> --- a/submodule.h
> +++ b/submodule.h
> @@ -90,5 +90,6 @@ extern int parallel_submodules(void);
>   * retaining any config in the environment.
>   */
>  extern void prepare_submodule_repo_env(struct argv_array *out);
> +extern void migrate_submodule_gitdir(const char *path);
> 
>  #endif

-- 
Brandon Williams

  reply	other threads:[~2016-11-18 17:46 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15 23:06 [RFC PATCH 00/16] Checkout aware of Submodules! Stefan Beller
2016-11-15 23:06 ` [PATCH 01/16] submodule.h: add extern keyword to functions, break line before 80 Stefan Beller
2016-11-16 19:08   ` Junio C Hamano
2016-11-17 18:29     ` Stefan Beller
2016-11-15 23:06 ` [PATCH 02/16] submodule: modernize ok_to_remove_submodule to use argv_array Stefan Beller
2016-11-15 23:11   ` David Turner
2016-11-16 19:03     ` Junio C Hamano
2016-11-17 18:36       ` Stefan Beller
2016-11-15 23:06 ` [PATCH 03/16] submodule: use absolute path for computing relative path connecting Stefan Beller
2016-11-15 23:06 ` [PATCH 04/16] update submodules: add is_submodule_populated Stefan Beller
2016-11-15 23:20   ` Brandon Williams
2016-11-15 23:06 ` [PATCH 05/16] update submodules: add submodule config parsing Stefan Beller
2016-11-15 23:06 ` [PATCH 06/16] update submodules: add a config option to determine if submodules are updated Stefan Beller
2016-11-15 23:06 ` [PATCH 07/16] update submodules: introduce submodule_is_interesting Stefan Beller
2016-11-15 23:34   ` Brandon Williams
2016-11-16  0:14   ` David Turner
2016-11-17 20:03     ` Stefan Beller
     [not found]   ` <20161117105715.GC39230@book.hvoigt.net>
2016-11-17 20:08     ` Stefan Beller
2016-11-15 23:06 ` [PATCH 08/16] update submodules: add depopulate_submodule Stefan Beller
2016-11-15 23:44   ` Brandon Williams
2016-11-17 22:23     ` Stefan Beller
2016-11-17 22:29       ` Brandon Williams
2016-11-17 22:42         ` Stefan Beller
2016-11-18  0:16           ` Stefan Beller
2016-11-18 17:46             ` Brandon Williams [this message]
2016-11-18 18:25               ` Stefan Beller
     [not found]   ` <20161117111337.GD39230@book.hvoigt.net>
2016-11-17 22:28     ` Stefan Beller
2016-11-15 23:06 ` [PATCH 09/16] update submodules: add scheduling to update submodules Stefan Beller
2016-11-16  0:02   ` Brandon Williams
2016-11-16  0:07     ` David Turner
2016-11-18  0:28     ` Stefan Beller
2016-11-15 23:06 ` [PATCH 10/16] update submodules: is_submodule_checkout_safe Stefan Beller
2016-11-16  0:06   ` Brandon Williams
2016-11-15 23:06 ` [PATCH 11/16] teach unpack_trees() to remove submodule contents Stefan Beller
2016-11-16  0:14   ` Brandon Williams
     [not found]   ` <20161117133538.GF39230@book.hvoigt.net>
2016-11-18 19:25     ` Stefan Beller
2016-11-15 23:06 ` [PATCH 12/16] entry: write_entry to write populate submodules Stefan Beller
2016-11-15 23:06 ` [PATCH 13/16] submodule: teach unpack_trees() to update submodules Stefan Beller
2016-11-16  0:22   ` David Turner
2016-11-18 23:33     ` Stefan Beller
2016-11-21 18:12       ` David Turner
2016-11-16  0:25   ` Brandon Williams
2016-11-18 23:39     ` Stefan Beller
2016-11-15 23:06 ` [PATCH 14/16] checkout: recurse into submodules if asked to Stefan Beller
2016-11-16  0:33   ` Brandon Williams
2016-11-16 17:03   ` David Turner
2016-11-16 17:05   ` David Turner
2016-11-15 23:06 ` [PATCH 15/16] completion: add '--recurse-submodules' to checkout Stefan Beller
2016-11-15 23:06 ` [PATCH 16/16] checkout: add config option to recurse into submodules by default Stefan Beller
2016-12-03  6:13 ` [RFC PATCH 00/16] Checkout aware of Submodules! Xiaodong Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161118174607.GP66382@google.com \
    --to=bmwill@google.com \
    --cc=David.Turner@twosigma.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=mogulguy10@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).