Skip to content

Commit 9ef6aeb

Browse files
hvoigtgitster
authored andcommitted
setup_revisions(): Allow walking history in a submodule
By passing the path to a submodule in opt->submodule, the function can be used to walk history in the named submodule repository, instead of the toplevel repository. Signed-off-by: Heiko Voigt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0bad611 commit 9ef6aeb

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

refs.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,31 +721,62 @@ int head_ref(each_ref_fn fn, void *cb_data)
721721
return do_head_ref(NULL, fn, cb_data);
722722
}
723723

724+
int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
725+
{
726+
return do_head_ref(submodule, fn, cb_data);
727+
}
728+
724729
int for_each_ref(each_ref_fn fn, void *cb_data)
725730
{
726731
return do_for_each_ref(NULL, "refs/", fn, 0, 0, cb_data);
727732
}
728733

734+
int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
735+
{
736+
return do_for_each_ref(submodule, "refs/", fn, 0, 0, cb_data);
737+
}
738+
729739
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
730740
{
731741
return do_for_each_ref(NULL, prefix, fn, strlen(prefix), 0, cb_data);
732742
}
733743

744+
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
745+
each_ref_fn fn, void *cb_data)
746+
{
747+
return do_for_each_ref(submodule, prefix, fn, strlen(prefix), 0, cb_data);
748+
}
749+
734750
int for_each_tag_ref(each_ref_fn fn, void *cb_data)
735751
{
736752
return for_each_ref_in("refs/tags/", fn, cb_data);
737753
}
738754

755+
int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
756+
{
757+
return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data);
758+
}
759+
739760
int for_each_branch_ref(each_ref_fn fn, void *cb_data)
740761
{
741762
return for_each_ref_in("refs/heads/", fn, cb_data);
742763
}
743764

765+
int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
766+
{
767+
return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data);
768+
}
769+
744770
int for_each_remote_ref(each_ref_fn fn, void *cb_data)
745771
{
746772
return for_each_ref_in("refs/remotes/", fn, cb_data);
747773
}
748774

775+
int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
776+
{
777+
return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data);
778+
}
779+
749780
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
750781
{
751782
return do_for_each_ref(NULL, "refs/replace/", fn, 13, 0, cb_data);

refs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ extern int for_each_replace_ref(each_ref_fn, void *);
2828
extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);
2929
extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);
3030

31+
extern int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
32+
extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
33+
extern int for_each_ref_in_submodule(const char *submodule, const char *prefix,
34+
each_ref_fn fn, void *cb_data);
35+
extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
36+
extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
37+
extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
38+
3139
static inline const char *has_glob_specials(const char *pattern)
3240
{
3341
return strpbrk(pattern, "?*[");

revision.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -820,12 +820,12 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
820820
cb->all_flags = flags;
821821
}
822822

823-
static void handle_refs(struct rev_info *revs, unsigned flags,
824-
int (*for_each)(each_ref_fn, void *))
823+
static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,
824+
int (*for_each)(const char *, each_ref_fn, void *))
825825
{
826826
struct all_refs_cb cb;
827827
init_all_refs_cb(&cb, revs, flags);
828-
for_each(handle_one_ref, &cb);
828+
for_each(submodule, handle_one_ref, &cb);
829829
}
830830

831831
static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
@@ -1417,14 +1417,14 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
14171417
ctx->argc -= n;
14181418
}
14191419

1420-
static int for_each_bad_bisect_ref(each_ref_fn fn, void *cb_data)
1420+
static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
14211421
{
1422-
return for_each_ref_in("refs/bisect/bad", fn, cb_data);
1422+
return for_each_ref_in_submodule(submodule, "refs/bisect/bad", fn, cb_data);
14231423
}
14241424

1425-
static int for_each_good_bisect_ref(each_ref_fn fn, void *cb_data)
1425+
static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
14261426
{
1427-
return for_each_ref_in("refs/bisect/good", fn, cb_data);
1427+
return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
14281428
}
14291429

14301430
static void append_prune_data(const char ***prune_data, const char **av)
@@ -1466,6 +1466,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
14661466
{
14671467
int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
14681468
const char **prune_data = NULL;
1469+
const char *submodule = NULL;
1470+
1471+
if (opt)
1472+
submodule = opt->submodule;
14691473

14701474
/* First, search for "--" */
14711475
seen_dashdash = 0;
@@ -1490,26 +1494,26 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
14901494
int opts;
14911495

14921496
if (!strcmp(arg, "--all")) {
1493-
handle_refs(revs, flags, for_each_ref);
1494-
handle_refs(revs, flags, head_ref);
1497+
handle_refs(submodule, revs, flags, for_each_ref_submodule);
1498+
handle_refs(submodule, revs, flags, head_ref_submodule);
14951499
continue;
14961500
}
14971501
if (!strcmp(arg, "--branches")) {
1498-
handle_refs(revs, flags, for_each_branch_ref);
1502+
handle_refs(submodule, revs, flags, for_each_branch_ref_submodule);
14991503
continue;
15001504
}
15011505
if (!strcmp(arg, "--bisect")) {
1502-
handle_refs(revs, flags, for_each_bad_bisect_ref);
1503-
handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
1506+
handle_refs(submodule, revs, flags, for_each_bad_bisect_ref);
1507+
handle_refs(submodule, revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
15041508
revs->bisect = 1;
15051509
continue;
15061510
}
15071511
if (!strcmp(arg, "--tags")) {
1508-
handle_refs(revs, flags, for_each_tag_ref);
1512+
handle_refs(submodule, revs, flags, for_each_tag_ref_submodule);
15091513
continue;
15101514
}
15111515
if (!strcmp(arg, "--remotes")) {
1512-
handle_refs(revs, flags, for_each_remote_ref);
1516+
handle_refs(submodule, revs, flags, for_each_remote_ref_submodule);
15131517
continue;
15141518
}
15151519
if (!prefixcmp(arg, "--glob=")) {

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ extern volatile show_early_output_fn_t show_early_output;
151151
struct setup_revision_opt {
152152
const char *def;
153153
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
154+
const char *submodule;
154155
};
155156

156157
extern void init_revisions(struct rev_info *revs, const char *prefix);

0 commit comments

Comments
 (0)