Skip to content

Commit d54a687

Browse files
committed
Merge 'pk/rebase-in-c-4-opts'
This wave of built rebase patches implements the remaining rebase options in the builtin rebase. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 730a0b1 + b106132 commit d54a687

File tree

4 files changed

+529
-85
lines changed

4 files changed

+529
-85
lines changed

builtin/merge-base.c

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -110,54 +110,12 @@ static int handle_is_ancestor(int argc, const char **argv)
110110
return 1;
111111
}
112112

113-
struct rev_collect {
114-
struct commit **commit;
115-
int nr;
116-
int alloc;
117-
unsigned int initial : 1;
118-
};
119-
120-
static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
121-
{
122-
struct commit *commit;
123-
124-
if (is_null_oid(oid))
125-
return;
126-
127-
commit = lookup_commit(the_repository, oid);
128-
if (!commit ||
129-
(commit->object.flags & TMP_MARK) ||
130-
parse_commit(commit))
131-
return;
132-
133-
ALLOC_GROW(revs->commit, revs->nr + 1, revs->alloc);
134-
revs->commit[revs->nr++] = commit;
135-
commit->object.flags |= TMP_MARK;
136-
}
137-
138-
static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid,
139-
const char *ident, timestamp_t timestamp,
140-
int tz, const char *message, void *cbdata)
141-
{
142-
struct rev_collect *revs = cbdata;
143-
144-
if (revs->initial) {
145-
revs->initial = 0;
146-
add_one_commit(ooid, revs);
147-
}
148-
add_one_commit(noid, revs);
149-
return 0;
150-
}
151-
152113
static int handle_fork_point(int argc, const char **argv)
153114
{
154115
struct object_id oid;
155116
char *refname;
117+
struct commit *derived, *fork_point;
156118
const char *commitname;
157-
struct rev_collect revs;
158-
struct commit *derived;
159-
struct commit_list *bases;
160-
int i, ret = 0;
161119

162120
switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
163121
case 0:
@@ -173,41 +131,14 @@ static int handle_fork_point(int argc, const char **argv)
173131
die("Not a valid object name: '%s'", commitname);
174132

175133
derived = lookup_commit_reference(the_repository, &oid);
176-
memset(&revs, 0, sizeof(revs));
177-
revs.initial = 1;
178-
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
179134

180-
if (!revs.nr && !get_oid(refname, &oid))
181-
add_one_commit(&oid, &revs);
135+
fork_point = get_fork_point(refname, derived);
182136

183-
for (i = 0; i < revs.nr; i++)
184-
revs.commit[i]->object.flags &= ~TMP_MARK;
185-
186-
bases = get_merge_bases_many_dirty(derived, revs.nr, revs.commit);
187-
188-
/*
189-
* There should be one and only one merge base, when we found
190-
* a common ancestor among reflog entries.
191-
*/
192-
if (!bases || bases->next) {
193-
ret = 1;
194-
goto cleanup_return;
195-
}
196-
197-
/* And the found one must be one of the reflog entries */
198-
for (i = 0; i < revs.nr; i++)
199-
if (&bases->item->object == &revs.commit[i]->object)
200-
break; /* found */
201-
if (revs.nr <= i) {
202-
ret = 1; /* not found */
203-
goto cleanup_return;
204-
}
205-
206-
printf("%s\n", oid_to_hex(&bases->item->object.oid));
137+
if (!fork_point)
138+
return 1;
207139

208-
cleanup_return:
209-
free_commit_list(bases);
210-
return ret;
140+
printf("%s\n", oid_to_hex(&fork_point->object.oid));
141+
return 0;
211142
}
212143

213144
int cmd_merge_base(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)