rugged 0.18.0.gh.de28323 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -4
- data/Rakefile +1 -1
- data/ext/rugged/extconf.rb +10 -0
- data/ext/rugged/rugged.c +153 -86
- data/ext/rugged/rugged.h +44 -33
- data/ext/rugged/rugged_blob.c +288 -60
- data/ext/rugged/rugged_branch.c +82 -57
- data/ext/rugged/rugged_commit.c +83 -86
- data/ext/rugged/rugged_config.c +68 -68
- data/ext/rugged/rugged_diff.c +509 -0
- data/ext/rugged/rugged_diff_delta.c +94 -0
- data/ext/rugged/rugged_diff_hunk.c +100 -0
- data/ext/rugged/rugged_diff_line.c +79 -0
- data/ext/rugged/rugged_diff_patch.c +169 -0
- data/ext/rugged/rugged_index.c +539 -8
- data/ext/rugged/rugged_note.c +74 -80
- data/ext/rugged/rugged_object.c +63 -8
- data/ext/rugged/rugged_reference.c +231 -145
- data/ext/rugged/rugged_remote.c +509 -53
- data/ext/rugged/rugged_repo.c +572 -236
- data/ext/rugged/rugged_revwalk.c +59 -36
- data/ext/rugged/rugged_settings.c +7 -9
- data/ext/rugged/rugged_signature.c +7 -11
- data/ext/rugged/rugged_tag.c +93 -39
- data/ext/rugged/rugged_tree.c +321 -58
- data/lib/rugged.rb +1 -0
- data/lib/rugged/commit.rb +16 -1
- data/lib/rugged/console.rb +9 -0
- data/lib/rugged/diff.rb +19 -0
- data/lib/rugged/diff/delta.rb +54 -0
- data/lib/rugged/diff/hunk.rb +23 -0
- data/lib/rugged/diff/line.rb +29 -0
- data/lib/rugged/diff/patch.rb +28 -0
- data/lib/rugged/repository.rb +36 -39
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +308 -1
- data/test/branch_test.rb +7 -0
- data/test/commit_test.rb +7 -10
- data/test/coverage/cover.rb +9 -1
- data/test/diff_test.rb +777 -0
- data/test/fixtures/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +1 -0
- data/test/fixtures/attr/attr1 +29 -0
- data/test/fixtures/attr/attr2 +21 -0
- data/test/fixtures/attr/attr3 +4 -0
- data/test/fixtures/attr/binfile +1 -0
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +1 -0
- data/test/fixtures/attr/gitattributes +29 -0
- data/test/fixtures/attr/gitignore +2 -0
- data/test/fixtures/attr/ign +1 -0
- data/test/fixtures/attr/macro_bad +1 -0
- data/test/fixtures/attr/macro_test +1 -0
- data/test/fixtures/attr/root_test1 +1 -0
- data/test/fixtures/attr/root_test2 +6 -0
- data/test/fixtures/attr/root_test3 +19 -0
- data/test/fixtures/attr/root_test4.txt +14 -0
- data/test/fixtures/attr/sub/abc +37 -0
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +1 -0
- data/test/fixtures/attr/sub/ign/file +1 -0
- data/test/fixtures/attr/sub/ign/sub/file +1 -0
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +1 -0
- data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
- data/test/fixtures/attr/sub/subdir_test1 +2 -0
- data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
- data/test/fixtures/diff/another.txt +38 -0
- data/test/fixtures/diff/readme.txt +36 -0
- data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
- data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
- data/test/fixtures/mergedrepo/one.txt +10 -0
- data/test/fixtures/mergedrepo/two.txt +12 -0
- data/test/fixtures/status/current_file +1 -0
- data/test/fixtures/status/ignored_file +1 -0
- data/test/fixtures/status/modified_file +2 -0
- data/test/fixtures/status/new_file +1 -0
- data/test/fixtures/status/staged_changes +2 -0
- data/test/fixtures/status/staged_changes_modified_file +3 -0
- data/test/fixtures/status/staged_delete_modified_file +1 -0
- data/test/fixtures/status/staged_new_file +1 -0
- data/test/fixtures/status/staged_new_file_modified_file +2 -0
- data/test/fixtures/status/subdir.txt +2 -0
- data/test/fixtures/status/subdir/current_file +1 -0
- data/test/fixtures/status/subdir/modified_file +2 -0
- data/test/fixtures/status/subdir/new_file +1 -0
- data/test/fixtures/status//350/277/231 +1 -0
- data/test/fixtures/testrepo.git/config +5 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/text_file.md +464 -0
- data/test/fixtures/unsymlinked.git/HEAD +1 -0
- data/test/fixtures/unsymlinked.git/config +6 -0
- data/test/fixtures/unsymlinked.git/description +1 -0
- data/test/fixtures/unsymlinked.git/info/exclude +2 -0
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
- data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
- data/test/index_test.rb +120 -0
- data/test/reference_test.rb +38 -3
- data/test/remote_test.rb +224 -3
- data/test/repo_reset_test.rb +2 -0
- data/test/repo_test.rb +147 -10
- data/test/test_helper.rb +5 -2
- data/vendor/libgit2/include/git2/attr.h +3 -3
- data/vendor/libgit2/include/git2/blob.h +11 -17
- data/vendor/libgit2/include/git2/branch.h +3 -2
- data/vendor/libgit2/include/git2/checkout.h +7 -0
- data/vendor/libgit2/include/git2/clone.h +3 -0
- data/vendor/libgit2/include/git2/commit.h +61 -66
- data/vendor/libgit2/include/git2/common.h +73 -42
- data/vendor/libgit2/include/git2/config.h +57 -71
- data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
- data/vendor/libgit2/include/git2/diff.h +179 -30
- data/vendor/libgit2/include/git2/errors.h +3 -3
- data/vendor/libgit2/include/git2/index.h +225 -146
- data/vendor/libgit2/include/git2/indexer.h +2 -22
- data/vendor/libgit2/include/git2/inttypes.h +9 -9
- data/vendor/libgit2/include/git2/merge.h +123 -5
- data/vendor/libgit2/include/git2/odb.h +59 -38
- data/vendor/libgit2/include/git2/odb_backend.h +45 -104
- data/vendor/libgit2/include/git2/oid.h +30 -19
- data/vendor/libgit2/include/git2/pack.h +21 -3
- data/vendor/libgit2/include/git2/refdb.h +0 -35
- data/vendor/libgit2/include/git2/refs.h +93 -31
- data/vendor/libgit2/include/git2/refspec.h +17 -0
- data/vendor/libgit2/include/git2/remote.h +60 -20
- data/vendor/libgit2/include/git2/repository.h +48 -70
- data/vendor/libgit2/include/git2/reset.h +3 -3
- data/vendor/libgit2/include/git2/revparse.h +22 -0
- data/vendor/libgit2/include/git2/stash.h +1 -1
- data/vendor/libgit2/include/git2/status.h +131 -56
- data/vendor/libgit2/include/git2/strarray.h +2 -2
- data/vendor/libgit2/include/git2/submodule.h +16 -16
- data/vendor/libgit2/include/git2/sys/commit.h +46 -0
- data/vendor/libgit2/include/git2/sys/config.h +71 -0
- data/vendor/libgit2/include/git2/sys/index.h +179 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
- data/vendor/libgit2/include/git2/sys/refs.h +38 -0
- data/vendor/libgit2/include/git2/sys/repository.h +106 -0
- data/vendor/libgit2/include/git2/tag.h +44 -18
- data/vendor/libgit2/include/git2/trace.h +1 -2
- data/vendor/libgit2/include/git2/transport.h +74 -0
- data/vendor/libgit2/include/git2/tree.h +12 -22
- data/vendor/libgit2/include/git2/types.h +33 -0
- data/vendor/libgit2/include/git2/version.h +2 -2
- data/vendor/libgit2/src/array.h +66 -0
- data/vendor/libgit2/src/attr.c +26 -13
- data/vendor/libgit2/src/attr_file.c +3 -2
- data/vendor/libgit2/src/attr_file.h +3 -3
- data/vendor/libgit2/src/attrcache.h +4 -4
- data/vendor/libgit2/src/blob.c +13 -9
- data/vendor/libgit2/src/blob.h +2 -2
- data/vendor/libgit2/src/branch.c +67 -49
- data/vendor/libgit2/src/cache.c +224 -54
- data/vendor/libgit2/src/cache.h +33 -20
- data/vendor/libgit2/src/checkout.c +145 -85
- data/vendor/libgit2/src/clone.c +62 -50
- data/vendor/libgit2/src/commit.c +74 -40
- data/vendor/libgit2/src/commit.h +2 -3
- data/vendor/libgit2/src/commit_list.c +14 -8
- data/vendor/libgit2/src/config.c +119 -36
- data/vendor/libgit2/src/config.h +3 -0
- data/vendor/libgit2/src/config_cache.c +24 -7
- data/vendor/libgit2/src/config_file.c +9 -6
- data/vendor/libgit2/src/crlf.c +4 -2
- data/vendor/libgit2/src/date.c +3 -3
- data/vendor/libgit2/src/delta.c +1 -1
- data/vendor/libgit2/src/diff.c +681 -303
- data/vendor/libgit2/src/diff.h +34 -2
- data/vendor/libgit2/src/diff_driver.c +405 -0
- data/vendor/libgit2/src/diff_driver.h +49 -0
- data/vendor/libgit2/src/diff_file.c +447 -0
- data/vendor/libgit2/src/diff_file.h +58 -0
- data/vendor/libgit2/src/diff_patch.c +995 -0
- data/vendor/libgit2/src/diff_patch.h +46 -0
- data/vendor/libgit2/src/diff_print.c +430 -0
- data/vendor/libgit2/src/diff_tform.c +464 -203
- data/vendor/libgit2/src/diff_xdiff.c +166 -0
- data/vendor/libgit2/src/diff_xdiff.h +28 -0
- data/vendor/libgit2/src/fetch.c +11 -4
- data/vendor/libgit2/src/fileops.c +85 -61
- data/vendor/libgit2/src/fileops.h +4 -0
- data/vendor/libgit2/src/global.c +10 -2
- data/vendor/libgit2/src/global.h +0 -8
- data/vendor/libgit2/src/hash/hash_generic.h +3 -3
- data/vendor/libgit2/src/hash/hash_win32.h +4 -4
- data/vendor/libgit2/src/hashsig.c +0 -1
- data/vendor/libgit2/src/ignore.c +68 -28
- data/vendor/libgit2/src/ignore.h +10 -1
- data/vendor/libgit2/src/index.c +666 -84
- data/vendor/libgit2/src/index.h +6 -0
- data/vendor/libgit2/src/indexer.c +10 -28
- data/vendor/libgit2/src/iterator.c +427 -283
- data/vendor/libgit2/src/iterator.h +58 -4
- data/vendor/libgit2/src/merge.c +1892 -32
- data/vendor/libgit2/src/merge.h +132 -5
- data/vendor/libgit2/src/merge_file.c +174 -0
- data/vendor/libgit2/src/merge_file.h +71 -0
- data/vendor/libgit2/src/mwindow.c +1 -1
- data/vendor/libgit2/src/notes.c +45 -48
- data/vendor/libgit2/src/object.c +89 -127
- data/vendor/libgit2/src/object.h +0 -1
- data/vendor/libgit2/src/object_api.c +129 -0
- data/vendor/libgit2/src/odb.c +156 -59
- data/vendor/libgit2/src/odb.h +5 -2
- data/vendor/libgit2/src/odb_loose.c +31 -17
- data/vendor/libgit2/src/odb_pack.c +39 -43
- data/vendor/libgit2/src/oid.c +62 -27
- data/vendor/libgit2/src/oid.h +33 -0
- data/vendor/libgit2/src/oidmap.h +4 -6
- data/vendor/libgit2/src/pack-objects.c +54 -22
- data/vendor/libgit2/src/pack.c +98 -56
- data/vendor/libgit2/src/pack.h +3 -1
- data/vendor/libgit2/src/pathspec.c +26 -1
- data/vendor/libgit2/src/pathspec.h +14 -0
- data/vendor/libgit2/src/pool.c +5 -0
- data/vendor/libgit2/src/posix.c +2 -2
- data/vendor/libgit2/src/posix.h +3 -0
- data/vendor/libgit2/src/push.c +13 -10
- data/vendor/libgit2/src/refdb.c +82 -62
- data/vendor/libgit2/src/refdb.h +16 -16
- data/vendor/libgit2/src/refdb_fs.c +386 -133
- data/vendor/libgit2/src/reflog.c +3 -1
- data/vendor/libgit2/src/refs.c +247 -221
- data/vendor/libgit2/src/refs.h +2 -1
- data/vendor/libgit2/src/refspec.c +18 -1
- data/vendor/libgit2/src/refspec.h +3 -1
- data/vendor/libgit2/src/remote.c +434 -253
- data/vendor/libgit2/src/remote.h +5 -3
- data/vendor/libgit2/src/repository.c +197 -111
- data/vendor/libgit2/src/repository.h +26 -5
- data/vendor/libgit2/src/reset.c +1 -1
- data/vendor/libgit2/src/revparse.c +84 -79
- data/vendor/libgit2/src/revwalk.c +1 -1
- data/vendor/libgit2/src/signature.c +22 -10
- data/vendor/libgit2/src/stash.c +5 -2
- data/vendor/libgit2/src/status.c +311 -107
- data/vendor/libgit2/src/status.h +23 -0
- data/vendor/libgit2/src/submodule.c +21 -13
- data/vendor/libgit2/src/tag.c +42 -31
- data/vendor/libgit2/src/tag.h +2 -3
- data/vendor/libgit2/src/thread-utils.h +105 -3
- data/vendor/libgit2/src/trace.c +1 -2
- data/vendor/libgit2/src/trace.h +3 -3
- data/vendor/libgit2/src/transport.c +18 -6
- data/vendor/libgit2/src/transports/cred.c +103 -1
- data/vendor/libgit2/src/transports/local.c +19 -9
- data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
- data/vendor/libgit2/src/transports/ssh.c +519 -0
- data/vendor/libgit2/src/transports/winhttp.c +3 -1
- data/vendor/libgit2/src/tree.c +26 -28
- data/vendor/libgit2/src/tree.h +3 -3
- data/vendor/libgit2/src/unix/posix.h +2 -0
- data/vendor/libgit2/src/util.c +43 -6
- data/vendor/libgit2/src/util.h +40 -12
- data/vendor/libgit2/src/vector.c +3 -5
- data/vendor/libgit2/src/vector.h +9 -0
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/error.c +2 -0
- data/vendor/libgit2/src/win32/findfile.c +3 -6
- data/vendor/libgit2/src/win32/posix_w32.c +85 -59
- data/vendor/libgit2/src/win32/pthread.c +16 -8
- data/vendor/libgit2/src/win32/pthread.h +7 -4
- metadata +407 -306
- data/test/coverage/HEAD.json +0 -1
- data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
- data/vendor/libgit2/src/diff_output.c +0 -1819
- data/vendor/libgit2/src/diff_output.h +0 -93
data/vendor/libgit2/src/object.c
CHANGED
@@ -18,65 +18,38 @@
|
|
18
18
|
|
19
19
|
static const int OBJECT_BASE_SIZE = 4096;
|
20
20
|
|
21
|
-
|
21
|
+
typedef struct {
|
22
22
|
const char *str; /* type name string */
|
23
|
-
int loose; /* valid loose object type flag */
|
24
23
|
size_t size; /* size in bytes of the object structure */
|
25
|
-
|
24
|
+
|
25
|
+
int (*parse)(void *self, git_odb_object *obj);
|
26
|
+
void (*free)(void *self);
|
27
|
+
} git_object_def;
|
28
|
+
|
29
|
+
static git_object_def git_objects_table[] = {
|
26
30
|
/* 0 = GIT_OBJ__EXT1 */
|
27
|
-
{ "", 0,
|
31
|
+
{ "", 0, NULL, NULL },
|
28
32
|
|
29
33
|
/* 1 = GIT_OBJ_COMMIT */
|
30
|
-
{ "commit",
|
34
|
+
{ "commit", sizeof(git_commit), git_commit__parse, git_commit__free },
|
31
35
|
|
32
36
|
/* 2 = GIT_OBJ_TREE */
|
33
|
-
{ "tree",
|
37
|
+
{ "tree", sizeof(git_tree), git_tree__parse, git_tree__free },
|
34
38
|
|
35
39
|
/* 3 = GIT_OBJ_BLOB */
|
36
|
-
{ "blob",
|
40
|
+
{ "blob", sizeof(git_blob), git_blob__parse, git_blob__free },
|
37
41
|
|
38
42
|
/* 4 = GIT_OBJ_TAG */
|
39
|
-
{ "tag",
|
43
|
+
{ "tag", sizeof(git_tag), git_tag__parse, git_tag__free },
|
40
44
|
|
41
45
|
/* 5 = GIT_OBJ__EXT2 */
|
42
|
-
{ "", 0,
|
43
|
-
|
46
|
+
{ "", 0, NULL, NULL },
|
44
47
|
/* 6 = GIT_OBJ_OFS_DELTA */
|
45
|
-
{ "OFS_DELTA", 0,
|
46
|
-
|
48
|
+
{ "OFS_DELTA", 0, NULL, NULL },
|
47
49
|
/* 7 = GIT_OBJ_REF_DELTA */
|
48
|
-
{ "REF_DELTA", 0,
|
50
|
+
{ "REF_DELTA", 0, NULL, NULL },
|
49
51
|
};
|
50
52
|
|
51
|
-
static int create_object(git_object **object_out, git_otype type)
|
52
|
-
{
|
53
|
-
git_object *object = NULL;
|
54
|
-
|
55
|
-
assert(object_out);
|
56
|
-
|
57
|
-
*object_out = NULL;
|
58
|
-
|
59
|
-
switch (type) {
|
60
|
-
case GIT_OBJ_COMMIT:
|
61
|
-
case GIT_OBJ_TAG:
|
62
|
-
case GIT_OBJ_BLOB:
|
63
|
-
case GIT_OBJ_TREE:
|
64
|
-
object = git__malloc(git_object__size(type));
|
65
|
-
GITERR_CHECK_ALLOC(object);
|
66
|
-
memset(object, 0x0, git_object__size(type));
|
67
|
-
break;
|
68
|
-
|
69
|
-
default:
|
70
|
-
giterr_set(GITERR_INVALID, "The given type is invalid");
|
71
|
-
return -1;
|
72
|
-
}
|
73
|
-
|
74
|
-
object->type = type;
|
75
|
-
|
76
|
-
*object_out = object;
|
77
|
-
return 0;
|
78
|
-
}
|
79
|
-
|
80
53
|
int git_object__from_odb_object(
|
81
54
|
git_object **object_out,
|
82
55
|
git_repository *repo,
|
@@ -84,49 +57,55 @@ int git_object__from_odb_object(
|
|
84
57
|
git_otype type)
|
85
58
|
{
|
86
59
|
int error;
|
60
|
+
size_t object_size;
|
61
|
+
git_object_def *def;
|
87
62
|
git_object *object = NULL;
|
88
63
|
|
89
|
-
|
90
|
-
|
64
|
+
assert(object_out);
|
65
|
+
*object_out = NULL;
|
66
|
+
|
67
|
+
/* Validate type match */
|
68
|
+
if (type != GIT_OBJ_ANY && type != odb_obj->cached.type) {
|
69
|
+
giterr_set(GITERR_INVALID,
|
70
|
+
"The requested type does not match the type in the ODB");
|
91
71
|
return GIT_ENOTFOUND;
|
92
72
|
}
|
93
73
|
|
94
|
-
|
74
|
+
if ((object_size = git_object__size(odb_obj->cached.type)) == 0) {
|
75
|
+
giterr_set(GITERR_INVALID, "The requested type is invalid");
|
76
|
+
return GIT_ENOTFOUND;
|
77
|
+
}
|
95
78
|
|
96
|
-
|
97
|
-
|
79
|
+
/* Allocate and initialize base object */
|
80
|
+
object = git__calloc(1, object_size);
|
81
|
+
GITERR_CHECK_ALLOC(object);
|
98
82
|
|
99
|
-
/* Initialize parent object */
|
100
83
|
git_oid_cpy(&object->cached.oid, &odb_obj->cached.oid);
|
84
|
+
object->cached.type = odb_obj->cached.type;
|
85
|
+
object->cached.size = odb_obj->cached.size;
|
101
86
|
object->repo = repo;
|
102
87
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
break;
|
107
|
-
|
108
|
-
case GIT_OBJ_TREE:
|
109
|
-
error = git_tree__parse((git_tree *)object, odb_obj);
|
110
|
-
break;
|
88
|
+
/* Parse raw object data */
|
89
|
+
def = &git_objects_table[odb_obj->cached.type];
|
90
|
+
assert(def->free && def->parse);
|
111
91
|
|
112
|
-
|
113
|
-
|
114
|
-
|
92
|
+
if ((error = def->parse(object, odb_obj)) < 0)
|
93
|
+
def->free(object);
|
94
|
+
else
|
95
|
+
*object_out = git_cache_store_parsed(&repo->objects, object);
|
115
96
|
|
116
|
-
|
117
|
-
|
118
|
-
break;
|
97
|
+
return error;
|
98
|
+
}
|
119
99
|
|
120
|
-
|
121
|
-
|
122
|
-
|
100
|
+
void git_object__free(void *obj)
|
101
|
+
{
|
102
|
+
git_otype type = ((git_object *)obj)->cached.type;
|
123
103
|
|
124
|
-
if (
|
125
|
-
|
104
|
+
if (type < 0 || ((size_t)type) >= ARRAY_SIZE(git_objects_table) ||
|
105
|
+
!git_objects_table[type].free)
|
106
|
+
git__free(obj);
|
126
107
|
else
|
127
|
-
|
128
|
-
|
129
|
-
return error;
|
108
|
+
git_objects_table[type].free(obj);
|
130
109
|
}
|
131
110
|
|
132
111
|
int git_object_lookup_prefix(
|
@@ -138,13 +117,15 @@ int git_object_lookup_prefix(
|
|
138
117
|
{
|
139
118
|
git_object *object = NULL;
|
140
119
|
git_odb *odb = NULL;
|
141
|
-
git_odb_object *odb_obj;
|
120
|
+
git_odb_object *odb_obj = NULL;
|
142
121
|
int error = 0;
|
143
122
|
|
144
123
|
assert(repo && object_out && id);
|
145
124
|
|
146
|
-
if (len < GIT_OID_MINPREFIXLEN)
|
125
|
+
if (len < GIT_OID_MINPREFIXLEN) {
|
126
|
+
giterr_set(GITERR_OBJECT, "Ambiguous lookup - OID prefix is too short");
|
147
127
|
return GIT_EAMBIGUOUS;
|
128
|
+
}
|
148
129
|
|
149
130
|
error = git_repository_odb__weakptr(&odb, repo);
|
150
131
|
if (error < 0)
|
@@ -154,27 +135,38 @@ int git_object_lookup_prefix(
|
|
154
135
|
len = GIT_OID_HEXSZ;
|
155
136
|
|
156
137
|
if (len == GIT_OID_HEXSZ) {
|
138
|
+
git_cached_obj *cached = NULL;
|
139
|
+
|
157
140
|
/* We want to match the full id : we can first look up in the cache,
|
158
141
|
* since there is no need to check for non ambiguousity
|
159
142
|
*/
|
160
|
-
|
161
|
-
if (
|
162
|
-
if (
|
163
|
-
|
164
|
-
|
165
|
-
|
143
|
+
cached = git_cache_get_any(&repo->objects, id);
|
144
|
+
if (cached != NULL) {
|
145
|
+
if (cached->flags == GIT_CACHE_STORE_PARSED) {
|
146
|
+
object = (git_object *)cached;
|
147
|
+
|
148
|
+
if (type != GIT_OBJ_ANY && type != object->cached.type) {
|
149
|
+
git_object_free(object);
|
150
|
+
giterr_set(GITERR_INVALID,
|
151
|
+
"The requested type does not match the type in ODB");
|
152
|
+
return GIT_ENOTFOUND;
|
153
|
+
}
|
154
|
+
|
155
|
+
*object_out = object;
|
156
|
+
return 0;
|
157
|
+
} else if (cached->flags == GIT_CACHE_STORE_RAW) {
|
158
|
+
odb_obj = (git_odb_object *)cached;
|
159
|
+
} else {
|
160
|
+
assert(!"Wrong caching type in the global object cache");
|
166
161
|
}
|
167
|
-
|
168
|
-
|
169
|
-
|
162
|
+
} else {
|
163
|
+
/* Object was not found in the cache, let's explore the backends.
|
164
|
+
* We could just use git_odb_read_unique_short_oid,
|
165
|
+
* it is the same cost for packed and loose object backends,
|
166
|
+
* but it may be much more costly for sqlite and hiredis.
|
167
|
+
*/
|
168
|
+
error = git_odb_read(&odb_obj, odb, id);
|
170
169
|
}
|
171
|
-
|
172
|
-
/* Object was not found in the cache, let's explore the backends.
|
173
|
-
* We could just use git_odb_read_unique_short_oid,
|
174
|
-
* it is the same cost for packed and loose object backends,
|
175
|
-
* but it may be much more costly for sqlite and hiredis.
|
176
|
-
*/
|
177
|
-
error = git_odb_read(&odb_obj, odb, id);
|
178
170
|
} else {
|
179
171
|
git_oid short_oid;
|
180
172
|
|
@@ -211,41 +203,12 @@ int git_object_lookup(git_object **object_out, git_repository *repo, const git_o
|
|
211
203
|
return git_object_lookup_prefix(object_out, repo, id, GIT_OID_HEXSZ, type);
|
212
204
|
}
|
213
205
|
|
214
|
-
void git_object__free(void *_obj)
|
215
|
-
{
|
216
|
-
git_object *object = (git_object *)_obj;
|
217
|
-
|
218
|
-
assert(object);
|
219
|
-
|
220
|
-
switch (object->type) {
|
221
|
-
case GIT_OBJ_COMMIT:
|
222
|
-
git_commit__free((git_commit *)object);
|
223
|
-
break;
|
224
|
-
|
225
|
-
case GIT_OBJ_TREE:
|
226
|
-
git_tree__free((git_tree *)object);
|
227
|
-
break;
|
228
|
-
|
229
|
-
case GIT_OBJ_TAG:
|
230
|
-
git_tag__free((git_tag *)object);
|
231
|
-
break;
|
232
|
-
|
233
|
-
case GIT_OBJ_BLOB:
|
234
|
-
git_blob__free((git_blob *)object);
|
235
|
-
break;
|
236
|
-
|
237
|
-
default:
|
238
|
-
git__free(object);
|
239
|
-
break;
|
240
|
-
}
|
241
|
-
}
|
242
|
-
|
243
206
|
void git_object_free(git_object *object)
|
244
207
|
{
|
245
208
|
if (object == NULL)
|
246
209
|
return;
|
247
210
|
|
248
|
-
git_cached_obj_decref(
|
211
|
+
git_cached_obj_decref(object);
|
249
212
|
}
|
250
213
|
|
251
214
|
const git_oid *git_object_id(const git_object *obj)
|
@@ -257,7 +220,7 @@ const git_oid *git_object_id(const git_object *obj)
|
|
257
220
|
git_otype git_object_type(const git_object *obj)
|
258
221
|
{
|
259
222
|
assert(obj);
|
260
|
-
return obj->type;
|
223
|
+
return obj->cached.type;
|
261
224
|
}
|
262
225
|
|
263
226
|
git_repository *git_object_owner(const git_object *obj)
|
@@ -293,7 +256,7 @@ int git_object_typeisloose(git_otype type)
|
|
293
256
|
if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table))
|
294
257
|
return 0;
|
295
258
|
|
296
|
-
return git_objects_table[type].
|
259
|
+
return (git_objects_table[type].size > 0) ? 1 : 0;
|
297
260
|
}
|
298
261
|
|
299
262
|
size_t git_object__size(git_otype type)
|
@@ -350,18 +313,17 @@ int git_object_peel(
|
|
350
313
|
git_object *source, *deref = NULL;
|
351
314
|
int error;
|
352
315
|
|
353
|
-
if (target_type != GIT_OBJ_TAG &&
|
354
|
-
target_type != GIT_OBJ_COMMIT &&
|
355
|
-
target_type != GIT_OBJ_TREE &&
|
356
|
-
target_type != GIT_OBJ_BLOB &&
|
357
|
-
target_type != GIT_OBJ_ANY)
|
358
|
-
return GIT_EINVALIDSPEC;
|
359
|
-
|
360
316
|
assert(object && peeled);
|
361
317
|
|
362
318
|
if (git_object_type(object) == target_type)
|
363
319
|
return git_object_dup(peeled, (git_object *)object);
|
364
320
|
|
321
|
+
assert(target_type == GIT_OBJ_TAG ||
|
322
|
+
target_type == GIT_OBJ_COMMIT ||
|
323
|
+
target_type == GIT_OBJ_TREE ||
|
324
|
+
target_type == GIT_OBJ_BLOB ||
|
325
|
+
target_type == GIT_OBJ_ANY);
|
326
|
+
|
365
327
|
source = (git_object *)object;
|
366
328
|
|
367
329
|
while (!(error = dereference_object(&deref, source))) {
|
data/vendor/libgit2/src/object.h
CHANGED
@@ -0,0 +1,129 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#include "git2/object.h"
|
8
|
+
|
9
|
+
#include "common.h"
|
10
|
+
#include "repository.h"
|
11
|
+
|
12
|
+
#include "commit.h"
|
13
|
+
#include "tree.h"
|
14
|
+
#include "blob.h"
|
15
|
+
#include "tag.h"
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Blob
|
19
|
+
*/
|
20
|
+
int git_commit_lookup(git_commit **out, git_repository *repo, const git_oid *id)
|
21
|
+
{
|
22
|
+
return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_COMMIT);
|
23
|
+
}
|
24
|
+
|
25
|
+
int git_commit_lookup_prefix(git_commit **out, git_repository *repo, const git_oid *id, size_t len)
|
26
|
+
{
|
27
|
+
return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_COMMIT);
|
28
|
+
}
|
29
|
+
|
30
|
+
void git_commit_free(git_commit *obj)
|
31
|
+
{
|
32
|
+
git_object_free((git_object *)obj);
|
33
|
+
}
|
34
|
+
|
35
|
+
const git_oid *git_commit_id(const git_commit *obj)
|
36
|
+
{
|
37
|
+
return git_object_id((const git_object *)obj);
|
38
|
+
}
|
39
|
+
|
40
|
+
git_repository *git_commit_owner(const git_commit *obj)
|
41
|
+
{
|
42
|
+
return git_object_owner((const git_object *)obj);
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Tree
|
48
|
+
*/
|
49
|
+
int git_tree_lookup(git_tree **out, git_repository *repo, const git_oid *id)
|
50
|
+
{
|
51
|
+
return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_TREE);
|
52
|
+
}
|
53
|
+
|
54
|
+
int git_tree_lookup_prefix(git_tree **out, git_repository *repo, const git_oid *id, size_t len)
|
55
|
+
{
|
56
|
+
return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_TREE);
|
57
|
+
}
|
58
|
+
|
59
|
+
void git_tree_free(git_tree *obj)
|
60
|
+
{
|
61
|
+
git_object_free((git_object *)obj);
|
62
|
+
}
|
63
|
+
|
64
|
+
const git_oid *git_tree_id(const git_tree *obj)
|
65
|
+
{
|
66
|
+
return git_object_id((const git_object *)obj);
|
67
|
+
}
|
68
|
+
|
69
|
+
git_repository *git_tree_owner(const git_tree *obj)
|
70
|
+
{
|
71
|
+
return git_object_owner((const git_object *)obj);
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Tag
|
77
|
+
*/
|
78
|
+
int git_tag_lookup(git_tag **out, git_repository *repo, const git_oid *id)
|
79
|
+
{
|
80
|
+
return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_TAG);
|
81
|
+
}
|
82
|
+
|
83
|
+
int git_tag_lookup_prefix(git_tag **out, git_repository *repo, const git_oid *id, size_t len)
|
84
|
+
{
|
85
|
+
return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_TAG);
|
86
|
+
}
|
87
|
+
|
88
|
+
void git_tag_free(git_tag *obj)
|
89
|
+
{
|
90
|
+
git_object_free((git_object *)obj);
|
91
|
+
}
|
92
|
+
|
93
|
+
const git_oid *git_tag_id(const git_tag *obj)
|
94
|
+
{
|
95
|
+
return git_object_id((const git_object *)obj);
|
96
|
+
}
|
97
|
+
|
98
|
+
git_repository *git_tag_owner(const git_tag *obj)
|
99
|
+
{
|
100
|
+
return git_object_owner((const git_object *)obj);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Blob
|
105
|
+
*/
|
106
|
+
int git_blob_lookup(git_blob **out, git_repository *repo, const git_oid *id)
|
107
|
+
{
|
108
|
+
return git_object_lookup((git_object **)out, repo, id, GIT_OBJ_BLOB);
|
109
|
+
}
|
110
|
+
|
111
|
+
int git_blob_lookup_prefix(git_blob **out, git_repository *repo, const git_oid *id, size_t len)
|
112
|
+
{
|
113
|
+
return git_object_lookup_prefix((git_object **)out, repo, id, len, GIT_OBJ_BLOB);
|
114
|
+
}
|
115
|
+
|
116
|
+
void git_blob_free(git_blob *obj)
|
117
|
+
{
|
118
|
+
git_object_free((git_object *)obj);
|
119
|
+
}
|
120
|
+
|
121
|
+
const git_oid *git_blob_id(const git_blob *obj)
|
122
|
+
{
|
123
|
+
return git_object_id((const git_object *)obj);
|
124
|
+
}
|
125
|
+
|
126
|
+
git_repository *git_blob_owner(const git_blob *obj)
|
127
|
+
{
|
128
|
+
return git_object_owner((const git_object *)obj);
|
129
|
+
}
|