Message ID | 1d5e0419c45087c474f33d5ea6b3bcdacd072fa5.1666012665.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | rebase --keep-base: imply --reapply-cherry-picks and --no-fork-point | expand |
> diff --git a/commit.c b/commit.c > index 0db461f9735..de30b098dd3 100644 > --- a/commit.c > +++ b/commit.c > @@ -59,6 +59,14 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref > return c; > } > > +struct commit *lookup_commit_object (struct repository *r, > + const struct object_id *oid) Let's lose the SP before opening parenthesis (I'll do that while queuing unless I forget ;-). > +{ > + struct object *obj = parse_object(r, oid); > + return obj ? object_as_type(obj, OBJ_COMMIT, 0) : NULL; > + > +} > + > struct commit *lookup_commit(struct repository *r, const struct object_id *oid) > { > struct object *obj = lookup_object(r, oid); > diff --git a/commit.h b/commit.h > index 21e4d25ce78..fa39202fa6b 100644 > --- a/commit.h > +++ b/commit.h > @@ -64,6 +64,19 @@ enum decoration_type { > void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); > const struct name_decoration *get_name_decoration(const struct object *obj); > > +/* > + * Look up commit named by "oid" respecting replacement objects. > + * Returns NULL if "oid" is not a commit or does not exist. > + */ > +struct commit *lookup_commit_object(struct repository *r, const struct object_id *oid); > + > +/* > + * Look up commit named by "oid" without replacement objects or > + * checking for object existence. Returns the requested commit if it > + * is found in the object cache, NULL if "oid" is in the object cache > + * but is not a commit and a newly allocated unparsed commit object if > + * "oid" is not in the object cache. > + */ > struct commit *lookup_commit(struct repository *r, const struct object_id *oid); I was going to ask documenting the differences of the two API functions, which is done here. Good. > struct commit *lookup_commit_reference(struct repository *r, > const struct object_id *oid);
On 17/10/2022 19:51, Junio C Hamano wrote: >> diff --git a/commit.c b/commit.c >> index 0db461f9735..de30b098dd3 100644 >> --- a/commit.c >> +++ b/commit.c >> @@ -59,6 +59,14 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref >> return c; >> } >> >> +struct commit *lookup_commit_object (struct repository *r, >> + const struct object_id *oid) > > Let's lose the SP before opening parenthesis (I'll do that while > queuing unless I forget ;-). Sorry, thanks for fixing it up Phillip
diff --git a/builtin/rebase.c b/builtin/rebase.c index 56e4214b441..06903eb6d4d 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -431,9 +431,9 @@ static int read_basic_state(struct rebase_options *opts) opts->head_name = starts_with(head_name.buf, "refs/") ? xstrdup(head_name.buf) : NULL; strbuf_release(&head_name); - if (get_oid(buf.buf, &oid)) - return error(_("could not get 'onto': '%s'"), buf.buf); - opts->onto = lookup_commit_or_die(&oid, buf.buf); + if (get_oid_hex(buf.buf, &oid) || + !(opts->onto = lookup_commit_object(the_repository, &oid))) + return error(_("invalid onto: '%s'"), buf.buf); /* * We always write to orig-head, but interactive rebase used to write to @@ -448,7 +448,7 @@ static int read_basic_state(struct rebase_options *opts) } else if (!read_oneliner(&buf, state_dir_path("head", opts), READ_ONELINER_WARN_MISSING)) return -1; - if (get_oid(buf.buf, &opts->orig_head)) + if (get_oid_hex(buf.buf, &opts->orig_head)) return error(_("invalid orig-head: '%s'"), buf.buf); if (file_exists(state_dir_path("quiet", opts))) diff --git a/commit.c b/commit.c index 0db461f9735..de30b098dd3 100644 --- a/commit.c +++ b/commit.c @@ -59,6 +59,14 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref return c; } +struct commit *lookup_commit_object (struct repository *r, + const struct object_id *oid) +{ + struct object *obj = parse_object(r, oid); + return obj ? object_as_type(obj, OBJ_COMMIT, 0) : NULL; + +} + struct commit *lookup_commit(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); diff --git a/commit.h b/commit.h index 21e4d25ce78..fa39202fa6b 100644 --- a/commit.h +++ b/commit.h @@ -64,6 +64,19 @@ enum decoration_type { void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj); +/* + * Look up commit named by "oid" respecting replacement objects. + * Returns NULL if "oid" is not a commit or does not exist. + */ +struct commit *lookup_commit_object(struct repository *r, const struct object_id *oid); + +/* + * Look up commit named by "oid" without replacement objects or + * checking for object existence. Returns the requested commit if it + * is found in the object cache, NULL if "oid" is in the object cache + * but is not a commit and a newly allocated unparsed commit object if + * "oid" is not in the object cache. + */ struct commit *lookup_commit(struct repository *r, const struct object_id *oid); struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid);