@matheusbsbs / matheus-bagliano / commits / 2ecd2bbcbe
Fork 0

Move in_merge_bases() to commit.c

This reasonably useful function was hidden inside builtin-branch.c

Junio C Hamano committed Dec 19, 2006 at 00:14 UTC 2ecd2bbcbe5335c1d9209b6ce28513e4e9d3491b
3 files changed +19 -20
builtin-branch.c
+1 -20
@@ -74,25 +74,6 @@ const char *branch_get_color(enum color_branch ix)
74 return "";
75 }
76
77 -static int in_merge_bases(const unsigned char *sha1,
78 - struct commit *rev1,
79 - struct commit *rev2)
80 -{
81 - struct commit_list *bases, *b;
82 - int ret = 0;
83 -
84 - bases = get_merge_bases(rev1, rev2, 1);
85 - for (b = bases; b; b = b->next) {
86 - if (!hashcmp(sha1, b->item->object.sha1)) {
87 - ret = 1;
88 - break;
89 - }
90 - }
91 -
92 - free_commit_list(bases);
93 - return ret;
94 -}
95 -
77 static int delete_branches(int argc, const char **argv, int force, int kinds)
78 {
79 struct commit *rev, *head_rev = head_rev;
@@ -153,7 +134,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
134 */
135
136 if (!force &&
156 - !in_merge_bases(sha1, rev, head_rev)) {
137 + !in_merge_bases(rev, head_rev)) {
138 error("The branch '%s' is not a strict subset of "
139 "your current HEAD.\n"
140 "If you are sure you want to delete it, "
commit.c
+17
@@ -1009,3 +1009,20 @@ struct commit_list *get_merge_bases(struct commit *one,
1009 free(rslt);
1010 return result;
1011 }
1012 +
1013 +int in_merge_bases(struct commit *rev1, struct commit *rev2)
1014 +{
1015 + struct commit_list *bases, *b;
1016 + int ret = 0;
1017 +
1018 + bases = get_merge_bases(rev1, rev2, 1);
1019 + for (b = bases; b; b = b->next) {
1020 + if (!hashcmp(rev1->object.sha1, b->item->object.sha1)) {
1021 + ret = 1;
1022 + break;
1023 + }
1024 + }
1025 +
1026 + free_commit_list(bases);
1027 + return ret;
1028 +}
commit.h
+1
@@ -107,4 +107,5 @@ int read_graft_file(const char *graft_file);
107
108 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
109
110 +int in_merge_bases(struct commit *rev1, struct commit *rev2);
111 #endif /* COMMIT_H */