@matheusbsbs / matheus-bagliano / commits / 9ef6aeb09f
Fork 0

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 <hvoigt@hvoigt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Heiko Voigt committed Jul 7, 2010 at 15:39 UTC 9ef6aeb09ffe0650ca86dca53de93fd85333b02d
4 files changed +58 -14
refs.c
+31
@@ -721,31 +721,62 @@ int head_ref(each_ref_fn fn, void *cb_data)
721 return do_head_ref(NULL, fn, cb_data);
722 }
723
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 +
729 int for_each_ref(each_ref_fn fn, void *cb_data)
730 {
731 return do_for_each_ref(NULL, "refs/", fn, 0, 0, cb_data);
732 }
733
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 +
739 int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
740 {
741 return do_for_each_ref(NULL, prefix, fn, strlen(prefix), 0, cb_data);
742 }
743
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 +
750 int for_each_tag_ref(each_ref_fn fn, void *cb_data)
751 {
752 return for_each_ref_in("refs/tags/", fn, cb_data);
753 }
754
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 +
760 int for_each_branch_ref(each_ref_fn fn, void *cb_data)
761 {
762 return for_each_ref_in("refs/heads/", fn, cb_data);
763 }
764
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 +
770 int for_each_remote_ref(each_ref_fn fn, void *cb_data)
771 {
772 return for_each_ref_in("refs/remotes/", fn, cb_data);
773 }
774
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 +
780 int for_each_replace_ref(each_ref_fn fn, void *cb_data)
781 {
782 return do_for_each_ref(NULL, "refs/replace/", fn, 13, 0, cb_data);
refs.h
+8
@@ -28,6 +28,14 @@ extern int for_each_replace_ref(each_ref_fn, void *);
28 extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);
29 extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);
30
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 +
39 static inline const char *has_glob_specials(const char *pattern)
40 {
41 return strpbrk(pattern, "?*[");
revision.c
+18 -14
@@ -820,12 +820,12 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
820 cb->all_flags = flags;
821 }
822
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 *))
825 {
826 struct all_refs_cb cb;
827 init_all_refs_cb(&cb, revs, flags);
828 - for_each(handle_one_ref, &cb);
828 + for_each(submodule, handle_one_ref, &cb);
829 }
830
831 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,
1417 ctx->argc -= n;
1418 }
1419
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)
1421 {
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);
1423 }
1424
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)
1426 {
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);
1428 }
1429
1430 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
1466 {
1467 int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
1468 const char **prune_data = NULL;
1469 + const char *submodule = NULL;
1470 +
1471 + if (opt)
1472 + submodule = opt->submodule;
1473
1474 /* First, search for "--" */
1475 seen_dashdash = 0;
@@ -1490,26 +1494,26 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
1494 int opts;
1495
1496 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);
1499 continue;
1500 }
1501 if (!strcmp(arg, "--branches")) {
1498 - handle_refs(revs, flags, for_each_branch_ref);
1502 + handle_refs(submodule, revs, flags, for_each_branch_ref_submodule);
1503 continue;
1504 }
1505 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);
1508 revs->bisect = 1;
1509 continue;
1510 }
1511 if (!strcmp(arg, "--tags")) {
1508 - handle_refs(revs, flags, for_each_tag_ref);
1512 + handle_refs(submodule, revs, flags, for_each_tag_ref_submodule);
1513 continue;
1514 }
1515 if (!strcmp(arg, "--remotes")) {
1512 - handle_refs(revs, flags, for_each_remote_ref);
1516 + handle_refs(submodule, revs, flags, for_each_remote_ref_submodule);
1517 continue;
1518 }
1519 if (!prefixcmp(arg, "--glob=")) {
revision.h
+1
@@ -151,6 +151,7 @@ extern volatile show_early_output_fn_t show_early_output;
151 struct setup_revision_opt {
152 const char *def;
153 void (*tweak)(struct rev_info *, struct setup_revision_opt *);
154 + const char *submodule;
155 };
156
157 extern void init_revisions(struct rev_info *revs, const char *prefix);