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/status.c
CHANGED
@@ -11,19 +11,20 @@
|
|
11
11
|
#include "hash.h"
|
12
12
|
#include "vector.h"
|
13
13
|
#include "tree.h"
|
14
|
+
#include "status.h"
|
14
15
|
#include "git2/status.h"
|
15
16
|
#include "repository.h"
|
16
17
|
#include "ignore.h"
|
18
|
+
#include "index.h"
|
17
19
|
|
18
20
|
#include "git2/diff.h"
|
19
21
|
#include "diff.h"
|
20
|
-
#include "diff_output.h"
|
21
22
|
|
22
|
-
static unsigned int index_delta2status(
|
23
|
+
static unsigned int index_delta2status(const git_diff_delta *head2idx)
|
23
24
|
{
|
24
|
-
|
25
|
+
git_status_t st = GIT_STATUS_CURRENT;
|
25
26
|
|
26
|
-
switch (
|
27
|
+
switch (head2idx->status) {
|
27
28
|
case GIT_DELTA_ADDED:
|
28
29
|
case GIT_DELTA_COPIED:
|
29
30
|
st = GIT_STATUS_INDEX_NEW;
|
@@ -36,6 +37,9 @@ static unsigned int index_delta2status(git_delta_t index_status)
|
|
36
37
|
break;
|
37
38
|
case GIT_DELTA_RENAMED:
|
38
39
|
st = GIT_STATUS_INDEX_RENAMED;
|
40
|
+
|
41
|
+
if (!git_oid_equal(&head2idx->old_file.oid, &head2idx->new_file.oid))
|
42
|
+
st |= GIT_STATUS_INDEX_MODIFIED;
|
39
43
|
break;
|
40
44
|
case GIT_DELTA_TYPECHANGE:
|
41
45
|
st = GIT_STATUS_INDEX_TYPECHANGE;
|
@@ -47,13 +51,13 @@ static unsigned int index_delta2status(git_delta_t index_status)
|
|
47
51
|
return st;
|
48
52
|
}
|
49
53
|
|
50
|
-
static unsigned int workdir_delta2status(
|
54
|
+
static unsigned int workdir_delta2status(
|
55
|
+
git_diff_list *diff, git_diff_delta *idx2wd)
|
51
56
|
{
|
52
|
-
|
57
|
+
git_status_t st = GIT_STATUS_CURRENT;
|
53
58
|
|
54
|
-
switch (
|
59
|
+
switch (idx2wd->status) {
|
55
60
|
case GIT_DELTA_ADDED:
|
56
|
-
case GIT_DELTA_RENAMED:
|
57
61
|
case GIT_DELTA_COPIED:
|
58
62
|
case GIT_DELTA_UNTRACKED:
|
59
63
|
st = GIT_STATUS_WT_NEW;
|
@@ -67,6 +71,31 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
|
|
67
71
|
case GIT_DELTA_IGNORED:
|
68
72
|
st = GIT_STATUS_IGNORED;
|
69
73
|
break;
|
74
|
+
case GIT_DELTA_RENAMED:
|
75
|
+
st = GIT_STATUS_WT_RENAMED;
|
76
|
+
|
77
|
+
if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid)) {
|
78
|
+
/* if OIDs don't match, we might need to calculate them now to
|
79
|
+
* discern between RENAMED vs RENAMED+MODIFED
|
80
|
+
*/
|
81
|
+
if (git_oid_iszero(&idx2wd->old_file.oid) &&
|
82
|
+
diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
|
83
|
+
!git_diff__oid_for_file(
|
84
|
+
diff->repo, idx2wd->old_file.path, idx2wd->old_file.mode,
|
85
|
+
idx2wd->old_file.size, &idx2wd->old_file.oid))
|
86
|
+
idx2wd->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
87
|
+
|
88
|
+
if (git_oid_iszero(&idx2wd->new_file.oid) &&
|
89
|
+
diff->new_src == GIT_ITERATOR_TYPE_WORKDIR &&
|
90
|
+
!git_diff__oid_for_file(
|
91
|
+
diff->repo, idx2wd->new_file.path, idx2wd->new_file.mode,
|
92
|
+
idx2wd->new_file.size, &idx2wd->new_file.oid))
|
93
|
+
idx2wd->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
94
|
+
|
95
|
+
if (!git_oid_equal(&idx2wd->old_file.oid, &idx2wd->new_file.oid))
|
96
|
+
st |= GIT_STATUS_WT_MODIFIED;
|
97
|
+
}
|
98
|
+
break;
|
70
99
|
case GIT_DELTA_TYPECHANGE:
|
71
100
|
st = GIT_STATUS_WT_TYPECHANGE;
|
72
101
|
break;
|
@@ -77,142 +106,329 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
|
|
77
106
|
return st;
|
78
107
|
}
|
79
108
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
} status_user_callback;
|
85
|
-
|
86
|
-
static int status_invoke_cb(
|
87
|
-
git_diff_delta *h2i, git_diff_delta *i2w, void *payload)
|
109
|
+
static bool status_is_included(
|
110
|
+
git_status_list *status,
|
111
|
+
git_diff_delta *head2idx,
|
112
|
+
git_diff_delta *idx2wd)
|
88
113
|
{
|
89
|
-
|
90
|
-
|
91
|
-
unsigned int status = 0;
|
114
|
+
if (!(status->opts.flags & GIT_STATUS_OPT_EXCLUDE_SUBMODULES))
|
115
|
+
return 1;
|
92
116
|
|
93
|
-
if
|
94
|
-
|
95
|
-
|
117
|
+
/* if excluding submodules and this is a submodule everywhere */
|
118
|
+
if (head2idx) {
|
119
|
+
if (head2idx->status != GIT_DELTA_ADDED &&
|
120
|
+
head2idx->old_file.mode != GIT_FILEMODE_COMMIT)
|
121
|
+
return 1;
|
122
|
+
if (head2idx->status != GIT_DELTA_DELETED &&
|
123
|
+
head2idx->new_file.mode != GIT_FILEMODE_COMMIT)
|
124
|
+
return 1;
|
96
125
|
}
|
97
|
-
if (
|
98
|
-
|
99
|
-
|
126
|
+
if (idx2wd) {
|
127
|
+
if (idx2wd->status != GIT_DELTA_ADDED &&
|
128
|
+
idx2wd->old_file.mode != GIT_FILEMODE_COMMIT)
|
129
|
+
return 1;
|
130
|
+
if (idx2wd->status != GIT_DELTA_DELETED &&
|
131
|
+
idx2wd->new_file.mode != GIT_FILEMODE_COMMIT)
|
132
|
+
return 1;
|
100
133
|
}
|
101
134
|
|
102
|
-
/*
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
135
|
+
/* only get here if every valid mode is GIT_FILEMODE_COMMIT */
|
136
|
+
return 0;
|
137
|
+
}
|
138
|
+
|
139
|
+
static git_status_t status_compute(
|
140
|
+
git_status_list *status,
|
141
|
+
git_diff_delta *head2idx,
|
142
|
+
git_diff_delta *idx2wd)
|
143
|
+
{
|
144
|
+
git_status_t st = GIT_STATUS_CURRENT;
|
145
|
+
|
146
|
+
if (head2idx)
|
147
|
+
st |= index_delta2status(head2idx);
|
148
|
+
|
149
|
+
if (idx2wd)
|
150
|
+
st |= workdir_delta2status(status->idx2wd, idx2wd);
|
151
|
+
|
152
|
+
return st;
|
153
|
+
}
|
154
|
+
|
155
|
+
static int status_collect(
|
156
|
+
git_diff_delta *head2idx,
|
157
|
+
git_diff_delta *idx2wd,
|
158
|
+
void *payload)
|
159
|
+
{
|
160
|
+
git_status_list *status = payload;
|
161
|
+
git_status_entry *status_entry;
|
162
|
+
|
163
|
+
if (!status_is_included(status, head2idx, idx2wd))
|
164
|
+
return 0;
|
165
|
+
|
166
|
+
status_entry = git__malloc(sizeof(git_status_entry));
|
167
|
+
GITERR_CHECK_ALLOC(status_entry);
|
168
|
+
|
169
|
+
status_entry->status = status_compute(status, head2idx, idx2wd);
|
170
|
+
status_entry->head_to_index = head2idx;
|
171
|
+
status_entry->index_to_workdir = idx2wd;
|
172
|
+
|
173
|
+
return git_vector_insert(&status->paired, status_entry);
|
174
|
+
}
|
175
|
+
|
176
|
+
GIT_INLINE(int) status_entry_cmp_base(
|
177
|
+
const void *a,
|
178
|
+
const void *b,
|
179
|
+
int (*strcomp)(const char *a, const char *b))
|
180
|
+
{
|
181
|
+
const git_status_entry *entry_a = a;
|
182
|
+
const git_status_entry *entry_b = b;
|
183
|
+
const git_diff_delta *delta_a, *delta_b;
|
184
|
+
|
185
|
+
delta_a = entry_a->index_to_workdir ? entry_a->index_to_workdir :
|
186
|
+
entry_a->head_to_index;
|
187
|
+
delta_b = entry_b->index_to_workdir ? entry_b->index_to_workdir :
|
188
|
+
entry_b->head_to_index;
|
189
|
+
|
190
|
+
if (!delta_a && delta_b)
|
191
|
+
return -1;
|
192
|
+
if (delta_a && !delta_b)
|
193
|
+
return 1;
|
194
|
+
if (!delta_a && !delta_b)
|
195
|
+
return 0;
|
196
|
+
|
197
|
+
return strcomp(delta_a->new_file.path, delta_b->new_file.path);
|
198
|
+
}
|
199
|
+
|
200
|
+
static int status_entry_icmp(const void *a, const void *b)
|
201
|
+
{
|
202
|
+
return status_entry_cmp_base(a, b, git__strcasecmp);
|
203
|
+
}
|
204
|
+
|
205
|
+
static int status_entry_cmp(const void *a, const void *b)
|
206
|
+
{
|
207
|
+
return status_entry_cmp_base(a, b, git__strcmp);
|
208
|
+
}
|
209
|
+
|
210
|
+
static git_status_list *git_status_list_alloc(git_index *index)
|
211
|
+
{
|
212
|
+
git_status_list *status = NULL;
|
213
|
+
int (*entrycmp)(const void *a, const void *b);
|
214
|
+
|
215
|
+
if (!(status = git__calloc(1, sizeof(git_status_list))))
|
216
|
+
return NULL;
|
217
|
+
|
218
|
+
entrycmp = index->ignore_case ? status_entry_icmp : status_entry_cmp;
|
219
|
+
|
220
|
+
if (git_vector_init(&status->paired, 0, entrycmp) < 0) {
|
221
|
+
git__free(status);
|
222
|
+
return NULL;
|
114
223
|
}
|
115
224
|
|
116
|
-
return
|
225
|
+
return status;
|
117
226
|
}
|
118
227
|
|
119
|
-
|
228
|
+
/*
|
229
|
+
static int newfile_cmp(const void *a, const void *b)
|
230
|
+
{
|
231
|
+
const git_diff_delta *delta_a = a;
|
232
|
+
const git_diff_delta *delta_b = b;
|
233
|
+
|
234
|
+
return git__strcmp(delta_a->new_file.path, delta_b->new_file.path);
|
235
|
+
}
|
236
|
+
|
237
|
+
static int newfile_casecmp(const void *a, const void *b)
|
238
|
+
{
|
239
|
+
const git_diff_delta *delta_a = a;
|
240
|
+
const git_diff_delta *delta_b = b;
|
241
|
+
|
242
|
+
return git__strcasecmp(delta_a->new_file.path, delta_b->new_file.path);
|
243
|
+
}
|
244
|
+
*/
|
245
|
+
|
246
|
+
int git_status_list_new(
|
247
|
+
git_status_list **out,
|
120
248
|
git_repository *repo,
|
121
|
-
const git_status_options *opts
|
122
|
-
git_status_cb cb,
|
123
|
-
void *payload)
|
249
|
+
const git_status_options *opts)
|
124
250
|
{
|
125
|
-
|
251
|
+
git_index *index = NULL;
|
252
|
+
git_status_list *status = NULL;
|
126
253
|
git_diff_options diffopt = GIT_DIFF_OPTIONS_INIT;
|
127
|
-
|
254
|
+
git_diff_find_options findopts_i2w = GIT_DIFF_FIND_OPTIONS_INIT;
|
128
255
|
git_tree *head = NULL;
|
129
256
|
git_status_show_t show =
|
130
257
|
opts ? opts->show : GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
|
131
|
-
|
258
|
+
int error = 0;
|
259
|
+
unsigned int flags = opts ? opts->flags : GIT_STATUS_OPT_DEFAULTS;
|
132
260
|
|
133
261
|
assert(show <= GIT_STATUS_SHOW_INDEX_THEN_WORKDIR);
|
134
262
|
|
263
|
+
*out = NULL;
|
264
|
+
|
135
265
|
GITERR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options");
|
136
266
|
|
137
|
-
if (
|
138
|
-
(
|
139
|
-
return
|
267
|
+
if ((error = git_repository__ensure_not_bare(repo, "status")) < 0 ||
|
268
|
+
(error = git_repository_index(&index, repo)) < 0)
|
269
|
+
return error;
|
140
270
|
|
141
271
|
/* if there is no HEAD, that's okay - we'll make an empty iterator */
|
142
|
-
if (((
|
143
|
-
|
144
|
-
|
272
|
+
if (((error = git_repository_head_tree(&head, repo)) < 0) &&
|
273
|
+
error != GIT_ENOTFOUND && error != GIT_EORPHANEDHEAD) {
|
274
|
+
git_index_free(index); /* release index */
|
275
|
+
return error;
|
276
|
+
}
|
277
|
+
|
278
|
+
status = git_status_list_alloc(index);
|
279
|
+
GITERR_CHECK_ALLOC(status);
|
145
280
|
|
146
|
-
|
281
|
+
if (opts) {
|
282
|
+
memcpy(&status->opts, opts, sizeof(git_status_options));
|
283
|
+
memcpy(&diffopt.pathspec, &opts->pathspec, sizeof(diffopt.pathspec));
|
284
|
+
}
|
147
285
|
|
148
286
|
diffopt.flags = GIT_DIFF_INCLUDE_TYPECHANGE;
|
149
287
|
|
150
|
-
if ((
|
288
|
+
if ((flags & GIT_STATUS_OPT_INCLUDE_UNTRACKED) != 0)
|
151
289
|
diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNTRACKED;
|
152
|
-
if ((
|
290
|
+
if ((flags & GIT_STATUS_OPT_INCLUDE_IGNORED) != 0)
|
153
291
|
diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_IGNORED;
|
154
|
-
if ((
|
292
|
+
if ((flags & GIT_STATUS_OPT_INCLUDE_UNMODIFIED) != 0)
|
155
293
|
diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNMODIFIED;
|
156
|
-
if ((
|
294
|
+
if ((flags & GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS) != 0)
|
157
295
|
diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_UNTRACKED_DIRS;
|
158
|
-
if ((
|
296
|
+
if ((flags & GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH) != 0)
|
159
297
|
diffopt.flags = diffopt.flags | GIT_DIFF_DISABLE_PATHSPEC_MATCH;
|
160
|
-
if ((
|
298
|
+
if ((flags & GIT_STATUS_OPT_RECURSE_IGNORED_DIRS) != 0)
|
161
299
|
diffopt.flags = diffopt.flags | GIT_DIFF_RECURSE_IGNORED_DIRS;
|
162
|
-
if ((
|
300
|
+
if ((flags & GIT_STATUS_OPT_EXCLUDE_SUBMODULES) != 0)
|
163
301
|
diffopt.flags = diffopt.flags | GIT_DIFF_IGNORE_SUBMODULES;
|
164
302
|
|
303
|
+
findopts_i2w.flags |= GIT_DIFF_FIND_FOR_UNTRACKED;
|
304
|
+
|
165
305
|
if (show != GIT_STATUS_SHOW_WORKDIR_ONLY) {
|
166
|
-
|
167
|
-
|
168
|
-
goto
|
306
|
+
if ((error = git_diff_tree_to_index(
|
307
|
+
&status->head2idx, repo, head, NULL, &diffopt)) < 0)
|
308
|
+
goto done;
|
309
|
+
|
310
|
+
if ((flags & GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX) != 0 &&
|
311
|
+
(error = git_diff_find_similar(status->head2idx, NULL)) < 0)
|
312
|
+
goto done;
|
169
313
|
}
|
170
314
|
|
171
315
|
if (show != GIT_STATUS_SHOW_INDEX_ONLY) {
|
172
|
-
|
173
|
-
|
174
|
-
goto
|
175
|
-
}
|
316
|
+
if ((error = git_diff_index_to_workdir(
|
317
|
+
&status->idx2wd, repo, NULL, &diffopt)) < 0)
|
318
|
+
goto done;
|
176
319
|
|
177
|
-
|
178
|
-
|
179
|
-
|
320
|
+
if ((flags & GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR) != 0 &&
|
321
|
+
(error = git_diff_find_similar(status->idx2wd, &findopts_i2w)) < 0)
|
322
|
+
goto done;
|
323
|
+
}
|
180
324
|
|
181
325
|
if (show == GIT_STATUS_SHOW_INDEX_THEN_WORKDIR) {
|
182
|
-
if ((
|
183
|
-
|
184
|
-
goto
|
326
|
+
if ((error = git_diff__paired_foreach(
|
327
|
+
status->head2idx, NULL, status_collect, status)) < 0)
|
328
|
+
goto done;
|
329
|
+
|
330
|
+
git_diff_list_free(status->head2idx);
|
331
|
+
status->head2idx = NULL;
|
332
|
+
}
|
185
333
|
|
186
|
-
|
187
|
-
|
334
|
+
if ((error = git_diff__paired_foreach(
|
335
|
+
status->head2idx, status->idx2wd, status_collect, status)) < 0)
|
336
|
+
goto done;
|
337
|
+
|
338
|
+
if (flags & GIT_STATUS_OPT_SORT_CASE_SENSITIVELY)
|
339
|
+
git_vector_set_cmp(&status->paired, status_entry_cmp);
|
340
|
+
if (flags & GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY)
|
341
|
+
git_vector_set_cmp(&status->paired, status_entry_icmp);
|
342
|
+
|
343
|
+
if ((flags &
|
344
|
+
(GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
|
345
|
+
GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR |
|
346
|
+
GIT_STATUS_OPT_SORT_CASE_SENSITIVELY |
|
347
|
+
GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY)) != 0)
|
348
|
+
git_vector_sort(&status->paired);
|
349
|
+
|
350
|
+
done:
|
351
|
+
if (error < 0) {
|
352
|
+
git_status_list_free(status);
|
353
|
+
status = NULL;
|
188
354
|
}
|
189
355
|
|
190
|
-
|
356
|
+
*out = status;
|
191
357
|
|
192
|
-
cleanup:
|
193
358
|
git_tree_free(head);
|
194
|
-
|
195
|
-
|
359
|
+
git_index_free(index);
|
360
|
+
|
361
|
+
return error;
|
362
|
+
}
|
363
|
+
|
364
|
+
size_t git_status_list_entrycount(git_status_list *status)
|
365
|
+
{
|
366
|
+
assert(status);
|
367
|
+
|
368
|
+
return status->paired.length;
|
369
|
+
}
|
370
|
+
|
371
|
+
const git_status_entry *git_status_byindex(git_status_list *status, size_t i)
|
372
|
+
{
|
373
|
+
assert(status);
|
196
374
|
|
197
|
-
|
198
|
-
|
375
|
+
return git_vector_get(&status->paired, i);
|
376
|
+
}
|
377
|
+
|
378
|
+
void git_status_list_free(git_status_list *status)
|
379
|
+
{
|
380
|
+
git_status_entry *status_entry;
|
381
|
+
size_t i;
|
382
|
+
|
383
|
+
if (status == NULL)
|
384
|
+
return;
|
385
|
+
|
386
|
+
git_diff_list_free(status->head2idx);
|
387
|
+
git_diff_list_free(status->idx2wd);
|
388
|
+
|
389
|
+
git_vector_foreach(&status->paired, i, status_entry)
|
390
|
+
git__free(status_entry);
|
391
|
+
|
392
|
+
git_vector_free(&status->paired);
|
199
393
|
|
200
|
-
|
394
|
+
git__memzero(status, sizeof(*status));
|
395
|
+
git__free(status);
|
201
396
|
}
|
202
397
|
|
203
|
-
int
|
398
|
+
int git_status_foreach_ext(
|
204
399
|
git_repository *repo,
|
205
|
-
|
400
|
+
const git_status_options *opts,
|
401
|
+
git_status_cb cb,
|
206
402
|
void *payload)
|
207
403
|
{
|
208
|
-
|
404
|
+
git_status_list *status;
|
405
|
+
const git_status_entry *status_entry;
|
406
|
+
size_t i;
|
407
|
+
int error = 0;
|
209
408
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
409
|
+
if ((error = git_status_list_new(&status, repo, opts)) < 0)
|
410
|
+
return error;
|
411
|
+
|
412
|
+
git_vector_foreach(&status->paired, i, status_entry) {
|
413
|
+
const char *path = status_entry->head_to_index ?
|
414
|
+
status_entry->head_to_index->old_file.path :
|
415
|
+
status_entry->index_to_workdir->old_file.path;
|
214
416
|
|
215
|
-
|
417
|
+
if (cb(path, status_entry->status, payload) != 0) {
|
418
|
+
error = GIT_EUSER;
|
419
|
+
giterr_clear();
|
420
|
+
break;
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
git_status_list_free(status);
|
425
|
+
|
426
|
+
return error;
|
427
|
+
}
|
428
|
+
|
429
|
+
int git_status_foreach(git_repository *repo, git_status_cb cb, void *payload)
|
430
|
+
{
|
431
|
+
return git_status_foreach_ext(repo, NULL, cb, payload);
|
216
432
|
}
|
217
433
|
|
218
434
|
struct status_file_info {
|
@@ -238,7 +454,7 @@ static int get_one_status(const char *path, unsigned int status, void *data)
|
|
238
454
|
p_fnmatch(sfi->expected, path, sfi->fnm_flags) != 0))
|
239
455
|
{
|
240
456
|
sfi->ambiguous = true;
|
241
|
-
return GIT_EAMBIGUOUS;
|
457
|
+
return GIT_EAMBIGUOUS; /* giterr_set will be done by caller */
|
242
458
|
}
|
243
459
|
|
244
460
|
return 0;
|
@@ -264,8 +480,9 @@ int git_status_file(
|
|
264
480
|
if (index->ignore_case)
|
265
481
|
sfi.fnm_flags = FNM_CASEFOLD;
|
266
482
|
|
267
|
-
opts.show
|
483
|
+
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
|
268
484
|
opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
|
485
|
+
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS |
|
269
486
|
GIT_STATUS_OPT_INCLUDE_UNTRACKED |
|
270
487
|
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS |
|
271
488
|
GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
|
@@ -281,22 +498,9 @@ int git_status_file(
|
|
281
498
|
}
|
282
499
|
|
283
500
|
if (!error && !sfi.count) {
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
* for it, then it must be contained inside an ignored directory, so
|
288
|
-
* mark it as such instead of generating an error.
|
289
|
-
*/
|
290
|
-
if (!git_buf_joinpath(&full, git_repository_workdir(repo), path) &&
|
291
|
-
git_path_exists(full.ptr))
|
292
|
-
sfi.status = GIT_STATUS_IGNORED;
|
293
|
-
else {
|
294
|
-
giterr_set(GITERR_INVALID,
|
295
|
-
"Attempt to get status of nonexistent file '%s'", path);
|
296
|
-
error = GIT_ENOTFOUND;
|
297
|
-
}
|
298
|
-
|
299
|
-
git_buf_free(&full);
|
501
|
+
giterr_set(GITERR_INVALID,
|
502
|
+
"Attempt to get status of nonexistent file '%s'", path);
|
503
|
+
error = GIT_ENOTFOUND;
|
300
504
|
}
|
301
505
|
|
302
506
|
*status_flags = sfi.status;
|