FYI / RFC: submodules: introduce repo-like workflow
Subsystems (2)
PATCH 1/1 FYI / RFC: submodules: introduce repo-like workflow
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]". The repo tool is described as:
Repo unifies Git repositories when necessary, performs uploads to the Gerrit revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path.
In working with the Android source files, you use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands.
[1] https://source.android.com/setup/develop/
Submodules can also be understood as unifying Git repositories, even more, in the superproject the submodules have relationships between their versions, which the repo tool only provides in releases.
The repo tool does not provide these relationships between versions, but all the repositories (in case of Android think of ~1000 git repositories) are put in their place without depending on each other.
This comes with a couple of advantages and disadvantages:
* Many users are familiar with Git, but not submodules. Each repository can be used independently with Git and there is no need to update the superproject or the repo manifest for a change in a repository.
* It is easy to work with repositories with no version-control-dependencies if there are dependencies in the code. In case of Android the repositories are bound at natural boundaries. For example the linux kernel is one repository, as then upstream work is made easy for this repository. So it is desirable to keep an easy-as-repo workflow.
* Fetching changes ("repo sync") needs to fetch all repositories, as there is no central place that tracks what has changed. In a superproject git fetch can determine which submodules need fetching. In Androids case the daily change is only in a few repositories (think 10s), so migrating to a superproject would save an order of magnitude in fetch traffic for daily updates of developers.
* Sometimes when the dependencies are not on a clear repository boundary one would like to have git-bisect available across the different repositories, which repo cannot provide due to its design.
Internally we have the Gerrit as a central point, where the source of truth is found for a given repository.
This patch adds a new mode to submodule handling, where the superproject controls the existence of the submodule (just as current submodule handling), but the submodule HEAD is not detached, but following the same branch name as the superproject.
Current situation visualized:
superproject
HEAD -> "<branch name>" -> OID
|
submodule v
HEAD --------------------> OID
The OID in the submodule is controlled via the HEAD in the submodule that is set accordingly to the gitlink in the superproject. Confusion can arise when the (detached) HEAD in the submodule doesn't match the superprojects gitlink.
This patch visualized:
superproject
HEAD -> "<branch name>" -> OID
|
submodule v
HEAD -> "<branch name>" -> OID
As there is a central point of truth in our setup (our Gerrit installation) which keeps the superproject and the submodule branches in sync, this ought to look the same for the user; removing the "detached HEAD" in the submodule. git-status will still notice if there is an OID mismatch between the gitlink and the submodules branch, but that is a race condition and should be caught by Gerrit.
This changes the following commands in the superproject:
checkout -B/-b create branches in subs, too
checkout (-f): update branch in submodule (create if needed) and check
it out; Pass the argument down literally if it is a branch name (e.g. "checkout -f master" will run a
"checkout -f master" in the submodule as well)
clone: see checkout
reset --hard: see checkout
--- Documentation/git-checkout.txt | 13 +++-- Makefile | 1 + branch.c | 84 +++++++++++++++++++++++++++++++++ builtin.h | 1 + builtin/branch.c | 35 ++++++++++++++ builtin/checkout.c | 76 ++++++++++++++++++++++++------ builtin/clone.c | 12 ++++- builtin/reset.c | 41 ++++++++++++++-- entry.c | 43 +++++++++++++---- git-submodule.sh | 24 +++++++++- git.c | 1 + submodule-move-head.c | 81 ++++++++++++++++++++++++++++++++ submodule-move-head.h | 22 +++++++++ submodule.c | 14 ++++++ submodule.h | 9 +++- t/lib-submodule-update.sh | 86 +++++++++++++++++++++++++++++++++- t/t1013-read-tree-submodule.sh | 1 + t/t2013-checkout-submodule.sh | 4 ++ t/t7112-reset-submodule.sh | 5 ++ unpack-trees.c | 20 ++++++-- unpack-trees.h | 10 ++++ 21 files changed, 538 insertions(+), 45 deletions(-) create mode 100644 submodule-move-head.c create mode 100644 submodule-move-head.h
Documentation/git-checkout.txt +6 -7
@@ -268,13 +268,12 @@ section of linkgit:git-add[1] to learn how to operate the `--patch` mode. worktree. --[no-]recurse-submodules:: - Using --recurse-submodules will update the content of all initialized - submodules according to the commit recorded in the superproject. If - local modifications in a submodule would be overwritten the checkout - will fail unless `-f` is used. If nothing (or --no-recurse-submodules) - is used, the work trees of submodules will not be updated. - Just like linkgit:git-submodule[1], this will detach the - submodules HEAD. + Using --recurse-submodules will update the content and current + branch of all initialized submodules in addition to the + superproject. If local modifications in a submodule would be + overwritten, the checkout will fail unless `-f` is used. If + nothing (or --no-recurse-submodules) is used, the work trees of + submodules will not be updated. <branch>:: Branch to checkout; if it refers to a branch (i.e., a name that,
Makefile +1 -0
@@ -975,6 +975,7 @@ LIB_OBJS += streaming.o LIB_OBJS += string-list.o LIB_OBJS += submodule.o LIB_OBJS += submodule-config.o +LIB_OBJS += submodule-move-head.o LIB_OBJS += sub-process.o LIB_OBJS += symlinks.o LIB_OBJS += tag.o
branch.c +84 -0
117 lines not on this page · raw message
builtin.h +1 -0
@@ -135,6 +135,7 @@ extern int cmd_archive(int argc, const char **argv, const char *prefix);extern int cmd_bisect__helper (int argc,const char **argv,const char *prefix);extern int cmd_blame (int argc,const char **argv,const char *prefix);extern int cmd_branch (int argc,const char **argv,const char *prefix); +extern int cmd_branch_helper (int argc,const char **argv,const char *prefix);extern int cmd_bundle (int argc,const char **argv,const char *prefix);extern int cmd_cat_file (int argc,const char **argv,const char *prefix);extern int cmd_checkout (int argc,const char **argv,const char *prefix);
builtin/branch.c +35 -0
@@ -36,6 +36,11 @@ static const char * const builtin_branch_usage[] = { NULL }; +static const char *const builtin_branch_helper_usage[] = { +N_ ("git branch--helper" ), +NULL +}; +static const char *head;static struct object_id head_oid;
@@ -578,6 +583,36 @@ static int edit_branch_description(const char *branch_name)return 0 ; } +int cmd_branch_helper (int argc,const char **argv,const char *prefix) +{ +const char *name =NULL , *start_name =NULL ; +int force =0 , reflog =0 , clobber_head =0 , quiet =0 ; +enum branch_track track =BRANCH_TRACK_NEVER ; + +struct option options[] = { +OPT_STRING (0 ,"name" , &name,N_ ("" ),N_ ("" )), +OPT_STRING (0 ,"start_name" , &start_name,N_ ("" ),N_ ("" )), + +OPT_INTEGER (0 ,"force" , &force,N_ ("" )), +OPT_INTEGER (0 ,"reflog" , &reflog,N_ ("" )), +OPT_INTEGER (0 ,"clobber_head" , &clobber_head,N_ ("" )), +OPT_INTEGER (0 ,"quiet" , &quiet,N_ ("" )), + +/* implicit int -> enum conversion */ +OPT_INTEGER (0 ,"track" , &track,N_ ("" )), +OPT_END (), + }; + + argc =parse_options (argc, argv, prefix, options, + builtin_branch_helper_usage,0 ); +if (argc >0 ) +die (_ ("branchhelper doesn't know about %s" ), argv[0 ]); + +create_branch (name, start_name, force, clobber_head, reflog, + quiet, track); +return 0 ; +} +int cmd_branch (int argc,const char **argv,const char *prefix) {int delete =0 , rename =0 , copy =0 , force =0 , list =0 ;
builtin/checkout.c +61 -15
158 lines not on this page · raw message
builtin/clone.c +11 -1
@@ -28,6 +28,7 @@#include "run-command.h" #include "connected.h" #include "packfile.h" +#include "submodule.h" #include "list-objects-filter-options.h" #include "object-store.h"
@@ -738,7 +739,6 @@ static int checkout(int submodule_progress)if (!starts_with (head,"refs/heads/" ))die (_ ("HEAD not found below refs/heads!" )); } -free (head);/* We need to be in the new work tree for the checkout */ setup_work_tree ();
@@ -767,8 +767,17 @@ static int checkout(int submodule_progress) oid_to_hex(&oid), "1", NULL);if (!err && (option_recurse_submodules.nr >0 )) { +const char *branch;struct argv_array args =ARGV_ARRAY_INIT ;argv_array_pushl (&args,"submodule" ,"update" ,"--init" ,"--recursive" ,NULL ); +if (behave_google_repo_like ()) { +if (!strcmp (head,"HEAD" )) + ;/* detach HEAD in submodules, too. */ +else if (skip_prefix (head,"refs/heads/" , &branch)) +argv_array_pushl (&args,"--checkout-branch" , branch,NULL ); +else +BUG ("HEAD not found below refs/heads!" ); + }if (option_shallow_submodules ==1 )argv_array_push (&args,"--depth=1" );
@@ -786,6 +795,7 @@ static int checkout(int submodule_progress)argv_array_clear (&args); } +free (head);return err; }
builtin/reset.c +37 -4
82 lines not on this page · raw message
entry.c +35 -8
89 lines not on this page · raw message
git-submodule.sh +23 -1
@@ -424,6 +424,18 @@ fetch_in_submodule () ( esac ) +# usage: checkout_in_submoodule "$sm_path" "$command" "${branch:-}" "$rev" +checkout_in_submodule () ( + sanitize_submodule_env && + cd "$1" && + if test -n "$3" + then + $2 -B "$3" "$4" + else + $2 "$4" + fi +) + # # Update each submodule path to correct revision, using clone and checkout as needed #
@@ -476,6 +488,11 @@ cmd_update() --recursive) recursive=1 ;; + --checkout-branch) + update="checkout" + checkout_dest=$2 + shift + ;; --checkout) update="checkout" ;;
@@ -592,6 +609,11 @@ cmd_update() die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")" fi + if test -n "$checkout_dest" && test "$update_module" != checkout + then + die "Cannot use --checkout-branch with update mode '$update_module'" + fi + must_die_on_failure= case "$update_module" in checkout)
@@ -621,7 +643,7 @@ cmd_update() die "$(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")" esac - if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1") + if checkout_in_submodule "$sm_path" "$command" "$checkout_dest" "$sha1" then say "$say_msg" elif test -n "$must_die_on_failure"
git.c +1 -0
@@ -447,6 +447,7 @@ static struct cmd_struct commands[] = { { "bisect--helper", cmd_bisect__helper, RUN_SETUP }, { "blame", cmd_blame, RUN_SETUP }, { "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG }, + { "branch--helper", cmd_branch_helper, RUN_SETUP }, { "bundle", cmd_bundle, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "cat-file", cmd_cat_file, RUN_SETUP }, { "check-attr", cmd_check_attr, RUN_SETUP },
submodule-move-head.c new file +81 -0
81 lines not on this page · raw message
submodule-move-head.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef SUBMODULE_MOVE_HEAD_H +#define SUBMODULE_MOVE_HEAD_H + +struct unpack_trees_options ; + +/* NEEDSWORK: document */ +struct submodule_move_head_options { +int force; +const char *old_ref; +const char *new_ref; +const char *target_ref; +}; + +/* +* For use as unpack_trees_options.move_head. Parameters should be a +* struct submodule_move_head_options * in unpack_trees_options.unpack_data. +*/ +extern int unpack_trees_move_head (const struct unpack_trees_options *opt,const char *path,const char *old,const char *new,unsigned flags); + +extern void create_symref_in_submodule (const char *path,const char *symref,const char *target,const char *logmsg); + +#endif /* SUBMODULE_MOVE_HEAD_H */
submodule.c +14 -0
@@ -30,6 +30,17 @@ static int initialized_fetch_ref_tips;static struct oid_array ref_tips_before_fetch;static struct oid_array ref_tips_after_fetch; +int behave_google_repo_like (void ) +{ +static int google_repo_like =-1 ; + +if (google_repo_like ==-1 ) +git_config_get_bool ("submodule.repolike" , &google_repo_like); + +return google_repo_like; +} + +/* * Check if the .gitmodules file is unmerged. Parsing of the .gitmodules file * will be disabled because we can't guess what might be configured in
@@ -1676,6 +1687,9 @@ int submodule_move_head(const char *path,if (!(flags &SUBMODULE_MOVE_HEAD_DRY_RUN )) {if (new_head) { +if (flags &SUBMODULE_MOVE_HEAD_SKIP_REF_UPDATE ) + goto out; +child_process_init (&cp);/* also set the HEAD accordingly */ cp.git_cmd =1 ;
submodule.h +7 -2
@@ -120,8 +120,11 @@ int push_unpushed_submodules(struct oid_array *commits,*/ int submodule_to_gitdir (struct strbuf *buf,const char *submodule); -#define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0) -#define SUBMODULE_MOVE_HEAD_FORCE (1<<1) +#define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0) +#define SUBMODULE_MOVE_HEAD_FORCE (1<<1) +#define SUBMODULE_MOVE_HEAD_SKIP_REF_UPDATE (1<<2) + +/* NULL values for old or new represent the "missing" state. */ int submodule_move_head(const char *path, const char *old, const char *new_head,
@@ -146,4 +149,6 @@ void absorb_git_dir_into_superproject(const char *prefix,*/ const char *get_superproject_working_tree (void ); +int behave_google_repo_like (void ); +#endif
t/lib-submodule-update.sh +84 -2
105 lines not on this page · raw message
t/t1013-read-tree-submodule.sh +1 -0
@@ -7,6 +7,7 @@ test_description='read-tree can handle submodules' KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 +KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED="read-tree" test_submodule_switch_recursing_with_args "read-tree -u -m"
t/t2013-checkout-submodule.sh +4 -0
@@ -66,6 +66,10 @@ test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/ KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 test_submodule_switch_recursing_with_args "checkout" +KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED="checkout -B current" +test_submodule_switch_recursing_with_args "checkout -B current" +unset KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED + test_submodule_forced_switch_recursing_with_args "checkout -f" test_submodule_switch "git checkout"
t/t7112-reset-submodule.sh +5 -0
@@ -8,13 +8,18 @@ test_description='reset can handle submodules' KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1 KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 +KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED="reset" +KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED=1 test_submodule_switch_recursing_with_args "reset --keep" +unset KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED test_submodule_forced_switch_recursing_with_args "reset --hard" +KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED=1 test_submodule_switch "git reset --keep" +unset KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED test_submodule_switch "git reset --merge" test_submodule_forced_switch "git reset --hard"
unpack-trees.c +15 -5
@@ -254,6 +254,16 @@ static void display_error_msgs(struct unpack_trees_options *o)fprintf (stderr,_ ("Aborting\n" )); } +static int move_head (const struct unpack_trees_options *o,const char *path,const char *old,const char *new,unsigned flags) +{ +if (behave_google_repo_like ()) { +if (!o->move_head) +return submodule_move_head (path, old, new, flags); +return o->move_head (o, path, old, new, flags); + }else +return submodule_move_head (path, old, new, flags); +} + static int check_submodule_move_head(const struct cache_entry *ce, const char *old_id, const char *new_id,
@@ -268,7 +278,7 @@ static int check_submodule_move_head(const struct cache_entry *ce,if (o->reset) flags |=SUBMODULE_MOVE_HEAD_FORCE ; -if (submodule_move_head (ce->name, old_id, new_id, flags)) +if (move_head (o, ce->name, old_id, new_id, flags))return o->gently ?-1 :add_rejected_path (o,ERROR_WOULD_LOSE_SUBMODULE , ce->name);return 0 ;
@@ -304,12 +314,12 @@ static void load_gitmodules_file(struct index_state *index,* Unlink the last component and schedule the leading directories for * removal, such that empty directories get removed. */ -static void unlink_entry (const struct cache_entry *ce) +static void unlink_entry (const struct unpack_trees_options *o,const struct cache_entry *ce) {const struct submodule *sub =submodule_from_ce (ce);if (sub) {/* state.force is set at the caller. */ -submodule_move_head (ce->name,"HEAD" ,NULL , +move_head (o, ce->name,"HEAD" ,NULL ,SUBMODULE_MOVE_HEAD_FORCE ); }if (!check_leading_path (ce->name,ce_namelen (ce)))
@@ -408,7 +418,7 @@ static int check_updates(struct unpack_trees_options *o)if (ce->ce_flags &CE_WT_REMOVE ) {display_progress (progress, ++cnt);if (o->update && !o->dry_run) -unlink_entry (ce); +unlink_entry (o, ce); } }remove_marked_cache_entries (index);
@@ -450,7 +460,7 @@ static int check_updates(struct unpack_trees_options *o)display_progress (progress, ++cnt); ce->ce_flags &= ~CE_UPDATE ;if (o->update && !o->dry_run) { - errs |=checkout_entry (ce, &state,NULL ); + errs |=unpack_trees_checkout_entry (o, ce, &state,NULL ); } } }
unpack-trees.h +10 -0
@@ -9,12 +9,15 @@#define MAX_UNPACK_TREES 8struct cache_entry ; +struct tree_desc ;struct unpack_trees_options ;struct exclude_list ;typedef int (*merge_fn_t )(const struct cache_entry *const *src,struct unpack_trees_options *options); +typedef int (*submodule_move_head_fn )(const struct unpack_trees_options *o,const char *path,const char *old,const char *new,unsigned flags); +enum unpack_trees_error_types {ERROR_WOULD_OVERWRITE =0 ,ERROR_NOT_UPTODATE_FILE ,
@@ -65,6 +68,7 @@ struct unpack_trees_options {struct dir_struct *dir;struct pathspec *pathspec;merge_fn_t fn; +submodule_move_head_fn move_head;const char *msgs[NB_UNPACK_TREES_ERROR_TYPES ];struct argv_array msgs_to_free;/*
@@ -86,6 +90,12 @@ struct unpack_trees_options {struct exclude_list *el;/* for internal use */ }; +/* defined in entry.c, for internal use */ +int unpack_trees_checkout_entry (struct unpack_trees_options *o, +struct cache_entry *ce, +const struct checkout *state, +char *topath); +int unpack_trees (unsigned n,struct tree_desc *t,struct unpack_trees_options *options);
Signature · 1 line
2.19.0
(dropping cc-s to my internal address that I don't use on this list
and to [email protected] which bounces)
Hi,
Quoted 8 lines · Stefan Beller
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]". The repo tool is described as:
Repo unifies Git repositories when necessary, performs uploads to the Gerrit revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path.
[...]
Quoted 9 lines
Submodules can also be understood as unifying Git repositories, even more, in the superproject the submodules have relationships between their versions, which the repo tool only provides in releases.
The repo tool does not provide these relationships between versions, but all the repositories (in case of Android think of ~1000 git repositories) are put in their place without depending on each other.
This comes with a couple of advantages and disadvantages:
Thanks for describing this background.
[...]
Quoted 9 lines
This changes the following commands in the superproject:
checkout -B/-b create branches in subs, too
checkout (-f): update branch in submodule (create if needed) and check
it out; Pass the argument down literally if it is a branch name (e.g. "checkout -f master" will run a
"checkout -f master" in the submodule as well)
clone: see checkout
reset --hard: see checkout
As you mentioned, I've been using this submodule.repoLike=true mode for my own use for a while. You did a nice job of explaining on how it fits into a Gerrit-driven workflow; I'd like to add that I find it pleasant in non-Gerrit-driven contexts as well.
The primary difference from repoLike=false is that this makes the normal state to have branches checked out in submodules. For example, if I run
git checkout --recurse-submodules -B master origin/master
then this will create and check out a "master" branch in all submodules instead of only in the superproject. This helps avoid some issues in Git's submodule handling where submodule commits can be pruned if they have not been checked out in a while because there is no ref pointing to them.
Some next steps:
- now that we have a repository object, some of the implementation can be simplified and made more robust. I expect that will also make these patches easier to review
- also in the direction of reviewability, at that point we may want to split this into multiple patches
- gitsubmodules.txt and config.txt should describe the new option, to help new users understand what this new repoLike workflow does
- there are some edge cases in the UX that get... messy that I should describe in another message
All that said, thanks for sending this out, and I'd be happy to hear from any interested people --- feedback from anyone adventurous enough to try this out would be very welcome.
Happy hacking,
Jonathan
Quoted 19 lines · Jonathan Nieder
(dropping cc-s to my internal address that I don't use on this list
and to [email protected] which bounces)
Hi,Quoted 8 lines · Stefan Beller
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]". The repo tool is described as:
Repo unifies Git repositories when necessary, performs uploads to the Gerrit revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path.
[...]
Quoted 4 lines
Submodules can also be understood as unifying Git repositories, even more, in the superproject the submodules have relationships between their versions, which the repo tool only provides in releases.
Quoted 7 lines
Quoted 5 lines
The repo tool does not provide these relationships between versions, but all the repositories (in case of Android think of ~1000 git repositories) are put in their place without depending on each other.
This comes with a couple of advantages and disadvantages:
Thanks for describing this background.
Thanks for this. I probably won't be reading this before other topics, but I've often found that changes from google were lacking the backstory to make sense of them as a coherent whole.
For example, a patch that says "Instead of detaching at the commit recorded in the superproject, check out the branch with the same name, even if it points at a different commit. Here is the write up of what it does in the Documentation/ and code" is hard to judge beyond checking if the code does what it claims to do and if the docs describe what the code does---without backstory like this that talks about how individual small pieces fit within the plan for the whole thing, judging if that "what it claims to do" is even sensible is impossible.
Quoted 14 lines · Stefan Beller
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]". The repo tool is described as:
Repo unifies Git repositories when necessary, performs uploads to the Gerrit revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path.
In working with the Android source files, you use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
Quoted 4 lines
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands.
Some questions just out of curiosity, not for this patch in particular:
Those docs seem to describe the situation without this patch, with this patch is the repo tool fully replaced?
How are you planning to migrate from repo to this on a repository-data basis, does gerrit also populate .gitmodules files appropriately, which your clone --recurse-submodules will pick up, but repo will just ignore, so you can use the two in parallel?
Now "repo init -u" takes a URL to a manifest of repositories to stitch together, I've understood from past conversations (but am not sure) that this is used e.g. by downstream Android vendors so they can use what Google's using + whatever they have in-house, i.e. make the manifest the set of open source repos plus some (e.g. drivers specific to their device). How is that sort of workflow going to work where you (presumably) have do that via .gitmodules + commit entries in trees? They run their own Gerrit install with some magic to sync back & forth?
I assume that now the recursive "checkout" relies on all the origin/HEAD symbolic refs pointing to "master", but how is this going to deal with incorporating a repo whose main branch has a different name? E.g. "trunk" or "blead"? Perhaps some interaction with checkout.defaultRemote + submodule.<name>.branch=<NAME> could make "git checkout :mainbranch" DWYM.
Quoted 6 lines
* Fetching changes ("repo sync") needs to fetch all repositories, as there is no central place that tracks what has changed. In a superproject git fetch can determine which submodules need fetching. In Androids case the daily change is only in a few repositories (think 10s), so migrating to a superproject would save an order of magnitude in fetch traffic for daily updates of developers.
Interesting that in all this time with the reliance on a central server repo wasn't already asking some custom API "what repos changed since xyz time" to narrow that down, but hey, .gitmodules + commit entries in trees will do it for you.
Quoted 3 lines
* Sometimes when the dependencies are not on a clear repository boundary one would like to have git-bisect available across the different repositories, which repo cannot provide due to its design.
I assume that you're not upgrading independently to e.g. every single linux commit, just stable releases, so does bisecting deal with knowing that e.g. a breakage occurred when linux.git was updated from v4.10 to v4.12, and then to go within the repo itself and bisect from there, or is that done manually?
Quoted 21 lines · Ævar Arnfjörð Bjarmason
Quoted 17 lines · Stefan Beller
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]". The repo tool is described as:
Repo unifies Git repositories when necessary, performs uploads to the Gerrit revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path.
In working with the Android source files, you use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands.
Quoted 6 lines
Quoted 1 line
Some questions just out of curiosity, not for this patch in particular:
Those docs seem to describe the situation without this patch, with this patch is the repo tool fully replaced?
Yeah I started by describing the status quo. Some points to add:
* The repo UX looks very similar to perforce, as that was used internally at Google at the time a lot. Git wasn't around for long in the days of early Android. Now that Git is well known, new grads joining are more likely to know Git than perforce.
* repo has no tests because it started as a small script
* maintenance/releases of repo are not ideal.
So yes, one of our long term goals is to replace repo with Git-only (on the client side) workflow.
Quoted 2 lines
How are you planning to migrate from repo to this on a repository-data basis
We don't plan to migrate the existing clients. You'd have to re-clone.
Quoted 3 lines
, does gerrit also populate .gitmodules files appropriately, which your clone --recurse-submodules will pick up, but repo will just ignore, so you can use the two in parallel?
Gerrit has native support to update submodules in a superproject. So if you submit code to a project that is a submodule of a superproject the superproject updates its gitlink. (and if you use a topic based workflow to submit to two projects, it will show up as an atomic update in the superproject by having just one commit updating two gitlinks)
Also Gerrit has a plugin "supermanifest" [1], which tracks repo manifests and mirrors changes from the manifest into the superproject, e.g. adding a new project to the manifest will add a new submodule to the superproject.
[1] https://gerrit.googlesource.com/plugins/supermanifest/
With both Gerrits internal superproject subscription and that plugin it should be possible to use repo or git-submodule in parallel (on an organisational level, i.e. you choose one of them, and your coworker chooses the other one)
Quoted 7 lines
Now "repo init -u" takes a URL to a manifest of repositories to stitch together, I've understood from past conversations (but am not sure) that this is used e.g. by downstream Android vendors so they can use what Google's using + whatever they have in-house, i.e. make the manifest the set of open source repos plus some (e.g. drivers specific to their device). How is that sort of workflow going to work where you (presumably) have do that via .gitmodules + commit entries in trees?
The manifest is tracked in its own manifest repo, so today they fork that project, with the superproject you'd fork the superproject and modify the .gitmodules file as needed.
Quoted 5 lines
They run their own Gerrit install with some magic to sync back & forth?
I assume that now the recursive "checkout" relies on all the origin/HEAD symbolic refs pointing to "master", but how is this going to deal with incorporating a repo whose main branch has a different name?
Change the name? Or pin it via sha1.
Quoted 11 lines
E.g. "trunk" or "blead"? Perhaps some interaction with checkout.defaultRemote + submodule.<name>.branch=<NAME> could make "git checkout :mainbranch" DWYM.
Quoted 6 lines
* Fetching changes ("repo sync") needs to fetch all repositories, as there is no central place that tracks what has changed. In a superproject git fetch can determine which submodules need fetching. In Androids case the daily change is only in a few repositories (think 10s), so migrating to a superproject would save an order of magnitude in fetch traffic for daily updates of developers.
Quoted 4 lines
Interesting that in all this time with the reliance on a central server repo wasn't already asking some custom API "what repos changed since xyz time" to narrow that down, but hey, .gitmodules + commit entries in trees will do it for you.
It's complicated. Shawn really grew to dislike the repo tool and wanted to have it gone as quickly as possible, so no hacks that extend its life. ;-) I would prefer to keep that stance as any hack in there would grow into a nightmare down the road.
Quoted 9 lines
Quoted 3 lines
* Sometimes when the dependencies are not on a clear repository boundary one would like to have git-bisect available across the different repositories, which repo cannot provide due to its design.
I assume that you're not upgrading independently to e.g. every single linux commit, just stable releases, so does bisecting deal with knowing that e.g. a breakage occurred when linux.git was updated from v4.10 to v4.12, and then to go within the repo itself and bisect from there, or is that done manually?
We currently have no submodule support in bisect, but that is open to future contribution. But with relations between submodules via the superproject it is at least possible to bisect precisely, whereas in repo the projects are unrelated to each other and it becomes a political issue if A broke B or B broke A.
Thanks for taking time to read and think through the concept here,
Stefan
Hi,
Quoted 2 lines · Stefan Beller
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]".
Thanks again for writing and explaining it. Here's an updated version, basically identical (just rebased). "git range-diff" shows mostly context lines affected, so this really is a minor update.
I suspect the *next* time this hits the list will be more interesting, since we can start making use of the repository API.
Thoughts of all kinds welcome, as always.
-- >8 --
From: Stefan Beller <[email protected]>
Date: Mon, 4 Dec 2017 15:47:40 -0800
Internally we have rolled out this as an experiment for "submodules replacing the repo tool[1]". The repo tool is described as:
Repo unifies Git repositories when necessary, performs uploads to the Gerrit revision control system, and automates parts of the Android development workflow. Repo is not meant to replace Git, only to make it easier to work with Git in the context of Android. The repo command is an executable Python script that you can put anywhere in your path.
In working with the Android source files, you use Repo for across-network operations. For example, with a single Repo command you can download files from multiple repositories into your local working directory.
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands.
[1] https://source.android.com/setup/develop/
Submodules can also be understood as unifying Git repositories, even more, in the superproject the submodules have relationships between their versions, which the repo tool only provides in releases.
The repo tool does not provide these relationships between versions, but all the repositories (in case of Android think of ~1000 git repositories) are put in their place without depending on each other.
This comes with a couple of advantages and disadvantages:
* Many users are familiar with Git, but not submodules. Each repository can be used independently with Git and there is no need to update the superproject or the repo manifest for a change in a repository.
* It is easy to work with repositories with no version-control-dependencies if there are dependencies in the code. In case of Android the repositories are bound at natural boundaries. For example the linux kernel is one repository, as then upstream work is made easy for this repository. So it is desirable to keep an easy-as-repo workflow.
* Fetching changes ("repo sync") needs to fetch all repositories, as there is no central place that tracks what has changed. In a superproject git fetch can determine which submodules need fetching. In Androids case the daily change is only in a few repositories (think 10s), so migrating to a superproject would save an order of magnitude in fetch traffic for daily updates of developers.
* Sometimes when the dependencies are not on a clear repository boundary one would like to have git-bisect available across the different repositories, which repo cannot provide due to its design.
Internally we have the Gerrit as a central point, where the source of truth is found for a given repository.
This patch adds a new mode to submodule handling, where the superproject controls the existence of the submodule (just as current submodule handling), but the submodule HEAD is not detached, but following the same branch name as the superproject.
Current situation visualized:
superproject
HEAD -> "<branch name>" -> OID
|
submodule v
HEAD --------------------> OID
The OID in the submodule is controlled via the HEAD in the submodule that is set accordingly to the gitlink in the superproject. Confusion can arise when the (detached) HEAD in the submodule doesn't match the superprojects gitlink.
This patch visualized:
superproject
HEAD -> "<branch name>" -> OID
|
submodule v
HEAD -> "<branch name>" -> OID
As there is a central point of truth in our setup (our Gerrit installation) which keeps the superproject and the submodule branches in sync, this ought to look the same for the user; removing the "detached HEAD" in the submodule. git-status will still notice if there is an OID mismatch between the gitlink and the submodules branch, but that is a race condition and should be caught by Gerrit.
This changes the following commands in the superproject:
checkout -B/-b create branches in subs, too
checkout (-f): update branch in submodule (create if needed) and check
it out; Pass the argument down literally if it is a branch name (e.g. "checkout -f master" will run a
"checkout -f master" in the submodule as well)
clone: see checkout
reset --hard: see checkout
--- Documentation/git-checkout.txt | 13 +++-- Makefile | 1 + branch.c | 84 +++++++++++++++++++++++++++++++++ builtin.h | 1 + builtin/branch.c | 35 ++++++++++++++ builtin/checkout.c | 76 ++++++++++++++++++++++++------ builtin/clone.c | 12 ++++- builtin/reset.c | 41 ++++++++++++++-- entry.c | 51 +++++++++++++------- git-submodule.sh | 24 +++++++++- git.c | 1 + submodule-move-head.c | 81 ++++++++++++++++++++++++++++++++ submodule-move-head.h | 22 +++++++++ submodule.c | 14 ++++++ submodule.h | 8 +++- t/lib-submodule-update.sh | 86 +++++++++++++++++++++++++++++++++- t/t1013-read-tree-submodule.sh | 1 + t/t2013-checkout-submodule.sh | 4 ++ t/t7112-reset-submodule.sh | 5 ++ unpack-trees.c | 20 ++++++-- unpack-trees.h | 9 ++++ 21 files changed, 536 insertions(+), 53 deletions(-) create mode 100644 submodule-move-head.c create mode 100644 submodule-move-head.h
Documentation/git-checkout.txt +6 -7
@@ -268,13 +268,12 @@ section of linkgit:git-add[1] to learn how to operate the `--patch` mode. worktree. --[no-]recurse-submodules:: - Using --recurse-submodules will update the content of all initialized - submodules according to the commit recorded in the superproject. If - local modifications in a submodule would be overwritten the checkout - will fail unless `-f` is used. If nothing (or --no-recurse-submodules) - is used, the work trees of submodules will not be updated. - Just like linkgit:git-submodule[1], this will detach the - submodules HEAD. + Using --recurse-submodules will update the content and current + branch of all initialized submodules in addition to the + superproject. If local modifications in a submodule would be + overwritten, the checkout will fail unless `-f` is used. If + nothing (or --no-recurse-submodules) is used, the work trees of + submodules will not be updated. --no-guess:: Do not attempt to create a branch if a remote tracking branch
Makefile +1 -0
@@ -989,6 +989,7 @@ LIB_OBJS += streaming.o LIB_OBJS += string-list.o LIB_OBJS += submodule.o LIB_OBJS += submodule-config.o +LIB_OBJS += submodule-move-head.o LIB_OBJS += sub-process.o LIB_OBJS += symlinks.o LIB_OBJS += tag.o
branch.c +84 -0
117 lines not on this page · raw message
builtin.h +1 -0
@@ -135,6 +135,7 @@ extern int cmd_archive(int argc, const char **argv, const char *prefix);extern int cmd_bisect__helper (int argc,const char **argv,const char *prefix);extern int cmd_blame (int argc,const char **argv,const char *prefix);extern int cmd_branch (int argc,const char **argv,const char *prefix); +extern int cmd_branch_helper (int argc,const char **argv,const char *prefix);extern int cmd_bundle (int argc,const char **argv,const char *prefix);extern int cmd_cat_file (int argc,const char **argv,const char *prefix);extern int cmd_checkout (int argc,const char **argv,const char *prefix);
builtin/branch.c +35 -0
@@ -36,6 +36,11 @@ static const char * const builtin_branch_usage[] = { NULL }; +static const char *const builtin_branch_helper_usage[] = { +N_ ("git branch--helper" ), +NULL +}; +static const char *head;static struct object_id head_oid;
@@ -578,6 +583,36 @@ static int edit_branch_description(const char *branch_name)return 0 ; } +int cmd_branch_helper (int argc,const char **argv,const char *prefix) +{ +const char *name =NULL , *start_name =NULL ; +int force =0 , reflog =0 , clobber_head =0 , quiet =0 ; +enum branch_track track =BRANCH_TRACK_NEVER ; + +struct option options[] = { +OPT_STRING (0 ,"name" , &name,N_ ("" ),N_ ("" )), +OPT_STRING (0 ,"start_name" , &start_name,N_ ("" ),N_ ("" )), + +OPT_INTEGER (0 ,"force" , &force,N_ ("" )), +OPT_INTEGER (0 ,"reflog" , &reflog,N_ ("" )), +OPT_INTEGER (0 ,"clobber_head" , &clobber_head,N_ ("" )), +OPT_INTEGER (0 ,"quiet" , &quiet,N_ ("" )), + +/* implicit int -> enum conversion */ +OPT_INTEGER (0 ,"track" , &track,N_ ("" )), +OPT_END (), + }; + + argc =parse_options (argc, argv, prefix, options, + builtin_branch_helper_usage,0 ); +if (argc >0 ) +die (_ ("branchhelper doesn't know about %s" ), argv[0 ]); + +create_branch (the_repository, name, start_name, force, clobber_head, + reflog, quiet, track); +return 0 ; +} +int cmd_branch (int argc,const char **argv,const char *prefix) {int delete =0 , rename =0 , copy =0 , force =0 , list =0 ;
builtin/checkout.c +61 -15
158 lines not on this page · raw message
builtin/clone.c +11 -1
@@ -28,6 +28,7 @@#include "run-command.h" #include "connected.h" #include "packfile.h" +#include "submodule.h" #include "list-objects-filter-options.h" #include "object-store.h"
@@ -744,7 +745,6 @@ static int checkout(int submodule_progress)if (!starts_with (head,"refs/heads/" ))die (_ ("HEAD not found below refs/heads!" )); } -free (head);/* We need to be in the new work tree for the checkout */ setup_work_tree ();
@@ -773,8 +773,17 @@ static int checkout(int submodule_progress) oid_to_hex(&oid), "1", NULL);if (!err && (option_recurse_submodules.nr >0 )) { +const char *branch;struct argv_array args =ARGV_ARRAY_INIT ;argv_array_pushl (&args,"submodule" ,"update" ,"--init" ,"--recursive" ,NULL ); +if (behave_google_repo_like ()) { +if (!strcmp (head,"HEAD" )) + ;/* detach HEAD in submodules, too. */ +else if (skip_prefix (head,"refs/heads/" , &branch)) +argv_array_pushl (&args,"--checkout-branch" , branch,NULL ); +else +BUG ("HEAD not found below refs/heads!" ); + }if (option_shallow_submodules ==1 )argv_array_push (&args,"--depth=1" );
@@ -792,6 +801,7 @@ static int checkout(int submodule_progress)argv_array_clear (&args); } +free (head);return err; }
builtin/reset.c +37 -4
82 lines not on this page · raw message
entry.c +35 -16
97 lines not on this page · raw message
git-submodule.sh +23 -1
@@ -434,6 +434,18 @@ fetch_in_submodule () ( esac ) +# usage: checkout_in_submoodule "$sm_path" "$command" "${branch:-}" "$rev" +checkout_in_submodule () ( + sanitize_submodule_env && + cd "$1" && + if test -n "$3" + then + $2 -B "$3" "$4" + else + $2 "$4" + fi +) + # # Update each submodule path to correct revision, using clone and checkout as needed #
@@ -486,6 +498,11 @@ cmd_update() --recursive) recursive=1 ;; + --checkout-branch) + update="checkout" + checkout_dest=$2 + shift + ;; --checkout) update="checkout" ;;
@@ -602,6 +619,11 @@ cmd_update() die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")" fi + if test -n "$checkout_dest" && test "$update_module" != checkout + then + die "Cannot use --checkout-branch with update mode '$update_module'" + fi + must_die_on_failure= case "$update_module" in checkout)
@@ -631,7 +653,7 @@ cmd_update() die "$(eval_gettext "Invalid update mode '$update_module' for submodule path '$path'")" esac - if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1") + if checkout_in_submodule "$sm_path" "$command" "$checkout_dest" "$sha1" then say "$say_msg" elif test -n "$must_die_on_failure"
git.c +1 -0
@@ -450,6 +450,7 @@ static struct cmd_struct commands[] = { { "bisect--helper", cmd_bisect__helper, RUN_SETUP }, { "blame", cmd_blame, RUN_SETUP }, { "branch", cmd_branch, RUN_SETUP | DELAY_PAGER_CONFIG }, + { "branch--helper", cmd_branch_helper, RUN_SETUP }, { "bundle", cmd_bundle, RUN_SETUP_GENTLY | NO_PARSEOPT }, { "cat-file", cmd_cat_file, RUN_SETUP }, { "check-attr", cmd_check_attr, RUN_SETUP },
submodule-move-head.c new file +81 -0
81 lines not on this page · raw message
submodule-move-head.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef SUBMODULE_MOVE_HEAD_H +#define SUBMODULE_MOVE_HEAD_H + +struct unpack_trees_options ; + +/* NEEDSWORK: document */ +struct submodule_move_head_options { +int force; +const char *old_ref; +const char *new_ref; +const char *target_ref; +}; + +/* +* For use as unpack_trees_options.move_head. Parameters should be a +* struct submodule_move_head_options * in unpack_trees_options.unpack_data. +*/ +extern int unpack_trees_move_head (const struct unpack_trees_options *opt,const char *path,const char *old,const char *new,unsigned flags); + +extern void create_symref_in_submodule (const char *path,const char *symref,const char *target,const char *logmsg); + +#endif /* SUBMODULE_MOVE_HEAD_H */
submodule.c +14 -0
@@ -30,6 +30,17 @@ static int initialized_fetch_ref_tips;static struct oid_array ref_tips_before_fetch;static struct oid_array ref_tips_after_fetch; +int behave_google_repo_like (void ) +{ +static int google_repo_like =-1 ; + +if (google_repo_like ==-1 ) +git_config_get_bool ("submodule.repolike" , &google_repo_like); + +return google_repo_like; +} + +/* * Check if the .gitmodules file is unmerged. Parsing of the .gitmodules file * will be disabled because we can't guess what might be configured in
@@ -1703,6 +1714,9 @@ int submodule_move_head(const char *path,if (!(flags &SUBMODULE_MOVE_HEAD_DRY_RUN )) {if (new_head) { +if (flags &SUBMODULE_MOVE_HEAD_SKIP_REF_UPDATE ) + goto out; +child_process_init (&cp);/* also set the HEAD accordingly */ cp.git_cmd =1 ;
submodule.h +6 -2
@@ -124,8 +124,10 @@ int push_unpushed_submodules(struct repository *r,*/ int submodule_to_gitdir (struct strbuf *buf,const char *submodule); -#define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0) -#define SUBMODULE_MOVE_HEAD_FORCE (1<<1) +#define SUBMODULE_MOVE_HEAD_DRY_RUN (1<<0) +#define SUBMODULE_MOVE_HEAD_FORCE (1<<1) +#define SUBMODULE_MOVE_HEAD_SKIP_REF_UPDATE (1<<2) + int submodule_move_head(const char *path, const char *old, const char *new_head,
@@ -150,4 +152,6 @@ void absorb_git_dir_into_superproject(const char *prefix,*/ const char *get_superproject_working_tree (void ); +int behave_google_repo_like (void ); +#endif
t/lib-submodule-update.sh +84 -2
100 lines not on this page · raw message
t/t1013-read-tree-submodule.sh +1 -0
@@ -7,6 +7,7 @@ test_description='read-tree can handle submodules' KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 +KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED="read-tree" test_submodule_switch_recursing_with_args "read-tree -u -m"
t/t2013-checkout-submodule.sh +4 -0
@@ -66,6 +66,10 @@ test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/ KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 test_submodule_switch_recursing_with_args "checkout" +KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED="checkout -B current" +test_submodule_switch_recursing_with_args "checkout -B current" +unset KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED + test_submodule_forced_switch_recursing_with_args "checkout -f" test_submodule_switch "git checkout"
t/t7112-reset-submodule.sh +5 -0
@@ -8,13 +8,18 @@ test_description='reset can handle submodules' KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1 KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 +KNOWN_DIFFERENCE_SUBMODULE_REFS_NOT_UPDATED="reset" +KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED=1 test_submodule_switch_recursing_with_args "reset --keep" +unset KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED test_submodule_forced_switch_recursing_with_args "reset --hard" +KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED=1 test_submodule_switch "git reset --keep" +unset KNOWN_FAILURE_SUBMODULE_REFS_NOT_UPDATED test_submodule_switch "git reset --merge" test_submodule_forced_switch "git reset --hard"
unpack-trees.c +15 -5
@@ -254,6 +254,16 @@ static void display_error_msgs(struct unpack_trees_options *o)fprintf (stderr,_ ("Aborting\n" )); } +static int move_head (const struct unpack_trees_options *o,const char *path,const char *old,const char *new,unsigned flags) +{ +if (behave_google_repo_like ()) { +if (!o->move_head) +return submodule_move_head (path, old, new, flags); +return o->move_head (o, path, old, new, flags); + }else +return submodule_move_head (path, old, new, flags); +} + static int check_submodule_move_head(const struct cache_entry *ce, const char *old_id, const char *new_id,
@@ -268,7 +278,7 @@ static int check_submodule_move_head(const struct cache_entry *ce,if (o->reset) flags |=SUBMODULE_MOVE_HEAD_FORCE ; -if (submodule_move_head (ce->name, old_id, new_id, flags)) +if (move_head (o, ce->name, old_id, new_id, flags))return o->gently ?-1 :add_rejected_path (o,ERROR_WOULD_LOSE_SUBMODULE , ce->name);return 0 ;
@@ -304,12 +314,12 @@ static void load_gitmodules_file(struct index_state *index,* Unlink the last component and schedule the leading directories for * removal, such that empty directories get removed. */ -static void unlink_entry (const struct cache_entry *ce) +static void unlink_entry (const struct unpack_trees_options *o,const struct cache_entry *ce) {const struct submodule *sub =submodule_from_ce (ce);if (sub) {/* state.force is set at the caller. */ -submodule_move_head (ce->name,"HEAD" ,NULL , +move_head (o, ce->name,"HEAD" ,NULL ,SUBMODULE_MOVE_HEAD_FORCE ); }if (!check_leading_path (ce->name,ce_namelen (ce)))
@@ -408,7 +418,7 @@ static int check_updates(struct unpack_trees_options *o)if (ce->ce_flags &CE_WT_REMOVE ) {display_progress (progress, ++cnt);if (o->update && !o->dry_run) -unlink_entry (ce); +unlink_entry (o, ce); } }remove_marked_cache_entries (index);
@@ -450,7 +460,7 @@ static int check_updates(struct unpack_trees_options *o)display_progress (progress, ++cnt); ce->ce_flags &= ~CE_UPDATE ;if (o->update && !o->dry_run) { - errs |=checkout_entry (ce, &state,NULL ); + errs |=unpack_trees_checkout_entry (o, ce, &state,NULL ); } } }
unpack-trees.h +9 -0
@@ -9,12 +9,15 @@#define MAX_UNPACK_TREES 8struct cache_entry ; +struct tree_desc ;struct unpack_trees_options ;struct exclude_list ;typedef int (*merge_fn_t )(const struct cache_entry *const *src,struct unpack_trees_options *options); +typedef int (*submodule_move_head_fn )(const struct unpack_trees_options *o,const char *path,const char *old,const char *new,unsigned flags); +enum unpack_trees_error_types {ERROR_WOULD_OVERWRITE =0 ,ERROR_NOT_UPTODATE_FILE ,
@@ -65,6 +68,7 @@ struct unpack_trees_options {struct dir_struct *dir;struct pathspec *pathspec;merge_fn_t fn; +submodule_move_head_fn move_head;const char *msgs[NB_UNPACK_TREES_ERROR_TYPES ];struct argv_array msgs_to_free;/*
@@ -86,6 +90,11 @@ struct unpack_trees_options {struct exclude_list *el;/* for internal use */ }; +/* defined in entry.c, for internal use */ +int unpack_trees_checkout_entry (struct unpack_trees_options *o, +struct cache_entry *ce, +const struct checkout *state,char *topath); +int unpack_trees (unsigned n,struct tree_desc *t,struct unpack_trees_options *options);
Signature · 1 line
2.20.1.97.g81188d93c3