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/odb.h
CHANGED
@@ -29,14 +29,14 @@ typedef struct {
|
|
29
29
|
/* EXPORT */
|
30
30
|
struct git_odb_object {
|
31
31
|
git_cached_obj cached;
|
32
|
-
|
32
|
+
void *buffer;
|
33
33
|
};
|
34
34
|
|
35
35
|
/* EXPORT */
|
36
36
|
struct git_odb {
|
37
37
|
git_refcount rc;
|
38
38
|
git_vector backends;
|
39
|
-
git_cache
|
39
|
+
git_cache own_cache;
|
40
40
|
};
|
41
41
|
|
42
42
|
/*
|
@@ -96,4 +96,7 @@ int git_odb__read_header_or_object(
|
|
96
96
|
git_odb_object **out, size_t *len_p, git_otype *type_p,
|
97
97
|
git_odb *db, const git_oid *id);
|
98
98
|
|
99
|
+
/* fully free the object; internal method, DO NOT EXPORT */
|
100
|
+
void git_odb_object__free(void *object);
|
101
|
+
|
99
102
|
#endif
|
@@ -8,7 +8,7 @@
|
|
8
8
|
#include "common.h"
|
9
9
|
#include <zlib.h>
|
10
10
|
#include "git2/object.h"
|
11
|
-
#include "git2/
|
11
|
+
#include "git2/sys/odb_backend.h"
|
12
12
|
#include "fileops.h"
|
13
13
|
#include "hash.h"
|
14
14
|
#include "odb.h"
|
@@ -33,7 +33,9 @@ typedef struct loose_backend {
|
|
33
33
|
|
34
34
|
int object_zlib_level; /** loose object zlib compression level. */
|
35
35
|
int fsync_object_files; /** loose object file fsync flag. */
|
36
|
-
|
36
|
+
|
37
|
+
size_t objects_dirlen;
|
38
|
+
char objects_dir[GIT_FLEX_ARRAY];
|
37
39
|
} loose_backend;
|
38
40
|
|
39
41
|
/* State structure for exploring directories,
|
@@ -56,24 +58,30 @@ typedef struct {
|
|
56
58
|
*
|
57
59
|
***********************************************************/
|
58
60
|
|
59
|
-
static int object_file_name(
|
61
|
+
static int object_file_name(
|
62
|
+
git_buf *name, const loose_backend *be, const git_oid *id)
|
60
63
|
{
|
61
|
-
|
62
|
-
|
63
|
-
/* expand length for 40 hex sha1 chars + 2 * '/' + '\0' */
|
64
|
-
if (git_buf_grow(name, git_buf_len(name) + GIT_OID_HEXSZ + 3) < 0)
|
64
|
+
/* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */
|
65
|
+
if (git_buf_grow(name, be->objects_dirlen + GIT_OID_HEXSZ + 3) < 0)
|
65
66
|
return -1;
|
66
67
|
|
68
|
+
git_buf_set(name, be->objects_dir, be->objects_dirlen);
|
67
69
|
git_path_to_dir(name);
|
68
70
|
|
69
71
|
/* loose object filename: aa/aaa... (41 bytes) */
|
70
|
-
git_oid_pathfmt(name->ptr +
|
72
|
+
git_oid_pathfmt(name->ptr + name->size, id);
|
71
73
|
name->size += GIT_OID_HEXSZ + 1;
|
72
74
|
name->ptr[name->size] = '\0';
|
73
75
|
|
74
76
|
return 0;
|
75
77
|
}
|
76
78
|
|
79
|
+
static int object_mkdir(const git_buf *name, const loose_backend *be)
|
80
|
+
{
|
81
|
+
return git_futils_mkdir(
|
82
|
+
name->ptr + be->objects_dirlen, be->objects_dir, GIT_OBJECT_DIR_MODE,
|
83
|
+
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
|
84
|
+
}
|
77
85
|
|
78
86
|
static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
|
79
87
|
{
|
@@ -457,7 +465,7 @@ static int locate_object(
|
|
457
465
|
loose_backend *backend,
|
458
466
|
const git_oid *oid)
|
459
467
|
{
|
460
|
-
int error = object_file_name(object_location, backend
|
468
|
+
int error = object_file_name(object_location, backend, oid);
|
461
469
|
|
462
470
|
if (!error && !git_path_exists(object_location->ptr))
|
463
471
|
return GIT_ENOTFOUND;
|
@@ -769,8 +777,8 @@ static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
|
|
769
777
|
int error = 0;
|
770
778
|
|
771
779
|
if (git_filebuf_hash(oid, &stream->fbuf) < 0 ||
|
772
|
-
object_file_name(&final_path, backend
|
773
|
-
|
780
|
+
object_file_name(&final_path, backend, oid) < 0 ||
|
781
|
+
object_mkdir(&final_path, backend) < 0)
|
774
782
|
error = -1;
|
775
783
|
/*
|
776
784
|
* Don't try to add an existing object to the repository. This
|
@@ -880,8 +888,8 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
|
|
880
888
|
git_filebuf_write(&fbuf, header, header_len);
|
881
889
|
git_filebuf_write(&fbuf, data, len);
|
882
890
|
|
883
|
-
if (object_file_name(&final_path, backend
|
884
|
-
|
891
|
+
if (object_file_name(&final_path, backend, oid) < 0 ||
|
892
|
+
object_mkdir(&final_path, backend) < 0 ||
|
885
893
|
git_filebuf_commit_at(&fbuf, final_path.ptr, GIT_OBJECT_FILE_MODE) < 0)
|
886
894
|
error = -1;
|
887
895
|
|
@@ -898,7 +906,6 @@ static void loose_backend__free(git_odb_backend *_backend)
|
|
898
906
|
assert(_backend);
|
899
907
|
backend = (loose_backend *)_backend;
|
900
908
|
|
901
|
-
git__free(backend->objects_dir);
|
902
909
|
git__free(backend);
|
903
910
|
}
|
904
911
|
|
@@ -909,13 +916,20 @@ int git_odb_backend_loose(
|
|
909
916
|
int do_fsync)
|
910
917
|
{
|
911
918
|
loose_backend *backend;
|
919
|
+
size_t objects_dirlen;
|
920
|
+
|
921
|
+
assert(backend_out && objects_dir);
|
922
|
+
|
923
|
+
objects_dirlen = strlen(objects_dir);
|
912
924
|
|
913
|
-
backend = git__calloc(1, sizeof(loose_backend));
|
925
|
+
backend = git__calloc(1, sizeof(loose_backend) + objects_dirlen + 2);
|
914
926
|
GITERR_CHECK_ALLOC(backend);
|
915
927
|
|
916
928
|
backend->parent.version = GIT_ODB_BACKEND_VERSION;
|
917
|
-
backend->
|
918
|
-
|
929
|
+
backend->objects_dirlen = objects_dirlen;
|
930
|
+
memcpy(backend->objects_dir, objects_dir, objects_dirlen);
|
931
|
+
if (backend->objects_dir[backend->objects_dirlen - 1] != '/')
|
932
|
+
backend->objects_dir[backend->objects_dirlen++] = '/';
|
919
933
|
|
920
934
|
if (compression_level < 0)
|
921
935
|
compression_level = Z_BEST_SPEED;
|
@@ -8,7 +8,8 @@
|
|
8
8
|
#include "common.h"
|
9
9
|
#include <zlib.h>
|
10
10
|
#include "git2/repository.h"
|
11
|
-
#include "git2/
|
11
|
+
#include "git2/indexer.h"
|
12
|
+
#include "git2/sys/odb_backend.h"
|
12
13
|
#include "fileops.h"
|
13
14
|
#include "hash.h"
|
14
15
|
#include "odb.h"
|
@@ -206,7 +207,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
|
|
206
207
|
return 0;
|
207
208
|
}
|
208
209
|
|
209
|
-
error =
|
210
|
+
error = git_packfile_alloc(&pack, path->ptr);
|
210
211
|
if (error == GIT_ENOTFOUND)
|
211
212
|
/* ignore missing .pack file as git does */
|
212
213
|
return 0;
|
@@ -526,80 +527,75 @@ static void pack_backend__free(git_odb_backend *_backend)
|
|
526
527
|
git__free(backend);
|
527
528
|
}
|
528
529
|
|
529
|
-
int
|
530
|
+
static int pack_backend__alloc(struct pack_backend **out, size_t initial_size)
|
530
531
|
{
|
531
|
-
struct pack_backend *backend =
|
532
|
-
|
532
|
+
struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend));
|
533
|
+
GITERR_CHECK_ALLOC(backend);
|
533
534
|
|
534
|
-
if (
|
535
|
+
if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) {
|
536
|
+
git__free(backend);
|
535
537
|
return -1;
|
538
|
+
}
|
536
539
|
|
537
|
-
backend = git__calloc(1, sizeof(struct pack_backend));
|
538
|
-
GITERR_CHECK_ALLOC(backend);
|
539
540
|
backend->parent.version = GIT_ODB_BACKEND_VERSION;
|
540
541
|
|
541
|
-
if (git_vector_init(&backend->packs, 1, NULL) < 0)
|
542
|
-
goto on_error;
|
543
|
-
|
544
|
-
if (git_vector_insert(&backend->packs, packfile) < 0)
|
545
|
-
goto on_error;
|
546
|
-
|
547
542
|
backend->parent.read = &pack_backend__read;
|
548
543
|
backend->parent.read_prefix = &pack_backend__read_prefix;
|
549
544
|
backend->parent.read_header = &pack_backend__read_header;
|
550
545
|
backend->parent.exists = &pack_backend__exists;
|
551
546
|
backend->parent.refresh = &pack_backend__refresh;
|
552
547
|
backend->parent.foreach = &pack_backend__foreach;
|
548
|
+
backend->parent.writepack = &pack_backend__writepack;
|
553
549
|
backend->parent.free = &pack_backend__free;
|
554
550
|
|
555
|
-
*
|
556
|
-
|
551
|
+
*out = backend;
|
557
552
|
return 0;
|
558
|
-
|
559
|
-
on_error:
|
560
|
-
git_vector_free(&backend->packs);
|
561
|
-
git__free(backend);
|
562
|
-
git__free(packfile);
|
563
|
-
return -1;
|
564
553
|
}
|
565
554
|
|
566
|
-
int
|
555
|
+
int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
|
567
556
|
{
|
568
557
|
struct pack_backend *backend = NULL;
|
569
|
-
|
558
|
+
struct git_pack_file *packfile = NULL;
|
570
559
|
|
571
|
-
|
572
|
-
|
573
|
-
backend->parent.version = GIT_ODB_BACKEND_VERSION;
|
560
|
+
if (pack_backend__alloc(&backend, 1) < 0)
|
561
|
+
return -1;
|
574
562
|
|
575
|
-
if (
|
576
|
-
|
563
|
+
if (git_packfile_alloc(&packfile, idx) < 0 ||
|
564
|
+
git_vector_insert(&backend->packs, packfile) < 0)
|
577
565
|
{
|
578
|
-
|
566
|
+
pack_backend__free((git_odb_backend *)backend);
|
579
567
|
return -1;
|
580
568
|
}
|
581
569
|
|
582
|
-
|
583
|
-
|
570
|
+
*backend_out = (git_odb_backend *)backend;
|
571
|
+
return 0;
|
572
|
+
}
|
573
|
+
|
574
|
+
int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
|
575
|
+
{
|
576
|
+
int error = 0;
|
577
|
+
struct pack_backend *backend = NULL;
|
578
|
+
git_buf path = GIT_BUF_INIT;
|
579
|
+
|
580
|
+
if (pack_backend__alloc(&backend, 8) < 0)
|
581
|
+
return -1;
|
584
582
|
|
583
|
+
if (!(error = git_buf_joinpath(&path, objects_dir, "pack")) &&
|
584
|
+
git_path_isdir(git_buf_cstr(&path)))
|
585
|
+
{
|
585
586
|
backend->pack_folder = git_buf_detach(&path);
|
587
|
+
|
586
588
|
error = pack_backend__refresh((git_odb_backend *)backend);
|
587
|
-
if (error < 0)
|
588
|
-
return error;
|
589
589
|
}
|
590
590
|
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
backend->parent.refresh = &pack_backend__refresh;
|
596
|
-
backend->parent.foreach = &pack_backend__foreach;
|
597
|
-
backend->parent.writepack = &pack_backend__writepack;
|
598
|
-
backend->parent.free = &pack_backend__free;
|
591
|
+
if (error < 0) {
|
592
|
+
pack_backend__free((git_odb_backend *)backend);
|
593
|
+
backend = NULL;
|
594
|
+
}
|
599
595
|
|
600
596
|
*backend_out = (git_odb_backend *)backend;
|
601
597
|
|
602
598
|
git_buf_free(&path);
|
603
599
|
|
604
|
-
return
|
600
|
+
return error;
|
605
601
|
}
|
data/vendor/libgit2/src/oid.c
CHANGED
@@ -68,12 +68,31 @@ GIT_INLINE(char) *fmt_one(char *str, unsigned int val)
|
|
68
68
|
return str;
|
69
69
|
}
|
70
70
|
|
71
|
-
void
|
71
|
+
void git_oid_nfmt(char *str, size_t n, const git_oid *oid)
|
72
72
|
{
|
73
|
-
size_t i;
|
73
|
+
size_t i, max_i;
|
74
|
+
|
75
|
+
if (!oid) {
|
76
|
+
memset(str, 0, n);
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
if (n > GIT_OID_HEXSZ) {
|
80
|
+
memset(&str[GIT_OID_HEXSZ], 0, n - GIT_OID_HEXSZ);
|
81
|
+
n = GIT_OID_HEXSZ;
|
82
|
+
}
|
83
|
+
|
84
|
+
max_i = n / 2;
|
74
85
|
|
75
|
-
for (i = 0; i <
|
86
|
+
for (i = 0; i < max_i; i++)
|
76
87
|
str = fmt_one(str, oid->id[i]);
|
88
|
+
|
89
|
+
if (n & 1)
|
90
|
+
*str++ = to_hex[oid->id[i] >> 4];
|
91
|
+
}
|
92
|
+
|
93
|
+
void git_oid_fmt(char *str, const git_oid *oid)
|
94
|
+
{
|
95
|
+
git_oid_nfmt(str, GIT_OID_HEXSZ, oid);
|
77
96
|
}
|
78
97
|
|
79
98
|
void git_oid_pathfmt(char *str, const git_oid *oid)
|
@@ -91,31 +110,20 @@ char *git_oid_allocfmt(const git_oid *oid)
|
|
91
110
|
char *str = git__malloc(GIT_OID_HEXSZ + 1);
|
92
111
|
if (!str)
|
93
112
|
return NULL;
|
94
|
-
|
95
|
-
str[GIT_OID_HEXSZ] = '\0';
|
113
|
+
git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid);
|
96
114
|
return str;
|
97
115
|
}
|
98
116
|
|
99
117
|
char *git_oid_tostr(char *out, size_t n, const git_oid *oid)
|
100
118
|
{
|
101
|
-
char str[GIT_OID_HEXSZ];
|
102
|
-
|
103
119
|
if (!out || n == 0)
|
104
120
|
return "";
|
105
121
|
|
106
|
-
n
|
107
|
-
|
108
|
-
if (oid == NULL)
|
109
|
-
n = 0;
|
110
|
-
|
111
|
-
if (n > 0) {
|
112
|
-
git_oid_fmt(str, oid);
|
113
|
-
if (n > GIT_OID_HEXSZ)
|
114
|
-
n = GIT_OID_HEXSZ;
|
115
|
-
memcpy(out, str, n);
|
116
|
-
}
|
122
|
+
if (n > GIT_OID_HEXSZ + 1)
|
123
|
+
n = GIT_OID_HEXSZ + 1;
|
117
124
|
|
118
|
-
out
|
125
|
+
git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */
|
126
|
+
out[n - 1] = '\0';
|
119
127
|
|
120
128
|
return out;
|
121
129
|
}
|
@@ -166,18 +174,26 @@ void git_oid_cpy(git_oid *out, const git_oid *src)
|
|
166
174
|
memcpy(out->id, src->id, sizeof(out->id));
|
167
175
|
}
|
168
176
|
|
177
|
+
int git_oid_cmp(const git_oid *a, const git_oid *b)
|
178
|
+
{
|
179
|
+
return git_oid__cmp(a, b);
|
180
|
+
}
|
181
|
+
|
169
182
|
int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
|
170
183
|
{
|
171
184
|
const unsigned char *a = oid_a->id;
|
172
185
|
const unsigned char *b = oid_b->id;
|
173
186
|
|
174
|
-
|
187
|
+
if (len > GIT_OID_HEXSZ)
|
188
|
+
len = GIT_OID_HEXSZ;
|
189
|
+
|
190
|
+
while (len > 1) {
|
175
191
|
if (*a != *b)
|
176
192
|
return 1;
|
177
193
|
a++;
|
178
194
|
b++;
|
179
195
|
len -= 2;
|
180
|
-
}
|
196
|
+
};
|
181
197
|
|
182
198
|
if (len)
|
183
199
|
if ((*a ^ *b) & 0xf0)
|
@@ -186,14 +202,31 @@ int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
|
|
186
202
|
return 0;
|
187
203
|
}
|
188
204
|
|
189
|
-
int
|
205
|
+
int git_oid_strcmp(const git_oid *oid_a, const char *str)
|
190
206
|
{
|
191
|
-
|
207
|
+
const unsigned char *a = oid_a->id;
|
208
|
+
unsigned char strval;
|
209
|
+
int hexval;
|
192
210
|
|
193
|
-
|
194
|
-
|
211
|
+
for (a = oid_a->id; *str && (a - oid_a->id) < GIT_OID_RAWSZ; ++a) {
|
212
|
+
if ((hexval = git__fromhex(*str++)) < 0)
|
213
|
+
return -1;
|
214
|
+
strval = hexval << 4;
|
215
|
+
if (*str) {
|
216
|
+
if ((hexval = git__fromhex(*str++)) < 0)
|
217
|
+
return -1;
|
218
|
+
strval |= hexval;
|
219
|
+
}
|
220
|
+
if (*a != strval)
|
221
|
+
return (*a - strval);
|
222
|
+
}
|
195
223
|
|
196
|
-
return
|
224
|
+
return 0;
|
225
|
+
}
|
226
|
+
|
227
|
+
int git_oid_streq(const git_oid *oid_a, const char *str)
|
228
|
+
{
|
229
|
+
return git_oid_strcmp(oid_a, str) == 0 ? 0 : -1;
|
197
230
|
}
|
198
231
|
|
199
232
|
int git_oid_iszero(const git_oid *oid_a)
|
@@ -244,8 +277,10 @@ static trie_node *push_leaf(git_oid_shorten *os, node_index idx, int push_at, co
|
|
244
277
|
|
245
278
|
idx_leaf = (node_index)os->node_count++;
|
246
279
|
|
247
|
-
if (os->node_count == SHRT_MAX)
|
280
|
+
if (os->node_count == SHRT_MAX) {
|
248
281
|
os->full = 1;
|
282
|
+
return NULL;
|
283
|
+
}
|
249
284
|
|
250
285
|
node = &os->nodes[idx];
|
251
286
|
node->children[push_at] = -idx_leaf;
|
@@ -0,0 +1,33 @@
|
|
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
|
+
#ifndef INCLUDE_oid_h__
|
8
|
+
#define INCLUDE_oid_h__
|
9
|
+
|
10
|
+
#include "git2/oid.h"
|
11
|
+
|
12
|
+
/*
|
13
|
+
* Compare two oid structures.
|
14
|
+
*
|
15
|
+
* @param a first oid structure.
|
16
|
+
* @param b second oid structure.
|
17
|
+
* @return <0, 0, >0 if a < b, a == b, a > b.
|
18
|
+
*/
|
19
|
+
GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b)
|
20
|
+
{
|
21
|
+
const unsigned char *sha1 = a->id;
|
22
|
+
const unsigned char *sha2 = b->id;
|
23
|
+
int i;
|
24
|
+
|
25
|
+
for (i = 0; i < GIT_OID_RAWSZ; i++, sha1++, sha2++) {
|
26
|
+
if (*sha1 != *sha2)
|
27
|
+
return *sha1 - *sha2;
|
28
|
+
}
|
29
|
+
|
30
|
+
return 0;
|
31
|
+
}
|
32
|
+
|
33
|
+
#endif
|