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
@@ -9,16 +9,18 @@
|
|
9
9
|
#include "hash.h"
|
10
10
|
#include "repository.h"
|
11
11
|
#include "fileops.h"
|
12
|
+
#include "filebuf.h"
|
12
13
|
#include "pack.h"
|
13
14
|
#include "reflog.h"
|
14
|
-
#include "config.h"
|
15
15
|
#include "refdb.h"
|
16
16
|
#include "refdb_fs.h"
|
17
|
+
#include "iterator.h"
|
17
18
|
|
18
19
|
#include <git2/tag.h>
|
19
20
|
#include <git2/object.h>
|
20
21
|
#include <git2/refdb.h>
|
21
|
-
#include <git2/refdb_backend.h>
|
22
|
+
#include <git2/sys/refdb_backend.h>
|
23
|
+
#include <git2/sys/refs.h>
|
22
24
|
|
23
25
|
GIT__USE_STRMAP;
|
24
26
|
|
@@ -26,8 +28,16 @@ GIT__USE_STRMAP;
|
|
26
28
|
#define MAX_NESTING_LEVEL 10
|
27
29
|
|
28
30
|
enum {
|
29
|
-
|
30
|
-
|
31
|
+
PACKREF_HAS_PEEL = 1,
|
32
|
+
PACKREF_WAS_LOOSE = 2,
|
33
|
+
PACKREF_CANNOT_PEEL = 4,
|
34
|
+
PACKREF_SHADOWED = 8,
|
35
|
+
};
|
36
|
+
|
37
|
+
enum {
|
38
|
+
PEELING_NONE = 0,
|
39
|
+
PEELING_STANDARD,
|
40
|
+
PEELING_FULL
|
31
41
|
};
|
32
42
|
|
33
43
|
struct packref {
|
@@ -41,10 +51,10 @@ typedef struct refdb_fs_backend {
|
|
41
51
|
git_refdb_backend parent;
|
42
52
|
|
43
53
|
git_repository *repo;
|
44
|
-
|
45
|
-
git_refdb *refdb;
|
54
|
+
char *path;
|
46
55
|
|
47
56
|
git_refcache refcache;
|
57
|
+
int peeling_mode;
|
48
58
|
} refdb_fs_backend;
|
49
59
|
|
50
60
|
static int reference_read(
|
@@ -62,7 +72,7 @@ static int reference_read(
|
|
62
72
|
/* Determine the full path of the file */
|
63
73
|
if (git_buf_joinpath(&path, repo_path, ref_name) < 0)
|
64
74
|
return -1;
|
65
|
-
|
75
|
+
|
66
76
|
result = git_futils_readbuffer_updated(file_content, path.ptr, mtime, NULL, updated);
|
67
77
|
git_buf_free(&path);
|
68
78
|
|
@@ -99,7 +109,7 @@ static int packed_parse_oid(
|
|
99
109
|
|
100
110
|
refname_len = refname_end - refname_begin;
|
101
111
|
|
102
|
-
ref =
|
112
|
+
ref = git__calloc(1, sizeof(struct packref) + refname_len + 1);
|
103
113
|
GITERR_CHECK_ALLOC(ref);
|
104
114
|
|
105
115
|
memcpy(ref->name, refname_begin, refname_len);
|
@@ -107,11 +117,8 @@ static int packed_parse_oid(
|
|
107
117
|
|
108
118
|
git_oid_cpy(&ref->oid, &id);
|
109
119
|
|
110
|
-
ref->flags = 0;
|
111
|
-
|
112
120
|
*ref_out = ref;
|
113
121
|
*buffer_out = refname_end + 1;
|
114
|
-
|
115
122
|
return 0;
|
116
123
|
|
117
124
|
corrupt:
|
@@ -133,10 +140,6 @@ static int packed_parse_peel(
|
|
133
140
|
if (tag_ref == NULL)
|
134
141
|
goto corrupt;
|
135
142
|
|
136
|
-
/* Ensure reference is a tag */
|
137
|
-
if (git__prefixcmp(tag_ref->name, GIT_REFS_TAGS_DIR) != 0)
|
138
|
-
goto corrupt;
|
139
|
-
|
140
143
|
if (buffer + GIT_OID_HEXSZ > buffer_end)
|
141
144
|
goto corrupt;
|
142
145
|
|
@@ -155,6 +158,7 @@ static int packed_parse_peel(
|
|
155
158
|
goto corrupt;
|
156
159
|
}
|
157
160
|
|
161
|
+
tag_ref->flags |= PACKREF_HAS_PEEL;
|
158
162
|
*buffer_out = buffer;
|
159
163
|
return 0;
|
160
164
|
|
@@ -175,7 +179,10 @@ static int packed_load(refdb_fs_backend *backend)
|
|
175
179
|
ref_cache->packfile = git_strmap_alloc();
|
176
180
|
GITERR_CHECK_ALLOC(ref_cache->packfile);
|
177
181
|
}
|
178
|
-
|
182
|
+
|
183
|
+
if (backend->path == NULL)
|
184
|
+
return 0;
|
185
|
+
|
179
186
|
result = reference_read(&packfile, &ref_cache->packfile_time,
|
180
187
|
backend->path, GIT_PACKEDREFS_FILE, &updated);
|
181
188
|
|
@@ -193,7 +200,7 @@ static int packed_load(refdb_fs_backend *backend)
|
|
193
200
|
|
194
201
|
if (result < 0)
|
195
202
|
return -1;
|
196
|
-
|
203
|
+
|
197
204
|
if (!updated)
|
198
205
|
return 0;
|
199
206
|
|
@@ -206,6 +213,30 @@ static int packed_load(refdb_fs_backend *backend)
|
|
206
213
|
buffer_start = (const char *)packfile.ptr;
|
207
214
|
buffer_end = (const char *)(buffer_start) + packfile.size;
|
208
215
|
|
216
|
+
backend->peeling_mode = PEELING_NONE;
|
217
|
+
|
218
|
+
if (buffer_start[0] == '#') {
|
219
|
+
static const char *traits_header = "# pack-refs with: ";
|
220
|
+
|
221
|
+
if (git__prefixcmp(buffer_start, traits_header) == 0) {
|
222
|
+
char *traits = (char *)buffer_start + strlen(traits_header);
|
223
|
+
char *traits_end = strchr(traits, '\n');
|
224
|
+
|
225
|
+
if (traits_end == NULL)
|
226
|
+
goto parse_failed;
|
227
|
+
|
228
|
+
*traits_end = '\0';
|
229
|
+
|
230
|
+
if (strstr(traits, " fully-peeled ") != NULL) {
|
231
|
+
backend->peeling_mode = PEELING_FULL;
|
232
|
+
} else if (strstr(traits, " peeled ") != NULL) {
|
233
|
+
backend->peeling_mode = PEELING_STANDARD;
|
234
|
+
}
|
235
|
+
|
236
|
+
buffer_start = traits_end + 1;
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
209
240
|
while (buffer_start < buffer_end && buffer_start[0] == '#') {
|
210
241
|
buffer_start = strchr(buffer_start, '\n');
|
211
242
|
if (buffer_start == NULL)
|
@@ -224,6 +255,10 @@ static int packed_load(refdb_fs_backend *backend)
|
|
224
255
|
if (buffer_start[0] == '^') {
|
225
256
|
if (packed_parse_peel(ref, &buffer_start, buffer_end) < 0)
|
226
257
|
goto parse_failed;
|
258
|
+
} else if (backend->peeling_mode == PEELING_FULL ||
|
259
|
+
(backend->peeling_mode == PEELING_STANDARD &&
|
260
|
+
git__prefixcmp(ref->name, GIT_REFS_TAGS_DIR) == 0)) {
|
261
|
+
ref->flags |= PACKREF_CANNOT_PEEL;
|
227
262
|
}
|
228
263
|
|
229
264
|
git_strmap_insert(ref_cache->packfile, ref->name, ref, err);
|
@@ -241,7 +276,7 @@ parse_failed:
|
|
241
276
|
return -1;
|
242
277
|
}
|
243
278
|
|
244
|
-
static int loose_parse_oid(git_oid *oid, git_buf *file_content)
|
279
|
+
static int loose_parse_oid(git_oid *oid, const char *filename, git_buf *file_content)
|
245
280
|
{
|
246
281
|
size_t len;
|
247
282
|
const char *str;
|
@@ -263,7 +298,7 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
|
|
263
298
|
return 0;
|
264
299
|
|
265
300
|
corrupted:
|
266
|
-
giterr_set(GITERR_REFERENCE, "Corrupted loose reference file");
|
301
|
+
giterr_set(GITERR_REFERENCE, "Corrupted loose reference file: %s", filename);
|
267
302
|
return -1;
|
268
303
|
}
|
269
304
|
|
@@ -284,19 +319,19 @@ static int loose_lookup_to_packfile(
|
|
284
319
|
git_buf_rtrim(&ref_file);
|
285
320
|
|
286
321
|
name_len = strlen(name);
|
287
|
-
ref =
|
322
|
+
ref = git__calloc(1, sizeof(struct packref) + name_len + 1);
|
288
323
|
GITERR_CHECK_ALLOC(ref);
|
289
324
|
|
290
325
|
memcpy(ref->name, name, name_len);
|
291
326
|
ref->name[name_len] = 0;
|
292
327
|
|
293
|
-
if (loose_parse_oid(&ref->oid, &ref_file) < 0) {
|
328
|
+
if (loose_parse_oid(&ref->oid, name, &ref_file) < 0) {
|
294
329
|
git_buf_free(&ref_file);
|
295
330
|
git__free(ref);
|
296
331
|
return -1;
|
297
332
|
}
|
298
333
|
|
299
|
-
ref->flags =
|
334
|
+
ref->flags = PACKREF_WAS_LOOSE;
|
300
335
|
|
301
336
|
*ref_out = ref;
|
302
337
|
git_buf_free(&ref_file);
|
@@ -430,12 +465,12 @@ static int loose_lookup(
|
|
430
465
|
goto done;
|
431
466
|
}
|
432
467
|
|
433
|
-
*out = git_reference__alloc_symbolic(
|
468
|
+
*out = git_reference__alloc_symbolic(ref_name, target);
|
434
469
|
} else {
|
435
|
-
if ((error = loose_parse_oid(&oid, &ref_file)) < 0)
|
470
|
+
if ((error = loose_parse_oid(&oid, ref_name, &ref_file)) < 0)
|
436
471
|
goto done;
|
437
|
-
|
438
|
-
*out = git_reference__alloc(
|
472
|
+
|
473
|
+
*out = git_reference__alloc(ref_name, &oid, NULL);
|
439
474
|
}
|
440
475
|
|
441
476
|
if (*out == NULL)
|
@@ -456,19 +491,19 @@ static int packed_map_entry(
|
|
456
491
|
|
457
492
|
if (packed_load(backend) < 0)
|
458
493
|
return -1;
|
459
|
-
|
494
|
+
|
460
495
|
/* Look up on the packfile */
|
461
496
|
packfile_refs = backend->refcache.packfile;
|
462
497
|
|
463
498
|
*pos = git_strmap_lookup_index(packfile_refs, ref_name);
|
464
|
-
|
499
|
+
|
465
500
|
if (!git_strmap_valid_index(packfile_refs, *pos)) {
|
466
501
|
giterr_set(GITERR_REFERENCE, "Reference '%s' not found", ref_name);
|
467
502
|
return GIT_ENOTFOUND;
|
468
503
|
}
|
469
504
|
|
470
505
|
*entry = git_strmap_value_at(packfile_refs, *pos);
|
471
|
-
|
506
|
+
|
472
507
|
return 0;
|
473
508
|
}
|
474
509
|
|
@@ -480,14 +515,14 @@ static int packed_lookup(
|
|
480
515
|
struct packref *entry;
|
481
516
|
khiter_t pos;
|
482
517
|
int error = 0;
|
483
|
-
|
518
|
+
|
484
519
|
if ((error = packed_map_entry(&entry, &pos, backend, ref_name)) < 0)
|
485
520
|
return error;
|
486
521
|
|
487
|
-
if ((*out = git_reference__alloc(
|
522
|
+
if ((*out = git_reference__alloc(ref_name,
|
488
523
|
&entry->oid, &entry->peel)) == NULL)
|
489
524
|
return -1;
|
490
|
-
|
525
|
+
|
491
526
|
return 0;
|
492
527
|
}
|
493
528
|
|
@@ -516,108 +551,239 @@ static int refdb_fs_backend__lookup(
|
|
516
551
|
return result;
|
517
552
|
}
|
518
553
|
|
519
|
-
struct
|
520
|
-
|
521
|
-
size_t repo_path_len;
|
522
|
-
unsigned int list_type:2;
|
554
|
+
typedef struct {
|
555
|
+
git_reference_iterator parent;
|
523
556
|
|
524
|
-
|
525
|
-
|
526
|
-
int
|
527
|
-
|
557
|
+
char *glob;
|
558
|
+
git_vector loose;
|
559
|
+
unsigned int loose_pos;
|
560
|
+
khiter_t packed_pos;
|
561
|
+
} refdb_fs_iter;
|
528
562
|
|
529
|
-
static
|
563
|
+
static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
|
530
564
|
{
|
531
|
-
|
532
|
-
|
565
|
+
refdb_fs_iter *iter = (refdb_fs_iter *) _iter;
|
566
|
+
char *loose_path;
|
567
|
+
size_t i;
|
568
|
+
|
569
|
+
git_vector_foreach(&iter->loose, i, loose_path) {
|
570
|
+
git__free(loose_path);
|
571
|
+
}
|
533
572
|
|
534
|
-
|
573
|
+
git_vector_free(&iter->loose);
|
535
574
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
575
|
+
git__free(iter->glob);
|
576
|
+
git__free(iter);
|
577
|
+
}
|
578
|
+
|
579
|
+
static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
|
580
|
+
{
|
581
|
+
git_strmap *packfile = backend->refcache.packfile;
|
582
|
+
git_buf path = GIT_BUF_INIT;
|
583
|
+
git_iterator *fsit;
|
584
|
+
const git_index_entry *entry = NULL;
|
585
|
+
|
586
|
+
if (!backend->path) /* do nothing if no path for loose refs */
|
587
|
+
return 0;
|
588
|
+
|
589
|
+
if (git_buf_printf(&path, "%s/refs", backend->path) < 0)
|
590
|
+
return -1;
|
591
|
+
|
592
|
+
if (git_iterator_for_filesystem(&fsit, git_buf_cstr(&path), 0, NULL, NULL) < 0)
|
593
|
+
return -1;
|
594
|
+
|
595
|
+
git_vector_init(&iter->loose, 8, NULL);
|
596
|
+
git_buf_sets(&path, GIT_REFS_DIR);
|
597
|
+
|
598
|
+
while (!git_iterator_advance(&entry, fsit)) {
|
599
|
+
const char *ref_name;
|
600
|
+
khiter_t pos;
|
601
|
+
|
602
|
+
git_buf_truncate(&path, strlen(GIT_REFS_DIR));
|
603
|
+
git_buf_puts(&path, entry->path);
|
604
|
+
ref_name = git_buf_cstr(&path);
|
605
|
+
|
606
|
+
if (git__suffixcmp(ref_name, ".lock") == 0 ||
|
607
|
+
(iter->glob && p_fnmatch(iter->glob, ref_name, 0) != 0))
|
608
|
+
continue;
|
609
|
+
|
610
|
+
pos = git_strmap_lookup_index(packfile, ref_name);
|
611
|
+
if (git_strmap_valid_index(packfile, pos)) {
|
612
|
+
struct packref *ref = git_strmap_value_at(packfile, pos);
|
613
|
+
ref->flags |= PACKREF_SHADOWED;
|
614
|
+
}
|
615
|
+
|
616
|
+
git_vector_insert(&iter->loose, git__strdup(ref_name));
|
541
617
|
}
|
542
618
|
|
543
|
-
|
544
|
-
|
619
|
+
git_iterator_free(fsit);
|
620
|
+
git_buf_free(&path);
|
621
|
+
|
622
|
+
return 0;
|
545
623
|
}
|
546
624
|
|
547
|
-
static int
|
625
|
+
static int refdb_fs_backend__iterator_next(
|
626
|
+
git_reference **out, git_reference_iterator *_iter)
|
548
627
|
{
|
549
|
-
|
550
|
-
|
628
|
+
refdb_fs_iter *iter = (refdb_fs_iter *)_iter;
|
629
|
+
refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.db->backend;
|
630
|
+
git_strmap *packfile = backend->refcache.packfile;
|
551
631
|
|
552
|
-
|
553
|
-
|
632
|
+
while (iter->loose_pos < iter->loose.length) {
|
633
|
+
const char *path = git_vector_get(&iter->loose, iter->loose_pos++);
|
554
634
|
|
555
|
-
|
556
|
-
|
557
|
-
return 0;
|
635
|
+
if (loose_lookup(out, backend, path) == 0)
|
636
|
+
return 0;
|
558
637
|
|
559
|
-
|
560
|
-
if ((data->list_type & loose_guess_rtype(full_path)) == 0)
|
561
|
-
return 0; /* we are filtering out this reference */
|
638
|
+
giterr_clear();
|
562
639
|
}
|
563
640
|
|
564
|
-
|
565
|
-
|
641
|
+
while (iter->packed_pos < kh_end(packfile)) {
|
642
|
+
struct packref *ref = NULL;
|
643
|
+
|
644
|
+
while (!kh_exist(packfile, iter->packed_pos)) {
|
645
|
+
iter->packed_pos++;
|
646
|
+
if (iter->packed_pos == kh_end(packfile))
|
647
|
+
return GIT_ITEROVER;
|
648
|
+
}
|
649
|
+
|
650
|
+
ref = kh_val(packfile, iter->packed_pos);
|
651
|
+
iter->packed_pos++;
|
652
|
+
|
653
|
+
if (ref->flags & PACKREF_SHADOWED)
|
654
|
+
continue;
|
655
|
+
|
656
|
+
if (iter->glob && p_fnmatch(iter->glob, ref->name, 0) != 0)
|
657
|
+
continue;
|
658
|
+
|
659
|
+
*out = git_reference__alloc(ref->name, &ref->oid, &ref->peel);
|
660
|
+
if (*out == NULL)
|
661
|
+
return -1;
|
662
|
+
|
663
|
+
return 0;
|
664
|
+
}
|
665
|
+
|
666
|
+
return GIT_ITEROVER;
|
667
|
+
}
|
668
|
+
|
669
|
+
static int refdb_fs_backend__iterator_next_name(
|
670
|
+
const char **out, git_reference_iterator *_iter)
|
671
|
+
{
|
672
|
+
refdb_fs_iter *iter = (refdb_fs_iter *)_iter;
|
673
|
+
refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.db->backend;
|
674
|
+
git_strmap *packfile = backend->refcache.packfile;
|
675
|
+
|
676
|
+
while (iter->loose_pos < iter->loose.length) {
|
677
|
+
const char *path = git_vector_get(&iter->loose, iter->loose_pos++);
|
678
|
+
|
679
|
+
if (git_strmap_exists(packfile, path))
|
680
|
+
continue;
|
681
|
+
|
682
|
+
*out = path;
|
566
683
|
return 0;
|
684
|
+
}
|
685
|
+
|
686
|
+
while (iter->packed_pos < kh_end(packfile)) {
|
687
|
+
while (!kh_exist(packfile, iter->packed_pos)) {
|
688
|
+
iter->packed_pos++;
|
689
|
+
if (iter->packed_pos == kh_end(packfile))
|
690
|
+
return GIT_ITEROVER;
|
691
|
+
}
|
692
|
+
|
693
|
+
*out = kh_key(packfile, iter->packed_pos);
|
694
|
+
iter->packed_pos++;
|
567
695
|
|
568
|
-
|
569
|
-
|
696
|
+
if (iter->glob && p_fnmatch(iter->glob, *out, 0) != 0)
|
697
|
+
continue;
|
698
|
+
|
699
|
+
return 0;
|
700
|
+
}
|
570
701
|
|
571
|
-
return
|
702
|
+
return GIT_ITEROVER;
|
572
703
|
}
|
573
704
|
|
574
|
-
static int
|
575
|
-
git_refdb_backend *_backend,
|
576
|
-
unsigned int list_type,
|
577
|
-
git_reference_foreach_cb callback,
|
578
|
-
void *payload)
|
705
|
+
static int refdb_fs_backend__iterator(
|
706
|
+
git_reference_iterator **out, git_refdb_backend *_backend, const char *glob)
|
579
707
|
{
|
708
|
+
refdb_fs_iter *iter;
|
580
709
|
refdb_fs_backend *backend;
|
581
|
-
int result;
|
582
|
-
struct dirent_list_data data;
|
583
|
-
git_buf refs_path = GIT_BUF_INIT;
|
584
|
-
const char *ref_name;
|
585
|
-
void *ref = NULL;
|
586
|
-
|
587
|
-
GIT_UNUSED(ref);
|
588
710
|
|
589
711
|
assert(_backend);
|
590
712
|
backend = (refdb_fs_backend *)_backend;
|
591
713
|
|
592
714
|
if (packed_load(backend) < 0)
|
593
715
|
return -1;
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
716
|
+
|
717
|
+
iter = git__calloc(1, sizeof(refdb_fs_iter));
|
718
|
+
GITERR_CHECK_ALLOC(iter);
|
719
|
+
|
720
|
+
if (glob != NULL)
|
721
|
+
iter->glob = git__strdup(glob);
|
722
|
+
|
723
|
+
iter->parent.next = refdb_fs_backend__iterator_next;
|
724
|
+
iter->parent.next_name = refdb_fs_backend__iterator_next_name;
|
725
|
+
iter->parent.free = refdb_fs_backend__iterator_free;
|
726
|
+
|
727
|
+
if (iter_load_loose_paths(backend, iter) < 0) {
|
728
|
+
refdb_fs_backend__iterator_free((git_reference_iterator *)iter);
|
729
|
+
return -1;
|
601
730
|
}
|
602
731
|
|
603
|
-
|
604
|
-
|
732
|
+
*out = (git_reference_iterator *)iter;
|
733
|
+
return 0;
|
734
|
+
}
|
605
735
|
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
736
|
+
static bool ref_is_available(
|
737
|
+
const char *old_ref, const char *new_ref, const char *this_ref)
|
738
|
+
{
|
739
|
+
if (old_ref == NULL || strcmp(old_ref, this_ref)) {
|
740
|
+
size_t reflen = strlen(this_ref);
|
741
|
+
size_t newlen = strlen(new_ref);
|
742
|
+
size_t cmplen = reflen < newlen ? reflen : newlen;
|
743
|
+
const char *lead = reflen < newlen ? new_ref : this_ref;
|
744
|
+
|
745
|
+
if (!strncmp(new_ref, this_ref, cmplen) && lead[cmplen] == '/') {
|
746
|
+
return false;
|
747
|
+
}
|
748
|
+
}
|
612
749
|
|
613
|
-
|
750
|
+
return true;
|
751
|
+
}
|
752
|
+
|
753
|
+
static int reference_path_available(
|
754
|
+
refdb_fs_backend *backend,
|
755
|
+
const char *new_ref,
|
756
|
+
const char* old_ref,
|
757
|
+
int force)
|
758
|
+
{
|
759
|
+
struct packref *this_ref;
|
760
|
+
|
761
|
+
if (packed_load(backend) < 0)
|
614
762
|
return -1;
|
615
763
|
|
616
|
-
|
764
|
+
if (!force) {
|
765
|
+
int exists;
|
617
766
|
|
618
|
-
|
767
|
+
if (refdb_fs_backend__exists(&exists, (git_refdb_backend *)backend, new_ref) < 0)
|
768
|
+
return -1;
|
769
|
+
|
770
|
+
if (exists) {
|
771
|
+
giterr_set(GITERR_REFERENCE,
|
772
|
+
"Failed to write reference '%s': a reference with "
|
773
|
+
" that name already exists.", new_ref);
|
774
|
+
return GIT_EEXISTS;
|
775
|
+
}
|
776
|
+
}
|
619
777
|
|
620
|
-
|
778
|
+
git_strmap_foreach_value(backend->refcache.packfile, this_ref, {
|
779
|
+
if (!ref_is_available(old_ref, new_ref, this_ref->name)) {
|
780
|
+
giterr_set(GITERR_REFERENCE,
|
781
|
+
"The path to reference '%s' collides with an existing one", new_ref);
|
782
|
+
return -1;
|
783
|
+
}
|
784
|
+
});
|
785
|
+
|
786
|
+
return 0;
|
621
787
|
}
|
622
788
|
|
623
789
|
static int loose_write(refdb_fs_backend *backend, const git_reference *ref)
|
@@ -628,8 +794,7 @@ static int loose_write(refdb_fs_backend *backend, const git_reference *ref)
|
|
628
794
|
/* Remove a possibly existing empty directory hierarchy
|
629
795
|
* which name would collide with the reference name
|
630
796
|
*/
|
631
|
-
if (git_futils_rmdir_r(ref->name, backend->path,
|
632
|
-
GIT_RMDIR_SKIP_NONEMPTY) < 0)
|
797
|
+
if (git_futils_rmdir_r(ref->name, backend->path, GIT_RMDIR_SKIP_NONEMPTY) < 0)
|
633
798
|
return -1;
|
634
799
|
|
635
800
|
if (git_buf_joinpath(&ref_path, backend->path, ref->name) < 0)
|
@@ -679,14 +844,7 @@ static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref)
|
|
679
844
|
{
|
680
845
|
git_object *object;
|
681
846
|
|
682
|
-
if (ref->flags &
|
683
|
-
return 0;
|
684
|
-
|
685
|
-
/*
|
686
|
-
* Only applies to tags, i.e. references
|
687
|
-
* in the /refs/tags folder
|
688
|
-
*/
|
689
|
-
if (git__prefixcmp(ref->name, GIT_REFS_TAGS_DIR) != 0)
|
847
|
+
if (ref->flags & PACKREF_HAS_PEEL || ref->flags & PACKREF_CANNOT_PEEL)
|
690
848
|
return 0;
|
691
849
|
|
692
850
|
/*
|
@@ -707,7 +865,7 @@ static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref)
|
|
707
865
|
* Find the object pointed at by this tag
|
708
866
|
*/
|
709
867
|
git_oid_cpy(&ref->peel, git_tag_target_id(tag));
|
710
|
-
ref->flags |=
|
868
|
+
ref->flags |= PACKREF_HAS_PEEL;
|
711
869
|
|
712
870
|
/*
|
713
871
|
* The reference has now cached the resolved OID, and is
|
@@ -740,7 +898,7 @@ static int packed_write_ref(struct packref *ref, git_filebuf *file)
|
|
740
898
|
* This obviously only applies to tags.
|
741
899
|
* The required peels have already been loaded into `ref->peel_target`.
|
742
900
|
*/
|
743
|
-
if (ref->flags &
|
901
|
+
if (ref->flags & PACKREF_HAS_PEEL) {
|
744
902
|
char peel[GIT_OID_HEXSZ + 1];
|
745
903
|
git_oid_fmt(peel, &ref->peel);
|
746
904
|
peel[GIT_OID_HEXSZ] = 0;
|
@@ -777,7 +935,7 @@ static int packed_remove_loose(
|
|
777
935
|
for (i = 0; i < packing_list->length; ++i) {
|
778
936
|
struct packref *ref = git_vector_get(packing_list, i);
|
779
937
|
|
780
|
-
if ((ref->flags &
|
938
|
+
if ((ref->flags & PACKREF_WAS_LOOSE) == 0)
|
781
939
|
continue;
|
782
940
|
|
783
941
|
if (git_buf_joinpath(&full_path, backend->path, ref->name) < 0)
|
@@ -896,66 +1054,113 @@ cleanup_memory:
|
|
896
1054
|
|
897
1055
|
static int refdb_fs_backend__write(
|
898
1056
|
git_refdb_backend *_backend,
|
899
|
-
const git_reference *ref
|
1057
|
+
const git_reference *ref,
|
1058
|
+
int force)
|
900
1059
|
{
|
901
1060
|
refdb_fs_backend *backend;
|
1061
|
+
int error;
|
902
1062
|
|
903
1063
|
assert(_backend);
|
904
1064
|
backend = (refdb_fs_backend *)_backend;
|
905
1065
|
|
1066
|
+
error = reference_path_available(backend, ref->name, NULL, force);
|
1067
|
+
if (error < 0)
|
1068
|
+
return error;
|
1069
|
+
|
906
1070
|
return loose_write(backend, ref);
|
907
1071
|
}
|
908
1072
|
|
909
1073
|
static int refdb_fs_backend__delete(
|
910
1074
|
git_refdb_backend *_backend,
|
911
|
-
const
|
1075
|
+
const char *ref_name)
|
912
1076
|
{
|
913
1077
|
refdb_fs_backend *backend;
|
914
|
-
git_repository *repo;
|
915
1078
|
git_buf loose_path = GIT_BUF_INIT;
|
916
1079
|
struct packref *pack_ref;
|
917
1080
|
khiter_t pack_ref_pos;
|
918
|
-
int error = 0
|
919
|
-
bool loose_deleted;
|
1081
|
+
int error = 0;
|
1082
|
+
bool loose_deleted = 0;
|
920
1083
|
|
921
1084
|
assert(_backend);
|
922
|
-
assert(
|
1085
|
+
assert(ref_name);
|
923
1086
|
|
924
1087
|
backend = (refdb_fs_backend *)_backend;
|
925
|
-
repo = backend->repo;
|
926
1088
|
|
927
1089
|
/* If a loose reference exists, remove it from the filesystem */
|
928
|
-
|
929
|
-
if (git_buf_joinpath(&loose_path, repo->path_repository, ref->name) < 0)
|
1090
|
+
if (git_buf_joinpath(&loose_path, backend->path, ref_name) < 0)
|
930
1091
|
return -1;
|
931
1092
|
|
932
1093
|
if (git_path_isfile(loose_path.ptr)) {
|
933
1094
|
error = p_unlink(loose_path.ptr);
|
934
1095
|
loose_deleted = 1;
|
935
1096
|
}
|
936
|
-
|
1097
|
+
|
937
1098
|
git_buf_free(&loose_path);
|
938
1099
|
|
939
1100
|
if (error != 0)
|
940
1101
|
return error;
|
941
1102
|
|
942
1103
|
/* If a packed reference exists, remove it from the packfile and repack */
|
1104
|
+
error = packed_map_entry(&pack_ref, &pack_ref_pos, backend, ref_name);
|
1105
|
+
|
1106
|
+
if (error == GIT_ENOTFOUND)
|
1107
|
+
return loose_deleted ? 0 : GIT_ENOTFOUND;
|
943
1108
|
|
944
|
-
if (
|
1109
|
+
if (error == 0) {
|
945
1110
|
git_strmap_delete_at(backend->refcache.packfile, pack_ref_pos);
|
946
1111
|
git__free(pack_ref);
|
947
|
-
|
948
1112
|
error = packed_write(backend);
|
949
1113
|
}
|
950
|
-
|
951
|
-
if (pack_error == GIT_ENOTFOUND)
|
952
|
-
error = loose_deleted ? 0 : GIT_ENOTFOUND;
|
953
|
-
else
|
954
|
-
error = pack_error;
|
955
1114
|
|
956
1115
|
return error;
|
957
1116
|
}
|
958
1117
|
|
1118
|
+
static int refdb_fs_backend__rename(
|
1119
|
+
git_reference **out,
|
1120
|
+
git_refdb_backend *_backend,
|
1121
|
+
const char *old_name,
|
1122
|
+
const char *new_name,
|
1123
|
+
int force)
|
1124
|
+
{
|
1125
|
+
refdb_fs_backend *backend;
|
1126
|
+
git_reference *old, *new;
|
1127
|
+
int error;
|
1128
|
+
|
1129
|
+
assert(_backend);
|
1130
|
+
backend = (refdb_fs_backend *)_backend;
|
1131
|
+
|
1132
|
+
error = reference_path_available(backend, new_name, old_name, force);
|
1133
|
+
if (error < 0)
|
1134
|
+
return error;
|
1135
|
+
|
1136
|
+
error = refdb_fs_backend__lookup(&old, _backend, old_name);
|
1137
|
+
if (error < 0)
|
1138
|
+
return error;
|
1139
|
+
|
1140
|
+
error = refdb_fs_backend__delete(_backend, old_name);
|
1141
|
+
if (error < 0) {
|
1142
|
+
git_reference_free(old);
|
1143
|
+
return error;
|
1144
|
+
}
|
1145
|
+
|
1146
|
+
new = realloc(old, sizeof(git_reference) + strlen(new_name) + 1);
|
1147
|
+
memcpy(new->name, new_name, strlen(new_name) + 1);
|
1148
|
+
|
1149
|
+
error = loose_write(backend, new);
|
1150
|
+
if (error < 0) {
|
1151
|
+
git_reference_free(new);
|
1152
|
+
return error;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
if (out) {
|
1156
|
+
*out = new;
|
1157
|
+
} else {
|
1158
|
+
git_reference_free(new);
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
return 0;
|
1162
|
+
}
|
1163
|
+
|
959
1164
|
static int refdb_fs_backend__compress(git_refdb_backend *_backend)
|
960
1165
|
{
|
961
1166
|
refdb_fs_backend *backend;
|
@@ -994,28 +1199,76 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
|
|
994
1199
|
backend = (refdb_fs_backend *)_backend;
|
995
1200
|
|
996
1201
|
refcache_free(&backend->refcache);
|
1202
|
+
git__free(backend->path);
|
997
1203
|
git__free(backend);
|
998
1204
|
}
|
999
1205
|
|
1206
|
+
static int setup_namespace(git_buf *path, git_repository *repo)
|
1207
|
+
{
|
1208
|
+
char *parts, *start, *end;
|
1209
|
+
|
1210
|
+
/* Not all repositories have a path */
|
1211
|
+
if (repo->path_repository == NULL)
|
1212
|
+
return 0;
|
1213
|
+
|
1214
|
+
/* Load the path to the repo first */
|
1215
|
+
git_buf_puts(path, repo->path_repository);
|
1216
|
+
|
1217
|
+
/* if the repo is not namespaced, nothing else to do */
|
1218
|
+
if (repo->namespace == NULL)
|
1219
|
+
return 0;
|
1220
|
+
|
1221
|
+
parts = end = git__strdup(repo->namespace);
|
1222
|
+
if (parts == NULL)
|
1223
|
+
return -1;
|
1224
|
+
|
1225
|
+
/**
|
1226
|
+
* From `man gitnamespaces`:
|
1227
|
+
* namespaces which include a / will expand to a hierarchy
|
1228
|
+
* of namespaces; for example, GIT_NAMESPACE=foo/bar will store
|
1229
|
+
* refs under refs/namespaces/foo/refs/namespaces/bar/
|
1230
|
+
*/
|
1231
|
+
while ((start = git__strsep(&end, "/")) != NULL) {
|
1232
|
+
git_buf_printf(path, "refs/namespaces/%s/", start);
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
git_buf_printf(path, "refs/namespaces/%s/refs", end);
|
1236
|
+
git__free(parts);
|
1237
|
+
|
1238
|
+
/* Make sure that the folder with the namespace exists */
|
1239
|
+
if (git_futils_mkdir_r(git_buf_cstr(path), repo->path_repository, 0777) < 0)
|
1240
|
+
return -1;
|
1241
|
+
|
1242
|
+
/* Return the root of the namespaced path, i.e. without the trailing '/refs' */
|
1243
|
+
git_buf_rtruncate_at_char(path, '/');
|
1244
|
+
return 0;
|
1245
|
+
}
|
1246
|
+
|
1000
1247
|
int git_refdb_backend_fs(
|
1001
1248
|
git_refdb_backend **backend_out,
|
1002
|
-
git_repository *repository
|
1003
|
-
git_refdb *refdb)
|
1249
|
+
git_repository *repository)
|
1004
1250
|
{
|
1251
|
+
git_buf path = GIT_BUF_INIT;
|
1005
1252
|
refdb_fs_backend *backend;
|
1006
1253
|
|
1007
1254
|
backend = git__calloc(1, sizeof(refdb_fs_backend));
|
1008
1255
|
GITERR_CHECK_ALLOC(backend);
|
1009
1256
|
|
1010
1257
|
backend->repo = repository;
|
1011
|
-
|
1012
|
-
|
1258
|
+
|
1259
|
+
if (setup_namespace(&path, repository) < 0) {
|
1260
|
+
git__free(backend);
|
1261
|
+
return -1;
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
backend->path = git_buf_detach(&path);
|
1013
1265
|
|
1014
1266
|
backend->parent.exists = &refdb_fs_backend__exists;
|
1015
1267
|
backend->parent.lookup = &refdb_fs_backend__lookup;
|
1016
|
-
backend->parent.
|
1268
|
+
backend->parent.iterator = &refdb_fs_backend__iterator;
|
1017
1269
|
backend->parent.write = &refdb_fs_backend__write;
|
1018
1270
|
backend->parent.delete = &refdb_fs_backend__delete;
|
1271
|
+
backend->parent.rename = &refdb_fs_backend__rename;
|
1019
1272
|
backend->parent.compress = &refdb_fs_backend__compress;
|
1020
1273
|
backend->parent.free = &refdb_fs_backend__free;
|
1021
1274
|
|