diff options
author | Russell Belfer <rb@github.com> | 2012-05-03 16:37:25 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-05-03 16:37:25 -0700 |
commit | f917481ee84cbba481c1854cccdedb2d98377d43 (patch) | |
tree | b6276158b43f8d54358df5609fd0e508928306b2 /src/object.c | |
parent | 3fbcac89c47cb66ea193f66da6d93d1c36ed0f5e (diff) | |
download | libgit2-f917481ee84cbba481c1854cccdedb2d98377d43.tar.gz |
Support reading attributes from index
Depending on the operation, we need to consider gitattributes
in both the work dir and the index. This adds a parameter to
all of the gitattributes related functions that allows user
control of attribute reading behavior (i.e. prefer workdir,
prefer index, only use index).
This fix also covers allowing us to check attributes (and
hence do diff and status) on bare repositories.
This was a somewhat larger change that I hoped because it had
to change the cache key used for gitattributes files.
Diffstat (limited to 'src/object.c')
-rw-r--r-- | src/object.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/object.c b/src/object.c index 8e8eac4e3..7189d60b1 100644 --- a/src/object.c +++ b/src/object.c @@ -292,3 +292,42 @@ size_t git_object__size(git_otype type) return git_objects_table[type].size; } +int git_object__resolve_to_type(git_object **obj, git_otype type) +{ + int error = 0; + git_object *scan, *next; + + if (type == GIT_OBJ_ANY) + return 0; + + scan = *obj; + + while (!error && scan && git_object_type(scan) != type) { + + switch (git_object_type(scan)) { + case GIT_OBJ_COMMIT: + { + git_tree *tree = NULL; + error = git_commit_tree(&tree, (git_commit *)scan); + next = (git_object *)tree; + break; + } + + case GIT_OBJ_TAG: + error = git_tag_target(&next, (git_tag *)scan); + break; + + default: + giterr_set(GITERR_REFERENCE, "Object does not resolve to type"); + error = -1; + next = NULL; + break; + } + + git_object_free(scan); + scan = next; + } + + *obj = scan; + return error; +} |