Skip to content

Commit 0293121

Browse files
committed
Merge branch 'pk/rebase-in-c-4-opts'
Rewrite "git rebase" in C. * pk/rebase-in-c-4-opts: builtin rebase: support --root builtin rebase: add support for custom merge strategies builtin rebase: support `fork-point` option merge-base --fork-point: extract libified function builtin rebase: support --rebase-merges[=[no-]rebase-cousins] builtin rebase: support `--allow-empty-message` option builtin rebase: support `--exec` builtin rebase: support `--autostash` option builtin rebase: support `-C` and `--whitespace=<type>` builtin rebase: support `--gpg-sign` option builtin rebase: support `--autosquash` builtin rebase: support `keep-empty` option builtin rebase: support `ignore-date` option builtin rebase: support `ignore-whitespace` option builtin rebase: support --committer-date-is-author-date builtin rebase: support --rerere-autoupdate builtin rebase: support --signoff builtin rebase: allow selecting the rebase "backend"
2 parents 39f7331 + 9dba809 commit 0293121

File tree

4 files changed

+530
-85
lines changed

4 files changed

+530
-85
lines changed

builtin/merge-base.c

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

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

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

176134
derived = lookup_commit_reference(the_repository, &oid);
177-
memset(&revs, 0, sizeof(revs));
178-
revs.initial = 1;
179-
for_each_reflog_ent(refname, collect_one_reflog_ent, &revs);
180135

181-
if (!revs.nr && !get_oid(refname, &oid))
182-
add_one_commit(&oid, &revs);
136+
fork_point = get_fork_point(refname, derived);
183137

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

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

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

0 commit comments

Comments
 (0)