revwalk: accept committish objects

Let the user push committish objects and peel them to figure out which
commit to push to our queue.

This is for convenience and for allowing uses of

    git_revwalk_push_glob(w, "tags")

with annotated tags.
This commit is contained in:
Carlos Martín Nieto 2014-02-01 12:51:36 +01:00
parent 7369ea8075
commit f61272e047
2 changed files with 17 additions and 12 deletions

View File

@ -87,7 +87,7 @@ GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
/** /**
* Mark a commit to start traversal from. * Mark a commit to start traversal from.
* *
* The given OID must belong to a commit on the walked * The given OID must belong to a committish on the walked
* repository. * repository.
* *
* The given commit will be used as one of the roots * The given commit will be used as one of the roots
@ -127,7 +127,7 @@ GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
/** /**
* Mark a commit (and its ancestors) uninteresting for the output. * Mark a commit (and its ancestors) uninteresting for the output.
* *
* The given OID must belong to a commit on the walked * The given OID must belong to a committish on the walked
* repository. * repository.
* *
* The resolved commit and all its parents will be hidden from the * The resolved commit and all its parents will be hidden from the
@ -166,7 +166,7 @@ GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
/** /**
* Push the OID pointed to by a reference * Push the OID pointed to by a reference
* *
* The reference must point to a commit. * The reference must point to a committish.
* *
* @param walk the walker being used for the traversal * @param walk the walker being used for the traversal
* @param refname the reference to push * @param refname the reference to push
@ -177,7 +177,7 @@ GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
/** /**
* Hide the OID pointed to by a reference * Hide the OID pointed to by a reference
* *
* The reference must point to a commit. * The reference must point to a committish.
* *
* @param walk the walker being used for the traversal * @param walk the walker being used for the traversal
* @param refname the reference to hide * @param refname the reference to hide

View File

@ -112,23 +112,28 @@ static int process_commit_parents(git_revwalk *walk, git_commit_list_node *commi
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting) static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
{ {
git_oid commit_id;
int error; int error;
git_object *obj; git_object *obj, *oobj;
git_otype type;
git_commit_list_node *commit; git_commit_list_node *commit;
if ((error = git_object_lookup(&obj, walk->repo, oid, GIT_OBJ_ANY)) < 0) if ((error = git_object_lookup(&oobj, walk->repo, oid, GIT_OBJ_ANY)) < 0)
return error; return error;
type = git_object_type(obj); error = git_object_peel(&obj, oobj, GIT_OBJ_COMMIT);
git_object_free(obj); git_object_free(oobj);
if (type != GIT_OBJ_COMMIT) { if (error == GIT_ENOTFOUND) {
giterr_set(GITERR_INVALID, "Object is no commit object"); giterr_set(GITERR_INVALID, "Object is not a committish");
return -1; return -1;
} }
if (error < 0)
return error;
commit = git_revwalk__commit_lookup(walk, oid); git_oid_cpy(&commit_id, git_object_id(obj));
git_object_free(obj);
commit = git_revwalk__commit_lookup(walk, &commit_id);
if (commit == NULL) if (commit == NULL)
return -1; /* error already reported by failed lookup */ return -1; /* error already reported by failed lookup */