From ff9445be4702d6cf6e5e8c202a15066ca355989b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:49 +0700 Subject: revision.h: new flag in struct rev_info wrt. worktree-related refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The revision walker can walk through per-worktree refs like HEAD or SHA-1 references in the index. These currently are from the current worktree only. This new flag is added to change rev-list behavior in this regard: When single_worktree is set, only current worktree is considered. When it is not set (which is the default), all worktrees are considered. The default is chosen so because the two big components that rev-list works with are object database (entirely shared between worktrees) and refs (mostly shared). It makes sense that default behavior goes per-repo too instead of per-worktree. The flag will eventually be exposed as a rev-list argument with documents. For now it stays internal until the new behavior is fully implemented. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/revision.h b/revision.h index bc18487..3a3d3e2 100644 --- a/revision.h +++ b/revision.h @@ -96,6 +96,7 @@ struct rev_info { topo_order:1, simplify_merges:1, simplify_by_decoration:1, + single_worktree:1, tag_objects:1, tree_objects:1, blob_objects:1, -- cgit v0.10.2-6-g49f6 From ee394bd376e833d8e9e38f81c57f6b4a370e8a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:50 +0700 Subject: refs.c: use is_dir_sep() in resolve_gitlink_ref() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "submodule" argument in this function is a path, which can have either '/' or '\\' as a separator. Use is_dir_sep() to support both. Noticed-by: Johannes Sixt Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 3d549a8..dec899a 100644 --- a/refs.c +++ b/refs.c @@ -1507,7 +1507,7 @@ int resolve_gitlink_ref(const char *submodule, const char *refname, struct ref_store *refs; int flags; - while (len && submodule[len - 1] == '/') + while (len && is_dir_sep(submodule[len - 1])) len--; if (!len) -- cgit v0.10.2-6-g49f6 From 6c3d818154eb74a4d5b35e786eefd297745bae1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:51 +0700 Subject: revision.c: refactor add_index_objects_to_pending() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The core code is factored out and take 'struct index_state *' instead so that we can reuse it to add objects from index files other than .git/index in the next patch. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/revision.c b/revision.c index aa3b946..6c46ad6 100644 --- a/revision.c +++ b/revision.c @@ -1262,13 +1262,13 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, } -void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) +static void do_add_index_objects_to_pending(struct rev_info *revs, + struct index_state *istate) { int i; - read_cache(); - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; struct blob *blob; if (S_ISGITLINK(ce->ce_mode)) @@ -1281,13 +1281,19 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) ce->ce_mode, ce->name); } - if (active_cache_tree) { + if (istate->cache_tree) { struct strbuf path = STRBUF_INIT; - add_cache_tree(active_cache_tree, revs, &path); + add_cache_tree(istate->cache_tree, revs, &path); strbuf_release(&path); } } +void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) +{ + read_cache(); + do_add_index_objects_to_pending(revs, &the_index); +} + static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, int exclude_parent) { -- cgit v0.10.2-6-g49f6 From be489d02d2f95b34e8f0fd15b9ec4752a11edd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:52 +0700 Subject: revision.c: --indexed-objects add objects from all worktrees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the result of single_worktree flag never being set (no way to up until now). To get objects from current index only, set single_worktree. The other add_index_objects_to_pending's caller is mark_reachable_objects() (e.g. "git prune") which also mark objects from all indexes. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/revision.c b/revision.c index 6c46ad6..f35cb49 100644 --- a/revision.c +++ b/revision.c @@ -19,6 +19,7 @@ #include "dir.h" #include "cache-tree.h" #include "bisect.h" +#include "worktree.h" volatile show_early_output_fn_t show_early_output; @@ -1290,8 +1291,28 @@ static void do_add_index_objects_to_pending(struct rev_info *revs, void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) { + struct worktree **worktrees, **p; + read_cache(); do_add_index_objects_to_pending(revs, &the_index); + + if (revs->single_worktree) + return; + + worktrees = get_worktrees(0); + for (p = worktrees; *p; p++) { + struct worktree *wt = *p; + struct index_state istate = { NULL }; + + if (wt->is_current) + continue; /* current index already taken care of */ + + if (read_index_from(&istate, + worktree_git_path(wt, "index")) > 0) + do_add_index_objects_to_pending(revs, &istate); + discard_index(&istate); + } + free_worktrees(worktrees); } static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index 133b584..cba45c7 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -283,4 +283,13 @@ test_expect_success 'prune: handle alternate object database' ' git -C B prune ' +test_expect_success 'prune: handle index in multiple worktrees' ' + git worktree add second-worktree && + echo "new blob for second-worktree" >second-worktree/blob && + git -C second-worktree add blob && + git prune --expire=now && + git -C second-worktree show :blob >actual && + test_cmp second-worktree/blob actual +' + test_done -- cgit v0.10.2-6-g49f6 From 2c616c172d5ae052600006e942ff34136e7c534e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:53 +0700 Subject: refs.c: refactor get_submodule_ref_store(), share common free block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index dec899a..522c4ab 100644 --- a/refs.c +++ b/refs.c @@ -1636,7 +1636,6 @@ struct ref_store *get_submodule_ref_store(const char *submodule) { struct strbuf submodule_sb = STRBUF_INIT; struct ref_store *refs; - int ret; if (!submodule || !*submodule) { /* @@ -1648,19 +1647,14 @@ struct ref_store *get_submodule_ref_store(const char *submodule) refs = lookup_ref_store_map(&submodule_ref_stores, submodule); if (refs) - return refs; + goto done; strbuf_addstr(&submodule_sb, submodule); - ret = is_nonbare_repository_dir(&submodule_sb); - strbuf_release(&submodule_sb); - if (!ret) - return NULL; + if (!is_nonbare_repository_dir(&submodule_sb)) + goto done; - ret = submodule_to_gitdir(&submodule_sb, submodule); - if (ret) { - strbuf_release(&submodule_sb); - return NULL; - } + if (submodule_to_gitdir(&submodule_sb, submodule)) + goto done; /* assume that add_submodule_odb() has been called */ refs = ref_store_init(submodule_sb.buf, @@ -1668,6 +1662,7 @@ struct ref_store *get_submodule_ref_store(const char *submodule) register_ref_store_map(&submodule_ref_stores, "submodule", refs, submodule); +done: strbuf_release(&submodule_sb); return refs; } -- cgit v0.10.2-6-g49f6 From 29babbeeb32fb4e8b892940e69207ec7de2e7a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:54 +0700 Subject: refs: move submodule slash stripping code to get_submodule_ref_store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a better place that will benefit all submodule callers instead of just resolve_gitlink_ref() Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 522c4ab..ea8e6b9 100644 --- a/refs.c +++ b/refs.c @@ -1503,25 +1503,10 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, int resolve_gitlink_ref(const char *submodule, const char *refname, unsigned char *sha1) { - size_t len = strlen(submodule); struct ref_store *refs; int flags; - while (len && is_dir_sep(submodule[len - 1])) - len--; - - if (!len) - return -1; - - if (submodule[len]) { - /* We need to strip off one or more trailing slashes */ - char *stripped = xmemdupz(submodule, len); - - refs = get_submodule_ref_store(stripped); - free(stripped); - } else { - refs = get_submodule_ref_store(submodule); - } + refs = get_submodule_ref_store(submodule); if (!refs) return -1; @@ -1636,6 +1621,16 @@ struct ref_store *get_submodule_ref_store(const char *submodule) { struct strbuf submodule_sb = STRBUF_INIT; struct ref_store *refs; + char *to_free = NULL; + size_t len; + + if (submodule) { + len = strlen(submodule); + while (len && is_dir_sep(submodule[len - 1])) + len--; + if (!len) + return NULL; + } if (!submodule || !*submodule) { /* @@ -1645,6 +1640,10 @@ struct ref_store *get_submodule_ref_store(const char *submodule) return get_main_ref_store(); } + if (submodule[len]) + /* We need to strip off one or more trailing slashes */ + submodule = to_free = xmemdupz(submodule, len); + refs = lookup_ref_store_map(&submodule_ref_stores, submodule); if (refs) goto done; @@ -1664,6 +1663,8 @@ struct ref_store *get_submodule_ref_store(const char *submodule) done: strbuf_release(&submodule_sb); + free(to_free); + return refs; } -- cgit v0.10.2-6-g49f6 From 62f0b399e00f38751834e688677ab49fcccd28fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:55 +0700 Subject: refs: add refs_head_ref() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index ea8e6b9..b3a0a24 100644 --- a/refs.c +++ b/refs.c @@ -1248,27 +1248,30 @@ int refs_rename_ref_available(struct ref_store *refs, return ok; } -int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { struct object_id oid; int flag; - if (submodule) { - if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0) - return fn("HEAD", &oid, 0, cb_data); - - return 0; - } - - if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) + if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING, + oid.hash, &flag)) return fn("HEAD", &oid, flag, cb_data); return 0; } +int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +{ + struct ref_store *refs = get_submodule_ref_store(submodule); + + if (!refs) + return -1; + return refs_head_ref(refs, fn, cb_data); +} + int head_ref(each_ref_fn fn, void *cb_data) { - return head_ref_submodule(NULL, fn, cb_data); + return refs_head_ref(get_main_ref_store(), fn, cb_data); } struct ref_iterator *refs_ref_iterator_begin( diff --git a/refs.h b/refs.h index 6daa78e..8073f8a 100644 --- a/refs.h +++ b/refs.h @@ -275,6 +275,8 @@ typedef int each_ref_fn(const char *refname, * modifies the reference also returns a nonzero value to immediately * stop the iteration. Returned references are sorted. */ +int refs_head_ref(struct ref_store *refs, + each_ref_fn fn, void *cb_data); int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, -- cgit v0.10.2-6-g49f6 From 073cf63c523e3e88a8e002fbc04fc1876f074aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:56 +0700 Subject: revision.c: use refs_for_each*() instead of for_each_*_submodule() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index b3a0a24..cd61509 100644 --- a/refs.c +++ b/refs.c @@ -1362,16 +1362,15 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix, prefix, fn, cb_data); } -int for_each_fullref_in_submodule(const char *submodule, const char *prefix, - each_ref_fn fn, void *cb_data, - unsigned int broken) +int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix, + each_ref_fn fn, void *cb_data, + unsigned int broken) { unsigned int flag = 0; if (broken) flag = DO_FOR_EACH_INCLUDE_BROKEN; - return do_for_each_ref(get_submodule_ref_store(submodule), - prefix, fn, 0, flag, cb_data); + return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data); } int for_each_replace_ref(each_ref_fn fn, void *cb_data) diff --git a/refs.h b/refs.h index 8073f8a..a8d6f33 100644 --- a/refs.h +++ b/refs.h @@ -291,6 +291,9 @@ int refs_for_each_remote_ref(struct ref_store *refs, int head_ref(each_ref_fn fn, void *cb_data); int for_each_ref(each_ref_fn fn, void *cb_data); int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data); +int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix, + each_ref_fn fn, void *cb_data, + unsigned int broken); int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken); int for_each_tag_ref(each_ref_fn fn, void *cb_data); @@ -306,9 +309,6 @@ int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); int for_each_ref_in_submodule(const char *submodule, const char *prefix, each_ref_fn fn, void *cb_data); -int for_each_fullref_in_submodule(const char *submodule, const char *prefix, - each_ref_fn fn, void *cb_data, - unsigned int broken); int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); int for_each_branch_ref_submodule(const char *submodule, diff --git a/revision.c b/revision.c index f35cb49..8d04516 100644 --- a/revision.c +++ b/revision.c @@ -1188,12 +1188,19 @@ void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude) string_list_append(*ref_excludes_p, exclude); } -static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags, - int (*for_each)(const char *, each_ref_fn, void *)) +static void handle_refs(struct ref_store *refs, + struct rev_info *revs, unsigned flags, + int (*for_each)(struct ref_store *, each_ref_fn, void *)) { struct all_refs_cb cb; + + if (!refs) { + /* this could happen with uninitialized submodules */ + return; + } + init_all_refs_cb(&cb, revs, flags); - for_each(submodule, handle_one_ref, &cb); + for_each(refs, handle_one_ref, &cb); } static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) @@ -2095,23 +2102,25 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, ctx->argc -= n; } -static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data, const char *term) { +static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn, + void *cb_data, const char *term) +{ struct strbuf bisect_refs = STRBUF_INIT; int status; strbuf_addf(&bisect_refs, "refs/bisect/%s", term); - status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0); + status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data, 0); strbuf_release(&bisect_refs); return status; } -static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data) +static int for_each_bad_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { - return for_each_bisect_ref(submodule, fn, cb_data, term_bad); + return for_each_bisect_ref(refs, fn, cb_data, term_bad); } -static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data) +static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { - return for_each_bisect_ref(submodule, fn, cb_data, term_good); + return for_each_bisect_ref(refs, fn, cb_data, term_good); } static int handle_revision_pseudo_opt(const char *submodule, @@ -2120,8 +2129,14 @@ static int handle_revision_pseudo_opt(const char *submodule, { const char *arg = argv[0]; const char *optarg; + struct ref_store *refs; int argcount; + if (submodule) { + refs = get_submodule_ref_store(submodule); + } else + refs = get_main_ref_store(); + /* * NOTE! * @@ -2133,22 +2148,23 @@ static int handle_revision_pseudo_opt(const char *submodule, * register it in the list at the top of handle_revision_opt. */ if (!strcmp(arg, "--all")) { - handle_refs(submodule, revs, *flags, for_each_ref_submodule); - handle_refs(submodule, revs, *flags, head_ref_submodule); + handle_refs(refs, revs, *flags, refs_for_each_ref); + handle_refs(refs, revs, *flags, refs_head_ref); clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--branches")) { - handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule); + handle_refs(refs, revs, *flags, refs_for_each_branch_ref); clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--bisect")) { read_bisect_terms(&term_bad, &term_good); - handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref); - handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref); + handle_refs(refs, revs, *flags, for_each_bad_bisect_ref); + handle_refs(refs, revs, *flags ^ (UNINTERESTING | BOTTOM), + for_each_good_bisect_ref); revs->bisect = 1; } else if (!strcmp(arg, "--tags")) { - handle_refs(submodule, revs, *flags, for_each_tag_ref_submodule); + handle_refs(refs, revs, *flags, refs_for_each_tag_ref); clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--remotes")) { - handle_refs(submodule, revs, *flags, for_each_remote_ref_submodule); + handle_refs(refs, revs, *flags, refs_for_each_remote_ref); clear_ref_exclusion(&revs->ref_excludes); } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { struct all_refs_cb cb; -- cgit v0.10.2-6-g49f6 From 2e2d4040bd1c26eccfe0e54b3ab73e13d4bf45e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:57 +0700 Subject: refs.c: move for_each_remote_ref_submodule() to submodule.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index cd61509..7fa19e9 100644 --- a/refs.c +++ b/refs.c @@ -368,12 +368,6 @@ int for_each_remote_ref(each_ref_fn fn, void *cb_data) return refs_for_each_remote_ref(get_main_ref_store(), fn, cb_data); } -int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return refs_for_each_remote_ref(get_submodule_ref_store(submodule), - fn, cb_data); -} - int head_ref_namespaced(each_ref_fn fn, void *cb_data) { struct strbuf buf = STRBUF_INIT; diff --git a/refs.h b/refs.h index a8d6f33..5d25da2 100644 --- a/refs.h +++ b/refs.h @@ -313,8 +313,6 @@ int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); -int for_each_remote_ref_submodule(const char *submodule, - each_ref_fn fn, void *cb_data); int head_ref_namespaced(each_ref_fn fn, void *cb_data); int for_each_namespaced_ref(each_ref_fn fn, void *cb_data); diff --git a/submodule.c b/submodule.c index e072036..98e1f9d 100644 --- a/submodule.c +++ b/submodule.c @@ -69,6 +69,13 @@ int is_staging_gitmodules_ok(const struct index_state *istate) return 1; } +static int for_each_remote_ref_submodule(const char *submodule, + each_ref_fn fn, void *cb_data) +{ + return refs_for_each_remote_ref(get_submodule_ref_store(submodule), + fn, cb_data); +} + /* * Try to update the "path" entry in the "submodule." section of the * .gitmodules file. Return 0 only if a .gitmodules file was found, a section -- cgit v0.10.2-6-g49f6 From 419221c1065981311b1a0f4a469d4d8a9ea09f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:58 +0700 Subject: refs: remove dead for_each_*_submodule() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are used in revision.c. After the last patch they are replaced with the refs_ version. Delete them. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/Documentation/technical/api-ref-iteration.txt b/Documentation/technical/api-ref-iteration.txt index 37379d8..46c3d5c 100644 --- a/Documentation/technical/api-ref-iteration.txt +++ b/Documentation/technical/api-ref-iteration.txt @@ -32,11 +32,8 @@ Iteration functions * `for_each_glob_ref_in()` the previous and `for_each_ref_in()` combined. -* `head_ref_submodule()`, `for_each_ref_submodule()`, - `for_each_ref_in_submodule()`, `for_each_tag_ref_submodule()`, - `for_each_branch_ref_submodule()`, `for_each_remote_ref_submodule()` - do the same as the functions described above but for a specified - submodule. +* Use `refs_` API for accessing submodules. The submodule ref store could + be obtained with `get_submodule_ref_store()`. * `for_each_rawref()` can be used to learn about broken ref and symref. diff --git a/refs.c b/refs.c index 7fa19e9..8c989ff 100644 --- a/refs.c +++ b/refs.c @@ -336,12 +336,6 @@ int for_each_tag_ref(each_ref_fn fn, void *cb_data) return refs_for_each_tag_ref(get_main_ref_store(), fn, cb_data); } -int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return refs_for_each_tag_ref(get_submodule_ref_store(submodule), - fn, cb_data); -} - int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data); @@ -352,12 +346,6 @@ int for_each_branch_ref(each_ref_fn fn, void *cb_data) return refs_for_each_branch_ref(get_main_ref_store(), fn, cb_data); } -int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return refs_for_each_branch_ref(get_submodule_ref_store(submodule), - fn, cb_data); -} - int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data); @@ -1254,15 +1242,6 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) return 0; } -int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - struct ref_store *refs = get_submodule_ref_store(submodule); - - if (!refs) - return -1; - return refs_head_ref(refs, fn, cb_data); -} - int head_ref(each_ref_fn fn, void *cb_data) { return refs_head_ref(get_main_ref_store(), fn, cb_data); @@ -1323,11 +1302,6 @@ int for_each_ref(each_ref_fn fn, void *cb_data) return refs_for_each_ref(get_main_ref_store(), fn, cb_data); } -int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return refs_for_each_ref(get_submodule_ref_store(submodule), fn, cb_data); -} - int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, each_ref_fn fn, void *cb_data) { @@ -1349,13 +1323,6 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsig prefix, fn, 0, flag, cb_data); } -int for_each_ref_in_submodule(const char *submodule, const char *prefix, - each_ref_fn fn, void *cb_data) -{ - return refs_for_each_ref_in(get_submodule_ref_store(submodule), - prefix, fn, cb_data); -} - int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken) diff --git a/refs.h b/refs.h index 5d25da2..78a2640 100644 --- a/refs.h +++ b/refs.h @@ -304,16 +304,6 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data); int for_each_glob_ref_in(each_ref_fn fn, const char *pattern, const char *prefix, void *cb_data); -int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data); -int for_each_ref_submodule(const char *submodule, - each_ref_fn fn, void *cb_data); -int for_each_ref_in_submodule(const char *submodule, const char *prefix, - each_ref_fn fn, void *cb_data); -int for_each_tag_ref_submodule(const char *submodule, - each_ref_fn fn, void *cb_data); -int for_each_branch_ref_submodule(const char *submodule, - each_ref_fn fn, void *cb_data); - int head_ref_namespaced(each_ref_fn fn, void *cb_data); int for_each_namespaced_ref(each_ref_fn fn, void *cb_data); -- cgit v0.10.2-6-g49f6 From d0c39a49ccb5dfe7feba4325c3374d99ab123c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:36:59 +0700 Subject: revision.c: --all adds HEAD from all worktrees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unless single_worktree is set, --all now adds HEAD from all worktrees. Since reachable.c code does not use setup_revisions(), we need to call other_head_refs_submodule() explicitly there to have the same effect on "git prune", so that we won't accidentally delete objects needed by some other HEADs. A new FIXME is added because we would need something like int refs_other_head_refs(struct ref_store *, each_ref_fn, cb_data); in addition to other_head_refs() to handle it, which might require int get_submodule_worktrees(const char *submodule, int flags); It could be a separate topic to reduce the scope of this one. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/reachable.c b/reachable.c index c62efbf..492e87b 100644 --- a/reachable.c +++ b/reachable.c @@ -9,6 +9,7 @@ #include "cache-tree.h" #include "progress.h" #include "list-objects.h" +#include "worktree.h" struct connectivity_progress { struct progress *progress; @@ -176,6 +177,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog, /* detached HEAD is not included in the list above */ head_ref(add_one_ref, revs); + other_head_refs(add_one_ref, revs); /* Add all reflog info */ if (mark_reflog) diff --git a/revision.c b/revision.c index 8d04516..0e98444 100644 --- a/revision.c +++ b/revision.c @@ -2133,6 +2133,14 @@ static int handle_revision_pseudo_opt(const char *submodule, int argcount; if (submodule) { + /* + * We need some something like get_submodule_worktrees() + * before we can go through all worktrees of a submodule, + * .e.g with adding all HEADs from --all, which is not + * supported right now, so stick to single worktree. + */ + if (!revs->single_worktree) + die("BUG: --single-worktree cannot be used together with submodule"); refs = get_submodule_ref_store(submodule); } else refs = get_main_ref_store(); @@ -2150,6 +2158,12 @@ static int handle_revision_pseudo_opt(const char *submodule, if (!strcmp(arg, "--all")) { handle_refs(refs, revs, *flags, refs_for_each_ref); handle_refs(refs, revs, *flags, refs_head_ref); + if (!revs->single_worktree) { + struct all_refs_cb cb; + + init_all_refs_cb(&cb, revs, *flags); + other_head_refs(handle_one_ref, &cb); + } clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--branches")) { handle_refs(refs, revs, *flags, refs_for_each_branch_ref); diff --git a/submodule.c b/submodule.c index 98e1f9d..61a38ad 100644 --- a/submodule.c +++ b/submodule.c @@ -1685,6 +1685,8 @@ static int find_first_merges(struct object_array *result, const char *path, oid_to_hex(&a->object.oid)); init_revisions(&revs, NULL); rev_opts.submodule = path; + /* FIXME: can't handle linked worktrees in submodules yet */ + revs.single_worktree = path != NULL; setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts); /* save all revisions from the above list that contain b */ diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index cba45c7..683bdb0 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -292,4 +292,16 @@ test_expect_success 'prune: handle index in multiple worktrees' ' test_cmp second-worktree/blob actual ' +test_expect_success 'prune: handle HEAD in multiple worktrees' ' + git worktree add --detach third-worktree && + echo "new blob for third-worktree" >third-worktree/blob && + git -C third-worktree add blob && + git -C third-worktree commit -m "third" && + rm .git/worktrees/third-worktree/index && + test_must_fail git -C third-worktree show :blob && + git prune --expire=now && + git -C third-worktree show HEAD:blob >actual && + test_cmp third-worktree/blob actual +' + test_done diff --git a/worktree.c b/worktree.c index e28ffbe..389e2e9 100644 --- a/worktree.c +++ b/worktree.c @@ -386,3 +386,25 @@ int submodule_uses_worktrees(const char *path) closedir(dir); return ret; } + +int other_head_refs(each_ref_fn fn, void *cb_data) +{ + struct worktree **worktrees, **p; + int ret = 0; + + worktrees = get_worktrees(0); + for (p = worktrees; *p; p++) { + struct worktree *wt = *p; + struct ref_store *refs; + + if (wt->is_current) + continue; + + refs = get_worktree_ref_store(wt); + ret = refs_head_ref(refs, fn, cb_data); + if (ret) + break; + } + free_worktrees(worktrees); + return ret; +} diff --git a/worktree.h b/worktree.h index 5ea5e50..9276c81 100644 --- a/worktree.h +++ b/worktree.h @@ -1,6 +1,8 @@ #ifndef WORKTREE_H #define WORKTREE_H +#include "refs.h" + struct worktree { char *path; char *id; @@ -70,6 +72,12 @@ extern void free_worktrees(struct worktree **); extern const struct worktree *find_shared_symref(const char *symref, const char *target); +/* + * Similar to head_ref() for all HEADs _except_ one from the current + * worktree, which is covered by head_ref(). + */ +int other_head_refs(each_ref_fn fn, void *cb_data); + int is_worktree_being_rebased(const struct worktree *wt, const char *target); int is_worktree_being_bisected(const struct worktree *wt, const char *target); -- cgit v0.10.2-6-g49f6 From 944b4e3013d6e21b1ecd2f2579395341f2cc8b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:37:00 +0700 Subject: files-backend: make reflog iterator go through per-worktree reflog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs/bisect is unfortunately per-worktree, so we need to look in per-worktree logs/refs/bisect in addition to per-repo logs/refs. The current iterator only goes through per-repo logs/refs. Use merge iterator to walk two ref stores at the same time and pick per-worktree refs from the right iterator. PS. Note the unsorted order of for_each_reflog in the test. This is supposed to be OK, for now. If we enforce order on for_each_reflog() then some more work will be required. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs/files-backend.c b/refs/files-backend.c index 5cca555..d4d2288 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -106,15 +106,6 @@ static void files_reflog_path(struct files_ref_store *refs, struct strbuf *sb, const char *refname) { - if (!refname) { - /* - * FIXME: of course this is wrong in multi worktree - * setting. To be fixed real soon. - */ - strbuf_addf(sb, "%s/logs", refs->gitcommondir); - return; - } - switch (ref_type(refname)) { case REF_TYPE_PER_WORKTREE: case REF_TYPE_PSEUDOREF: @@ -2055,23 +2046,63 @@ static struct ref_iterator_vtable files_reflog_iterator_vtable = { files_reflog_iterator_abort }; -static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_store) +static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store, + const char *gitdir) { - struct files_ref_store *refs = - files_downcast(ref_store, REF_STORE_READ, - "reflog_iterator_begin"); struct files_reflog_iterator *iter = xcalloc(1, sizeof(*iter)); struct ref_iterator *ref_iterator = &iter->base; struct strbuf sb = STRBUF_INIT; base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable); - files_reflog_path(refs, &sb, NULL); + strbuf_addf(&sb, "%s/logs", gitdir); iter->dir_iterator = dir_iterator_begin(sb.buf); iter->ref_store = ref_store; strbuf_release(&sb); + return ref_iterator; } +static enum iterator_selection reflog_iterator_select( + struct ref_iterator *iter_worktree, + struct ref_iterator *iter_common, + void *cb_data) +{ + if (iter_worktree) { + /* + * We're a bit loose here. We probably should ignore + * common refs if they are accidentally added as + * per-worktree refs. + */ + return ITER_SELECT_0; + } else if (iter_common) { + if (ref_type(iter_common->refname) == REF_TYPE_NORMAL) + return ITER_SELECT_1; + + /* + * The main ref store may contain main worktree's + * per-worktree refs, which should be ignored + */ + return ITER_SKIP_1; + } else + return ITER_DONE; +} + +static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_store) +{ + struct files_ref_store *refs = + files_downcast(ref_store, REF_STORE_READ, + "reflog_iterator_begin"); + + if (!strcmp(refs->gitdir, refs->gitcommondir)) { + return reflog_iterator_begin(ref_store, refs->gitcommondir); + } else { + return merge_ref_iterator_begin( + reflog_iterator_begin(ref_store, refs->gitdir), + reflog_iterator_begin(ref_store, refs->gitcommondir), + reflog_iterator_select, refs); + } +} + /* * If update is a direct update of head_ref (the reference pointed to * by HEAD), then add an extra REF_LOG_ONLY update for HEAD. diff --git a/t/t1407-worktree-ref-store.sh b/t/t1407-worktree-ref-store.sh index 5df06f3..8842d03 100755 --- a/t/t1407-worktree-ref-store.sh +++ b/t/t1407-worktree-ref-store.sh @@ -49,4 +49,34 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' ' test_cmp expected actual ' +test_expect_success 'for_each_reflog()' ' + echo $_z40 > .git/logs/PSEUDO-MAIN && + mkdir -p .git/logs/refs/bisect && + echo $_z40 > .git/logs/refs/bisect/random && + + echo $_z40 > .git/worktrees/wt/logs/PSEUDO-WT && + mkdir -p .git/worktrees/wt/logs/refs/bisect && + echo $_z40 > .git/worktrees/wt/logs/refs/bisect/wt-random && + + $RWT for-each-reflog | cut -c 42- | sort >actual && + cat >expected <<-\EOF && + HEAD 0x1 + PSEUDO-WT 0x0 + refs/bisect/wt-random 0x0 + refs/heads/master 0x0 + refs/heads/wt-master 0x0 + EOF + test_cmp expected actual && + + $RMAIN for-each-reflog | cut -c 42- | sort >actual && + cat >expected <<-\EOF && + HEAD 0x1 + PSEUDO-MAIN 0x0 + refs/bisect/random 0x0 + refs/heads/master 0x0 + refs/heads/wt-master 0x0 + EOF + test_cmp expected actual +' + test_done -- cgit v0.10.2-6-g49f6 From acd9544a8fdcf8095c82c91365c45dcb93112be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:37:01 +0700 Subject: revision.c: --reflog add HEAD reflog from all worktrees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that add_other_reflogs_to_pending() is a bit inefficient, since it scans reflog for all refs of each worktree, including shared refs, so the shared ref's reflog is scanned over and over again. We could update refs API to pass "per-worktree only" flag to avoid that. But long term we should be able to obtain a "per-worktree only" ref store and would need to revert the changes in reflog iteration API. So let's just wait until then. add_reflogs_to_pending() is called by reachable.c so by default "git prune" will examine reflog from all worktrees. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/revision.c b/revision.c index 0e98444..d100b3a 100644 --- a/revision.c +++ b/revision.c @@ -1132,6 +1132,7 @@ struct all_refs_cb { int warned_bad_reflog; struct rev_info *all_revs; const char *name_for_errormsg; + struct ref_store *refs; }; int ref_excluded(struct string_list *ref_excludes, const char *path) @@ -1168,6 +1169,7 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs, cb->all_revs = revs; cb->all_flags = flags; revs->rev_input_given = 1; + cb->refs = NULL; } void clear_ref_exclusion(struct string_list **ref_excludes_p) @@ -1236,17 +1238,41 @@ static int handle_one_reflog(const char *path, const struct object_id *oid, struct all_refs_cb *cb = cb_data; cb->warned_bad_reflog = 0; cb->name_for_errormsg = path; - for_each_reflog_ent(path, handle_one_reflog_ent, cb_data); + refs_for_each_reflog_ent(cb->refs, path, + handle_one_reflog_ent, cb_data); return 0; } +static void add_other_reflogs_to_pending(struct all_refs_cb *cb) +{ + struct worktree **worktrees, **p; + + worktrees = get_worktrees(0); + for (p = worktrees; *p; p++) { + struct worktree *wt = *p; + + if (wt->is_current) + continue; + + cb->refs = get_worktree_ref_store(wt); + refs_for_each_reflog(cb->refs, + handle_one_reflog, + cb); + } + free_worktrees(worktrees); +} + void add_reflogs_to_pending(struct rev_info *revs, unsigned flags) { struct all_refs_cb cb; cb.all_revs = revs; cb.all_flags = flags; + cb.refs = get_main_ref_store(); for_each_reflog(handle_one_reflog, &cb); + + if (!revs->single_worktree) + add_other_reflogs_to_pending(&cb); } static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index 683bdb0..6694c19 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -304,4 +304,20 @@ test_expect_success 'prune: handle HEAD in multiple worktrees' ' test_cmp third-worktree/blob actual ' +test_expect_success 'prune: handle HEAD reflog in multiple worktrees' ' + git config core.logAllRefUpdates true && + echo "lost blob for third-worktree" >expected && + ( + cd third-worktree && + cat ../expected >blob && + git add blob && + git commit -m "second commit in third" && + git reset --hard HEAD^ + ) && + git prune --expire=now && + SHA1=`git hash-object expected` && + git -C third-worktree show "$SHA1" >actual && + test_cmp expected actual +' + test_done -- cgit v0.10.2-6-g49f6 From 32619f99f94760e90c36fd2a4476f459cb11aa41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:37:02 +0700 Subject: rev-list: expose and document --single-worktree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index a6cf9eb..7d860bf 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -184,6 +184,14 @@ explicitly. Pretend as if all objects mentioned by reflogs are listed on the command line as ``. +--single-worktree:: + By default, all working trees will be examined by the + following options when there are more than one (see + linkgit:git-worktree[1]): `--all`, `--reflog` and + `--indexed-objects`. + This option forces them to examine the current working tree + only. + --ignore-missing:: Upon seeing an invalid object name in the input, pretend as if the bad input was not given. diff --git a/revision.c b/revision.c index d100b3a..6eba413 100644 --- a/revision.c +++ b/revision.c @@ -2251,6 +2251,8 @@ static int handle_revision_pseudo_opt(const char *submodule, return error("invalid argument to --no-walk"); } else if (!strcmp(arg, "--do-walk")) { revs->no_walk = 0; + } else if (!strcmp(arg, "--single-worktree")) { + revs->single_worktree = 1; } else { return 0; } -- cgit v0.10.2-6-g49f6 From 82a150f27a16cd1425d4c78904470e4b7b8c4cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:37:03 +0700 Subject: refs.c: remove fallback-to-main-store code get_submodule_ref_store() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At this state, there are three get_submodule_ref_store() callers: - for_each_remote_ref_submodule() - handle_revision_pseudo_opt() - resolve_gitlink_ref() The first two deal explicitly with submodules (and we should never fall back to the main ref store as a result). They are only called from submodule.c: - find_first_merges() - submodule_needs_pushing() - push_submodule() The last one, as its name implies, deals only with submodules too, and the "submodule" (path) argument must be a non-NULL, non-empty string. So, this "if NULL or empty string" code block should never ever trigger. And it's wrong to fall back to the main ref store anyway. Delete it. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 8c989ff..a0c5078 100644 --- a/refs.c +++ b/refs.c @@ -1587,6 +1587,9 @@ struct ref_store *get_submodule_ref_store(const char *submodule) char *to_free = NULL; size_t len; + if (!submodule) + return NULL; + if (submodule) { len = strlen(submodule); while (len && is_dir_sep(submodule[len - 1])) @@ -1595,14 +1598,6 @@ struct ref_store *get_submodule_ref_store(const char *submodule) return NULL; } - if (!submodule || !*submodule) { - /* - * FIXME: This case is ideally not allowed. But that - * can't happen until we clean up all the callers. - */ - return get_main_ref_store(); - } - if (submodule[len]) /* We need to strip off one or more trailing slashes */ submodule = to_free = xmemdupz(submodule, len); -- cgit v0.10.2-6-g49f6 From 873ea90d61fa45ec91af3864c2e336bfe489d181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Wed, 23 Aug 2017 19:37:04 +0700 Subject: refs.c: reindent get_submodule_ref_store() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the new "if (!submodule) return NULL;" code added in the previous commit, we don't need to check if submodule is not NULL anymore. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index a0c5078..206af61 100644 --- a/refs.c +++ b/refs.c @@ -1590,13 +1590,11 @@ struct ref_store *get_submodule_ref_store(const char *submodule) if (!submodule) return NULL; - if (submodule) { - len = strlen(submodule); - while (len && is_dir_sep(submodule[len - 1])) - len--; - if (!len) - return NULL; - } + len = strlen(submodule); + while (len && is_dir_sep(submodule[len - 1])) + len--; + if (!len) + return NULL; if (submodule[len]) /* We need to strip off one or more trailing slashes */ -- cgit v0.10.2-6-g49f6