diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2012-06-27 16:51:19 +0200 |
|---|---|---|
| committer | nulltoken <emeric.fermas@gmail.com> | 2012-06-28 19:12:40 +0200 |
| commit | faaa7c517c71b1937da6888e173c9aa763b5286a (patch) | |
| tree | bdb08aae6079ab5da249da9ebcfa9324eb378c09 /src/revparse.c | |
| parent | e28dd29b6ec9cfce63cb5db02d964376cb713bfd (diff) | |
| download | libgit2-faaa7c517c71b1937da6888e173c9aa763b5286a.tar.gz | |
revparse: return trees through the "colon" syntax
Diffstat (limited to 'src/revparse.c')
| -rw-r--r-- | src/revparse.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/revparse.c b/src/revparse.c index bc750f441..4bc6849a1 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -533,16 +533,24 @@ static int handle_linear_syntax(git_object **out, git_object *obj, const char *m static int oid_for_tree_path(git_oid *out, git_tree *tree, git_repository *repo, const char *path) { - char *str = git__strdup(path); - char *tok; - void *alloc = str; + char *str, *tok; + void *alloc; git_tree *tree2 = tree; const git_tree_entry *entry = NULL; + if (*path == '\0') { + git_oid_cpy(out, git_object_id((git_object *)tree)); + return 0; + } + + alloc = str = git__strdup(path); + while ((tok = git__strtok(&str, "/\\")) != NULL) { entry = git_tree_entry_byname(tree2, tok); if (tree2 != tree) git_tree_free(tree2); if (git_tree_entry__is_tree(entry)) { + if (str == '\0') + break; if (git_tree_lookup(&tree2, repo, &entry->oid) < 0) { git__free(alloc); return GIT_ERROR; @@ -576,7 +584,7 @@ static int handle_colon_syntax(git_object **out, } tree = (git_tree*)obj; - /* Find the blob at the given path. */ + /* Find the blob or tree at the given path. */ error = oid_for_tree_path(&oid, tree, repo, path); git_tree_free(tree); |
