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/cache.h
CHANGED
@@ -12,43 +12,56 @@
|
|
12
12
|
#include "git2/odb.h"
|
13
13
|
|
14
14
|
#include "thread-utils.h"
|
15
|
+
#include "oidmap.h"
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
enum {
|
18
|
+
GIT_CACHE_STORE_ANY = 0,
|
19
|
+
GIT_CACHE_STORE_RAW = 1,
|
20
|
+
GIT_CACHE_STORE_PARSED = 2
|
21
|
+
};
|
19
22
|
|
20
23
|
typedef struct {
|
21
|
-
git_oid
|
24
|
+
git_oid oid;
|
25
|
+
int16_t type; /* git_otype value */
|
26
|
+
uint16_t flags; /* GIT_CACHE_STORE value */
|
27
|
+
size_t size;
|
22
28
|
git_atomic refcount;
|
23
29
|
} git_cached_obj;
|
24
30
|
|
25
31
|
typedef struct {
|
26
|
-
|
27
|
-
git_mutex
|
28
|
-
|
29
|
-
unsigned int lru_count;
|
30
|
-
size_t size_mask;
|
31
|
-
git_cached_obj_freeptr free_obj;
|
32
|
+
git_oidmap *map;
|
33
|
+
git_mutex lock;
|
34
|
+
ssize_t used_memory;
|
32
35
|
} git_cache;
|
33
36
|
|
34
|
-
|
37
|
+
extern bool git_cache__enabled;
|
38
|
+
extern ssize_t git_cache__max_storage;
|
39
|
+
extern git_atomic_ssize git_cache__current_storage;
|
40
|
+
|
41
|
+
int git_cache_set_max_object_size(git_otype type, size_t size);
|
42
|
+
|
43
|
+
int git_cache_init(git_cache *cache);
|
35
44
|
void git_cache_free(git_cache *cache);
|
45
|
+
void git_cache_clear(git_cache *cache);
|
36
46
|
|
37
|
-
void *
|
38
|
-
void *
|
47
|
+
void *git_cache_store_raw(git_cache *cache, git_odb_object *entry);
|
48
|
+
void *git_cache_store_parsed(git_cache *cache, git_object *entry);
|
39
49
|
|
40
|
-
|
50
|
+
git_odb_object *git_cache_get_raw(git_cache *cache, const git_oid *oid);
|
51
|
+
git_object *git_cache_get_parsed(git_cache *cache, const git_oid *oid);
|
52
|
+
void *git_cache_get_any(git_cache *cache, const git_oid *oid);
|
53
|
+
|
54
|
+
GIT_INLINE(size_t) git_cache_size(git_cache *cache)
|
41
55
|
{
|
42
|
-
|
43
|
-
git_atomic_inc(&obj->refcount);
|
56
|
+
return (size_t)kh_size(cache->map);
|
44
57
|
}
|
45
58
|
|
46
|
-
GIT_INLINE(void)
|
59
|
+
GIT_INLINE(void) git_cached_obj_incref(void *_obj)
|
47
60
|
{
|
48
61
|
git_cached_obj *obj = _obj;
|
49
|
-
|
50
|
-
if (git_atomic_dec(&obj->refcount) == 0)
|
51
|
-
free_obj(obj);
|
62
|
+
git_atomic_inc(&obj->refcount);
|
52
63
|
}
|
53
64
|
|
65
|
+
void git_cached_obj_decref(void *_obj);
|
66
|
+
|
54
67
|
#endif
|
@@ -16,9 +16,11 @@
|
|
16
16
|
#include "git2/config.h"
|
17
17
|
#include "git2/diff.h"
|
18
18
|
#include "git2/submodule.h"
|
19
|
+
#include "git2/sys/index.h"
|
19
20
|
|
20
21
|
#include "refs.h"
|
21
22
|
#include "repository.h"
|
23
|
+
#include "index.h"
|
22
24
|
#include "filter.h"
|
23
25
|
#include "blob.h"
|
24
26
|
#include "diff.h"
|
@@ -138,7 +140,7 @@ static bool checkout_is_workdir_modified(
|
|
138
140
|
if (!sm_oid)
|
139
141
|
return false;
|
140
142
|
|
141
|
-
return (
|
143
|
+
return (git_oid__cmp(&baseitem->oid, sm_oid) != 0);
|
142
144
|
}
|
143
145
|
|
144
146
|
/* Look at the cache to decide if the workdir is modified. If not,
|
@@ -149,7 +151,7 @@ static bool checkout_is_workdir_modified(
|
|
149
151
|
if (wditem->mtime.seconds == ie->mtime.seconds &&
|
150
152
|
wditem->mtime.nanoseconds == ie->mtime.nanoseconds &&
|
151
153
|
wditem->file_size == ie->file_size)
|
152
|
-
return (
|
154
|
+
return (git_oid__cmp(&baseitem->oid, &ie->oid) != 0);
|
153
155
|
}
|
154
156
|
|
155
157
|
/* depending on where base is coming from, we may or may not know
|
@@ -163,7 +165,7 @@ static bool checkout_is_workdir_modified(
|
|
163
165
|
wditem->file_size, &oid) < 0)
|
164
166
|
return false;
|
165
167
|
|
166
|
-
return (
|
168
|
+
return (git_oid__cmp(&baseitem->oid, &oid) != 0);
|
167
169
|
}
|
168
170
|
|
169
171
|
#define CHECKOUT_ACTION_IF(FLAG,YES,NO) \
|
@@ -188,6 +190,10 @@ static int checkout_action_common(
|
|
188
190
|
action = (action & ~CHECKOUT_ACTION__UPDATE_BLOB) |
|
189
191
|
CHECKOUT_ACTION__UPDATE_SUBMODULE;
|
190
192
|
|
193
|
+
/* to "update" a symlink, we must remove the old one first */
|
194
|
+
if (delta->new_file.mode == GIT_FILEMODE_LINK && wd != NULL)
|
195
|
+
action |= CHECKOUT_ACTION__REMOVE;
|
196
|
+
|
191
197
|
notify = GIT_CHECKOUT_NOTIFY_UPDATED;
|
192
198
|
}
|
193
199
|
|
@@ -214,9 +220,11 @@ static int checkout_action_no_wd(
|
|
214
220
|
action = CHECKOUT_ACTION_IF(SAFE_CREATE, UPDATE_BLOB, NONE);
|
215
221
|
break;
|
216
222
|
case GIT_DELTA_ADDED: /* case 2 or 28 (and 5 but not really) */
|
217
|
-
case GIT_DELTA_MODIFIED: /* case 13 (and 35 but not really) */
|
218
223
|
action = CHECKOUT_ACTION_IF(SAFE, UPDATE_BLOB, NONE);
|
219
224
|
break;
|
225
|
+
case GIT_DELTA_MODIFIED: /* case 13 (and 35 but not really) */
|
226
|
+
action = CHECKOUT_ACTION_IF(SAFE_CREATE, UPDATE_BLOB, CONFLICT);
|
227
|
+
break;
|
220
228
|
case GIT_DELTA_TYPECHANGE: /* case 21 (B->T) and 28 (T->B)*/
|
221
229
|
if (delta->new_file.mode == GIT_FILEMODE_TREE)
|
222
230
|
action = CHECKOUT_ACTION_IF(SAFE, UPDATE_BLOB, NONE);
|
@@ -466,6 +474,7 @@ static int checkout_action(
|
|
466
474
|
int cmp = -1, act;
|
467
475
|
int (*strcomp)(const char *, const char *) = data->diff->strcomp;
|
468
476
|
int (*pfxcomp)(const char *str, const char *pfx) = data->diff->pfxcomp;
|
477
|
+
int error;
|
469
478
|
|
470
479
|
/* move workdir iterator to follow along with deltas */
|
471
480
|
|
@@ -489,9 +498,9 @@ static int checkout_action(
|
|
489
498
|
if (cmp == 0) {
|
490
499
|
if (wd->mode == GIT_FILEMODE_TREE) {
|
491
500
|
/* case 2 - entry prefixed by workdir tree */
|
492
|
-
|
501
|
+
error = git_iterator_advance_into_or_over(&wd, workdir);
|
502
|
+
if (error && error != GIT_ITEROVER)
|
493
503
|
goto fail;
|
494
|
-
|
495
504
|
*wditem_ptr = wd;
|
496
505
|
continue;
|
497
506
|
}
|
@@ -506,8 +515,10 @@ static int checkout_action(
|
|
506
515
|
}
|
507
516
|
|
508
517
|
/* case 1 - handle wd item (if it matches pathspec) */
|
509
|
-
if (checkout_action_wd_only(data, workdir, wd, pathspec) < 0
|
510
|
-
|
518
|
+
if (checkout_action_wd_only(data, workdir, wd, pathspec) < 0)
|
519
|
+
goto fail;
|
520
|
+
if ((error = git_iterator_advance(&wd, workdir)) < 0 &&
|
521
|
+
error != GIT_ITEROVER)
|
511
522
|
goto fail;
|
512
523
|
|
513
524
|
*wditem_ptr = wd;
|
@@ -530,8 +541,9 @@ static int checkout_action(
|
|
530
541
|
if (delta->status == GIT_DELTA_TYPECHANGE) {
|
531
542
|
if (delta->old_file.mode == GIT_FILEMODE_TREE) {
|
532
543
|
act = checkout_action_with_wd(data, delta, wd);
|
533
|
-
if (git_iterator_advance_into(&wd, workdir) < 0
|
534
|
-
|
544
|
+
if ((error = git_iterator_advance_into(&wd, workdir)) < 0 &&
|
545
|
+
error != GIT_ENOTFOUND)
|
546
|
+
goto fail;
|
535
547
|
*wditem_ptr = wd;
|
536
548
|
return act;
|
537
549
|
}
|
@@ -541,8 +553,9 @@ static int checkout_action(
|
|
541
553
|
delta->old_file.mode == GIT_FILEMODE_COMMIT)
|
542
554
|
{
|
543
555
|
act = checkout_action_with_wd(data, delta, wd);
|
544
|
-
if (git_iterator_advance(&wd, workdir) < 0
|
545
|
-
|
556
|
+
if ((error = git_iterator_advance(&wd, workdir)) < 0 &&
|
557
|
+
error != GIT_ITEROVER)
|
558
|
+
goto fail;
|
546
559
|
*wditem_ptr = wd;
|
547
560
|
return act;
|
548
561
|
}
|
@@ -573,6 +586,9 @@ static int checkout_remaining_wd_items(
|
|
573
586
|
error = git_iterator_advance(&wd, workdir);
|
574
587
|
}
|
575
588
|
|
589
|
+
if (error == GIT_ITEROVER)
|
590
|
+
error = 0;
|
591
|
+
|
576
592
|
return error;
|
577
593
|
}
|
578
594
|
|
@@ -594,7 +610,8 @@ static int checkout_get_actions(
|
|
594
610
|
git_pathspec_init(&pathspec, &data->opts.paths, &pathpool) < 0)
|
595
611
|
return -1;
|
596
612
|
|
597
|
-
if ((error = git_iterator_current(&wditem, workdir)) < 0
|
613
|
+
if ((error = git_iterator_current(&wditem, workdir)) < 0 &&
|
614
|
+
error != GIT_ITEROVER)
|
598
615
|
goto fail;
|
599
616
|
|
600
617
|
deltas = &data->diff->deltas;
|
@@ -667,33 +684,26 @@ static int buffer_to_file(
|
|
667
684
|
int file_open_flags,
|
668
685
|
mode_t file_mode)
|
669
686
|
{
|
670
|
-
int
|
687
|
+
int error;
|
671
688
|
|
672
689
|
if ((error = git_futils_mkpath2file(path, dir_mode)) < 0)
|
673
690
|
return error;
|
674
691
|
|
675
|
-
if ((
|
676
|
-
|
677
|
-
return
|
678
|
-
}
|
679
|
-
|
680
|
-
if ((error = p_write(fd, git_buf_cstr(buffer), git_buf_len(buffer))) < 0) {
|
681
|
-
giterr_set(GITERR_OS, "Could not write to '%s'", path);
|
682
|
-
(void)p_close(fd);
|
683
|
-
} else {
|
684
|
-
if ((error = p_close(fd)) < 0)
|
685
|
-
giterr_set(GITERR_OS, "Error while closing '%s'", path);
|
692
|
+
if ((error = git_futils_writebuffer(
|
693
|
+
buffer, path, file_open_flags, file_mode)) < 0)
|
694
|
+
return error;
|
686
695
|
|
687
|
-
|
688
|
-
|
696
|
+
if (st != NULL && (error = p_stat(path, st)) < 0) {
|
697
|
+
giterr_set(GITERR_OS, "Error while statting '%s'", path);
|
698
|
+
return error;
|
689
699
|
}
|
690
700
|
|
691
|
-
if (
|
692
|
-
(file_mode & 0100) != 0 &&
|
693
|
-
(error = p_chmod(path, file_mode)) < 0)
|
701
|
+
if ((file_mode & 0100) != 0 && (error = p_chmod(path, file_mode)) < 0) {
|
694
702
|
giterr_set(GITERR_OS, "Failed to set permissions on '%s'", path);
|
703
|
+
return error;
|
704
|
+
}
|
695
705
|
|
696
|
-
return
|
706
|
+
return 0;
|
697
707
|
}
|
698
708
|
|
699
709
|
static int blob_content_to_file(
|
@@ -710,8 +720,8 @@ static int blob_content_to_file(
|
|
710
720
|
git_vector filters = GIT_VECTOR_INIT;
|
711
721
|
|
712
722
|
/* Create a fake git_buf from the blob raw data... */
|
713
|
-
filtered.ptr
|
714
|
-
filtered.size = blob
|
723
|
+
filtered.ptr = (void *)git_blob_rawcontent(blob);
|
724
|
+
filtered.size = (size_t)git_blob_rawsize(blob);
|
715
725
|
/* ... and make sure it doesn't get unexpectedly freed */
|
716
726
|
dont_free_filtered = true;
|
717
727
|
|
@@ -759,17 +769,24 @@ cleanup:
|
|
759
769
|
}
|
760
770
|
|
761
771
|
static int blob_content_to_link(
|
762
|
-
struct stat *st,
|
772
|
+
struct stat *st,
|
773
|
+
git_blob *blob,
|
774
|
+
const char *path,
|
775
|
+
mode_t dir_mode,
|
776
|
+
int can_symlink)
|
763
777
|
{
|
764
778
|
git_buf linktarget = GIT_BUF_INIT;
|
765
779
|
int error;
|
766
780
|
|
781
|
+
if ((error = git_futils_mkpath2file(path, dir_mode)) < 0)
|
782
|
+
return error;
|
783
|
+
|
767
784
|
if ((error = git_blob__getbuf(&linktarget, blob)) < 0)
|
768
785
|
return error;
|
769
786
|
|
770
787
|
if (can_symlink) {
|
771
788
|
if ((error = p_symlink(git_buf_cstr(&linktarget), path)) < 0)
|
772
|
-
giterr_set(
|
789
|
+
giterr_set(GITERR_OS, "Could not create symlink %s\n", path);
|
773
790
|
} else {
|
774
791
|
error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path);
|
775
792
|
}
|
@@ -804,6 +821,31 @@ static int checkout_update_index(
|
|
804
821
|
return git_index_add(data->index, &entry);
|
805
822
|
}
|
806
823
|
|
824
|
+
static int checkout_submodule_update_index(
|
825
|
+
checkout_data *data,
|
826
|
+
const git_diff_file *file)
|
827
|
+
{
|
828
|
+
struct stat st;
|
829
|
+
|
830
|
+
/* update the index unless prevented */
|
831
|
+
if ((data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) != 0)
|
832
|
+
return 0;
|
833
|
+
|
834
|
+
git_buf_truncate(&data->path, data->workdir_len);
|
835
|
+
if (git_buf_puts(&data->path, file->path) < 0)
|
836
|
+
return -1;
|
837
|
+
|
838
|
+
if (p_stat(git_buf_cstr(&data->path), &st) < 0) {
|
839
|
+
giterr_set(
|
840
|
+
GITERR_CHECKOUT, "Could not stat submodule %s\n", file->path);
|
841
|
+
return GIT_ENOTFOUND;
|
842
|
+
}
|
843
|
+
|
844
|
+
st.st_mode = GIT_FILEMODE_COMMIT;
|
845
|
+
|
846
|
+
return checkout_update_index(data, file, &st);
|
847
|
+
}
|
848
|
+
|
807
849
|
static int checkout_submodule(
|
808
850
|
checkout_data *data,
|
809
851
|
const git_diff_file *file)
|
@@ -816,12 +858,21 @@ static int checkout_submodule(
|
|
816
858
|
return 0;
|
817
859
|
|
818
860
|
if ((error = git_futils_mkdir(
|
819
|
-
file->path,
|
861
|
+
file->path, data->opts.target_directory,
|
820
862
|
data->opts.dir_mode, GIT_MKDIR_PATH)) < 0)
|
821
863
|
return error;
|
822
864
|
|
823
|
-
if ((error = git_submodule_lookup(&sm, data->repo, file->path)) < 0)
|
865
|
+
if ((error = git_submodule_lookup(&sm, data->repo, file->path)) < 0) {
|
866
|
+
/* I've observed repos with submodules in the tree that do not
|
867
|
+
* have a .gitmodules - core Git just makes an empty directory
|
868
|
+
*/
|
869
|
+
if (error == GIT_ENOTFOUND) {
|
870
|
+
giterr_clear();
|
871
|
+
return checkout_submodule_update_index(data, file);
|
872
|
+
}
|
873
|
+
|
824
874
|
return error;
|
875
|
+
}
|
825
876
|
|
826
877
|
/* TODO: Support checkout_strategy options. Two circumstances:
|
827
878
|
* 1 - submodule already checked out, but we need to move the HEAD
|
@@ -832,26 +883,7 @@ static int checkout_submodule(
|
|
832
883
|
* command should probably be able to. Do we need a submodule callback?
|
833
884
|
*/
|
834
885
|
|
835
|
-
|
836
|
-
if ((data->strategy & GIT_CHECKOUT_DONT_UPDATE_INDEX) == 0) {
|
837
|
-
struct stat st;
|
838
|
-
|
839
|
-
git_buf_truncate(&data->path, data->workdir_len);
|
840
|
-
if (git_buf_puts(&data->path, file->path) < 0)
|
841
|
-
return -1;
|
842
|
-
|
843
|
-
if ((error = p_stat(git_buf_cstr(&data->path), &st)) < 0) {
|
844
|
-
giterr_set(
|
845
|
-
GITERR_CHECKOUT, "Could not stat submodule %s\n", file->path);
|
846
|
-
return error;
|
847
|
-
}
|
848
|
-
|
849
|
-
st.st_mode = GIT_FILEMODE_COMMIT;
|
850
|
-
|
851
|
-
error = checkout_update_index(data, file, &st);
|
852
|
-
}
|
853
|
-
|
854
|
-
return error;
|
886
|
+
return checkout_submodule_update_index(data, file);
|
855
887
|
}
|
856
888
|
|
857
889
|
static void report_progress(
|
@@ -909,7 +941,7 @@ static int checkout_blob(
|
|
909
941
|
|
910
942
|
if (S_ISLNK(file->mode))
|
911
943
|
error = blob_content_to_link(
|
912
|
-
&st, blob, git_buf_cstr(&data->path), data->can_symlink);
|
944
|
+
&st, blob, git_buf_cstr(&data->path), data->opts.dir_mode, data->can_symlink);
|
913
945
|
else
|
914
946
|
error = blob_content_to_file(
|
915
947
|
&st, blob, git_buf_cstr(&data->path), file->mode, &data->opts);
|
@@ -950,6 +982,9 @@ static int checkout_remove_the_old(
|
|
950
982
|
uint32_t flg = GIT_RMDIR_EMPTY_PARENTS |
|
951
983
|
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS;
|
952
984
|
|
985
|
+
if (data->opts.checkout_strategy & GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES)
|
986
|
+
flg |= GIT_RMDIR_SKIP_NONEMPTY;
|
987
|
+
|
953
988
|
git_buf_truncate(&data->path, data->workdir_len);
|
954
989
|
|
955
990
|
git_vector_foreach(&data->diff->deltas, i, delta) {
|
@@ -995,7 +1030,7 @@ static int checkout_deferred_remove(git_repository *repo, const char *path)
|
|
995
1030
|
{
|
996
1031
|
#if 0
|
997
1032
|
int error = git_futils_rmdir_r(
|
998
|
-
path,
|
1033
|
+
path, data->opts.target_directory, GIT_RMDIR_EMPTY_PARENTS);
|
999
1034
|
|
1000
1035
|
if (error == GIT_ENOTFOUND) {
|
1001
1036
|
error = 0;
|
@@ -1119,7 +1154,6 @@ static int checkout_data_init(
|
|
1119
1154
|
git_checkout_opts *proposed)
|
1120
1155
|
{
|
1121
1156
|
int error = 0;
|
1122
|
-
git_config *cfg;
|
1123
1157
|
git_repository *repo = git_iterator_owner(target);
|
1124
1158
|
|
1125
1159
|
memset(data, 0, sizeof(*data));
|
@@ -1129,10 +1163,8 @@ static int checkout_data_init(
|
|
1129
1163
|
return -1;
|
1130
1164
|
}
|
1131
1165
|
|
1132
|
-
if ((
|
1133
|
-
|
1134
|
-
|
1135
|
-
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
|
1166
|
+
if ((!proposed || !proposed->target_directory) &&
|
1167
|
+
(error = git_repository__ensure_not_bare(repo, "checkout")) < 0)
|
1136
1168
|
return error;
|
1137
1169
|
|
1138
1170
|
data->repo = repo;
|
@@ -1145,9 +1177,19 @@ static int checkout_data_init(
|
|
1145
1177
|
else
|
1146
1178
|
memmove(&data->opts, proposed, sizeof(git_checkout_opts));
|
1147
1179
|
|
1180
|
+
if (!data->opts.target_directory)
|
1181
|
+
data->opts.target_directory = git_repository_workdir(repo);
|
1182
|
+
else if (!git_path_isdir(data->opts.target_directory) &&
|
1183
|
+
(error = git_futils_mkdir(data->opts.target_directory, NULL,
|
1184
|
+
GIT_DIR_MODE, GIT_MKDIR_VERIFY_DIR)) < 0)
|
1185
|
+
goto cleanup;
|
1186
|
+
|
1148
1187
|
/* refresh config and index content unless NO_REFRESH is given */
|
1149
1188
|
if ((data->opts.checkout_strategy & GIT_CHECKOUT_NO_REFRESH) == 0) {
|
1150
|
-
|
1189
|
+
git_config *cfg;
|
1190
|
+
|
1191
|
+
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 ||
|
1192
|
+
(error = git_config_refresh(cfg)) < 0)
|
1151
1193
|
goto cleanup;
|
1152
1194
|
|
1153
1195
|
/* if we are checking out the index, don't reload,
|
@@ -1184,19 +1226,13 @@ static int checkout_data_init(
|
|
1184
1226
|
|
1185
1227
|
data->pfx = git_pathspec_prefix(&data->opts.paths);
|
1186
1228
|
|
1187
|
-
error =
|
1188
|
-
|
1189
|
-
|
1190
|
-
goto cleanup;
|
1191
|
-
|
1192
|
-
/* If "core.symlinks" is not found anywhere, default to true. */
|
1193
|
-
data->can_symlink = true;
|
1194
|
-
giterr_clear();
|
1195
|
-
error = 0;
|
1196
|
-
}
|
1229
|
+
if ((error = git_repository__cvar(
|
1230
|
+
&data->can_symlink, repo, GIT_CVAR_SYMLINKS)) < 0)
|
1231
|
+
goto cleanup;
|
1197
1232
|
|
1198
1233
|
if (!data->opts.baseline) {
|
1199
1234
|
data->opts_free_baseline = true;
|
1235
|
+
|
1200
1236
|
error = checkout_lookup_head_tree(&data->opts.baseline, repo);
|
1201
1237
|
|
1202
1238
|
if (error == GIT_EORPHANEDHEAD) {
|
@@ -1210,7 +1246,8 @@ static int checkout_data_init(
|
|
1210
1246
|
|
1211
1247
|
if ((error = git_vector_init(&data->removes, 0, git__strcmp_cb)) < 0 ||
|
1212
1248
|
(error = git_pool_init(&data->pool, 1, 0)) < 0 ||
|
1213
|
-
(error = git_buf_puts(&data->path,
|
1249
|
+
(error = git_buf_puts(&data->path, data->opts.target_directory)) < 0 ||
|
1250
|
+
(error = git_path_to_dir(&data->path)) < 0)
|
1214
1251
|
goto cleanup;
|
1215
1252
|
|
1216
1253
|
data->workdir_len = git_buf_len(&data->path);
|
@@ -1258,11 +1295,13 @@ int git_checkout_iterator(
|
|
1258
1295
|
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
|
1259
1296
|
|
1260
1297
|
if ((error = git_iterator_reset(target, data.pfx, data.pfx)) < 0 ||
|
1261
|
-
(error =
|
1262
|
-
&workdir, data.repo,
|
1298
|
+
(error = git_iterator_for_workdir_ext(
|
1299
|
+
&workdir, data.repo, data.opts.target_directory,
|
1300
|
+
iterflags | GIT_ITERATOR_DONT_AUTOEXPAND,
|
1263
1301
|
data.pfx, data.pfx)) < 0 ||
|
1264
1302
|
(error = git_iterator_for_tree(
|
1265
|
-
&baseline, data.opts.baseline,
|
1303
|
+
&baseline, data.opts.baseline,
|
1304
|
+
iterflags, data.pfx, data.pfx)) < 0)
|
1266
1305
|
goto cleanup;
|
1267
1306
|
|
1268
1307
|
/* Should not have case insensitivity mismatch */
|
@@ -1330,8 +1369,19 @@ int git_checkout_index(
|
|
1330
1369
|
int error;
|
1331
1370
|
git_iterator *index_i;
|
1332
1371
|
|
1333
|
-
if (
|
1334
|
-
|
1372
|
+
if (!index && !repo) {
|
1373
|
+
giterr_set(GITERR_CHECKOUT,
|
1374
|
+
"Must provide either repository or index to checkout");
|
1375
|
+
return -1;
|
1376
|
+
}
|
1377
|
+
if (index && repo && git_index_owner(index) != repo) {
|
1378
|
+
giterr_set(GITERR_CHECKOUT,
|
1379
|
+
"Index to checkout does not match repository");
|
1380
|
+
return -1;
|
1381
|
+
}
|
1382
|
+
|
1383
|
+
if (!repo)
|
1384
|
+
repo = git_index_owner(index);
|
1335
1385
|
|
1336
1386
|
if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
|
1337
1387
|
return error;
|
@@ -1355,8 +1405,19 @@ int git_checkout_tree(
|
|
1355
1405
|
git_tree *tree = NULL;
|
1356
1406
|
git_iterator *tree_i = NULL;
|
1357
1407
|
|
1358
|
-
if (
|
1359
|
-
|
1408
|
+
if (!treeish && !repo) {
|
1409
|
+
giterr_set(GITERR_CHECKOUT,
|
1410
|
+
"Must provide either repository or tree to checkout");
|
1411
|
+
return -1;
|
1412
|
+
}
|
1413
|
+
if (treeish && repo && git_object_owner(treeish) != repo) {
|
1414
|
+
giterr_set(GITERR_CHECKOUT,
|
1415
|
+
"Object to checkout does not match repository");
|
1416
|
+
return -1;
|
1417
|
+
}
|
1418
|
+
|
1419
|
+
if (!repo)
|
1420
|
+
repo = git_object_owner(treeish);
|
1360
1421
|
|
1361
1422
|
if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
|
1362
1423
|
giterr_set(
|
@@ -1381,8 +1442,7 @@ int git_checkout_head(
|
|
1381
1442
|
git_tree *head = NULL;
|
1382
1443
|
git_iterator *head_i = NULL;
|
1383
1444
|
|
1384
|
-
|
1385
|
-
return error;
|
1445
|
+
assert(repo);
|
1386
1446
|
|
1387
1447
|
if (!(error = checkout_lookup_head_tree(&head, repo)) &&
|
1388
1448
|
!(error = git_iterator_for_tree(&head_i, head, 0, NULL, NULL)))
|