mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-19 20:51:48 +00:00
Simplify diff example using revparse
When the examples/diff.c was written, there was not yet a revparse API. Now we can use it to make command line parsing way better with less code. Yay!
This commit is contained in:
parent
1631147c19
commit
7bd53bf385
@ -15,28 +15,9 @@ static int resolve_to_tree(
|
|||||||
git_repository *repo, const char *identifier, git_tree **tree)
|
git_repository *repo, const char *identifier, git_tree **tree)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
size_t len = strlen(identifier);
|
|
||||||
git_oid oid;
|
|
||||||
git_object *obj = NULL;
|
git_object *obj = NULL;
|
||||||
|
|
||||||
/* try to resolve as OID */
|
if (git_revparse_single(&obj, repo, identifier) < 0)
|
||||||
if (git_oid_fromstrn(&oid, identifier, len) == 0)
|
|
||||||
git_object_lookup_prefix(&obj, repo, &oid, len, GIT_OBJ_ANY);
|
|
||||||
|
|
||||||
/* try to resolve as reference */
|
|
||||||
if (obj == NULL) {
|
|
||||||
git_reference *ref, *resolved;
|
|
||||||
if (git_reference_lookup(&ref, repo, identifier) == 0) {
|
|
||||||
git_reference_resolve(&resolved, ref);
|
|
||||||
git_reference_free(ref);
|
|
||||||
if (resolved) {
|
|
||||||
git_object_lookup(&obj, repo, git_reference_target(resolved), GIT_OBJ_ANY);
|
|
||||||
git_reference_free(resolved);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj == NULL)
|
|
||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
|
|
||||||
switch (git_object_type(obj)) {
|
switch (git_object_type(obj)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user