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/diff.h
CHANGED
@@ -26,17 +26,31 @@ enum {
|
|
26
26
|
GIT_DIFFCAPS_TRUST_MODE_BITS = (1 << 2), /* use st_mode? */
|
27
27
|
GIT_DIFFCAPS_TRUST_CTIME = (1 << 3), /* use st_ctime? */
|
28
28
|
GIT_DIFFCAPS_USE_DEV = (1 << 4), /* use st_dev? */
|
29
|
+
GIT_DIFFCAPS_TRUST_NANOSECS = (1 << 5), /* use stat time nanoseconds */
|
29
30
|
};
|
30
31
|
|
32
|
+
#define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
|
33
|
+
#define DIFF_FLAGS_NOT_BINARY (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA)
|
34
|
+
|
31
35
|
enum {
|
32
36
|
GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */
|
33
37
|
GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */
|
34
38
|
GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */
|
35
39
|
GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */
|
36
|
-
|
37
|
-
|
40
|
+
GIT_DIFF_FLAG__FREE_BLOB = (1 << 11), /* release the blob when done */
|
41
|
+
GIT_DIFF_FLAG__LOADED = (1 << 12), /* file data has been loaded */
|
42
|
+
|
43
|
+
GIT_DIFF_FLAG__TO_DELETE = (1 << 16), /* delete entry during rename det. */
|
44
|
+
GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */
|
45
|
+
GIT_DIFF_FLAG__IS_RENAME_TARGET = (1 << 18),
|
46
|
+
GIT_DIFF_FLAG__IS_RENAME_SOURCE = (1 << 19),
|
47
|
+
GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20),
|
38
48
|
};
|
39
49
|
|
50
|
+
#define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF)
|
51
|
+
|
52
|
+
#define GIT_DIFF__VERBOSE (1 << 30)
|
53
|
+
|
40
54
|
struct git_diff_list {
|
41
55
|
git_refcount rc;
|
42
56
|
git_repository *repo;
|
@@ -60,6 +74,7 @@ extern void git_diff__cleanup_modes(
|
|
60
74
|
extern void git_diff_list_addref(git_diff_list *diff);
|
61
75
|
|
62
76
|
extern int git_diff_delta__cmp(const void *a, const void *b);
|
77
|
+
extern int git_diff_delta__casecmp(const void *a, const void *b);
|
63
78
|
|
64
79
|
extern bool git_diff_delta__should_skip(
|
65
80
|
const git_diff_options *opts, const git_diff_delta *delta);
|
@@ -74,5 +89,22 @@ extern int git_diff__from_iterators(
|
|
74
89
|
git_iterator *new_iter,
|
75
90
|
const git_diff_options *opts);
|
76
91
|
|
92
|
+
extern int git_diff__paired_foreach(
|
93
|
+
git_diff_list *idx2head,
|
94
|
+
git_diff_list *wd2idx,
|
95
|
+
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
|
96
|
+
void *payload);
|
97
|
+
|
98
|
+
extern int git_diff_find_similar__hashsig_for_file(
|
99
|
+
void **out, const git_diff_file *f, const char *path, void *p);
|
100
|
+
|
101
|
+
extern int git_diff_find_similar__hashsig_for_buf(
|
102
|
+
void **out, const git_diff_file *f, const char *buf, size_t len, void *p);
|
103
|
+
|
104
|
+
extern void git_diff_find_similar__hashsig_free(void *sig, void *payload);
|
105
|
+
|
106
|
+
extern int git_diff_find_similar__calc_similarity(
|
107
|
+
int *score, void *siga, void *sigb, void *payload);
|
108
|
+
|
77
109
|
#endif
|
78
110
|
|
@@ -0,0 +1,405 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#include "common.h"
|
8
|
+
|
9
|
+
#include "git2/attr.h"
|
10
|
+
|
11
|
+
#include "diff.h"
|
12
|
+
#include "diff_patch.h"
|
13
|
+
#include "diff_driver.h"
|
14
|
+
#include "strmap.h"
|
15
|
+
#include "map.h"
|
16
|
+
#include "buf_text.h"
|
17
|
+
#include "repository.h"
|
18
|
+
|
19
|
+
GIT__USE_STRMAP;
|
20
|
+
|
21
|
+
typedef enum {
|
22
|
+
DIFF_DRIVER_AUTO = 0,
|
23
|
+
DIFF_DRIVER_BINARY = 1,
|
24
|
+
DIFF_DRIVER_TEXT = 2,
|
25
|
+
DIFF_DRIVER_PATTERNLIST = 3,
|
26
|
+
} git_diff_driver_t;
|
27
|
+
|
28
|
+
enum {
|
29
|
+
DIFF_CONTEXT_FIND_NORMAL = 0,
|
30
|
+
DIFF_CONTEXT_FIND_ICASE = (1 << 0),
|
31
|
+
DIFF_CONTEXT_FIND_EXT = (1 << 1),
|
32
|
+
};
|
33
|
+
|
34
|
+
/* data for finding function context for a given file type */
|
35
|
+
struct git_diff_driver {
|
36
|
+
git_diff_driver_t type;
|
37
|
+
uint32_t binary_flags;
|
38
|
+
uint32_t other_flags;
|
39
|
+
git_array_t(regex_t) fn_patterns;
|
40
|
+
regex_t word_pattern;
|
41
|
+
char name[GIT_FLEX_ARRAY];
|
42
|
+
};
|
43
|
+
|
44
|
+
struct git_diff_driver_registry {
|
45
|
+
git_strmap *drivers;
|
46
|
+
};
|
47
|
+
|
48
|
+
#define FORCE_DIFFABLE (GIT_DIFF_FORCE_TEXT | GIT_DIFF_FORCE_BINARY)
|
49
|
+
|
50
|
+
static git_diff_driver global_drivers[3] = {
|
51
|
+
{ DIFF_DRIVER_AUTO, 0, 0, },
|
52
|
+
{ DIFF_DRIVER_BINARY, GIT_DIFF_FORCE_BINARY, 0 },
|
53
|
+
{ DIFF_DRIVER_TEXT, GIT_DIFF_FORCE_TEXT, 0 },
|
54
|
+
};
|
55
|
+
|
56
|
+
git_diff_driver_registry *git_diff_driver_registry_new()
|
57
|
+
{
|
58
|
+
git_diff_driver_registry *reg =
|
59
|
+
git__calloc(1, sizeof(git_diff_driver_registry));
|
60
|
+
if (!reg)
|
61
|
+
return NULL;
|
62
|
+
|
63
|
+
if ((reg->drivers = git_strmap_alloc()) == NULL) {
|
64
|
+
git_diff_driver_registry_free(reg);
|
65
|
+
return NULL;
|
66
|
+
}
|
67
|
+
|
68
|
+
return reg;
|
69
|
+
}
|
70
|
+
|
71
|
+
void git_diff_driver_registry_free(git_diff_driver_registry *reg)
|
72
|
+
{
|
73
|
+
git_diff_driver *drv;
|
74
|
+
|
75
|
+
if (!reg)
|
76
|
+
return;
|
77
|
+
|
78
|
+
git_strmap_foreach_value(reg->drivers, drv, git_diff_driver_free(drv));
|
79
|
+
git_strmap_free(reg->drivers);
|
80
|
+
git__free(reg);
|
81
|
+
}
|
82
|
+
|
83
|
+
static int diff_driver_add_funcname(
|
84
|
+
git_diff_driver *drv, const char *name, int regex_flags)
|
85
|
+
{
|
86
|
+
int error;
|
87
|
+
regex_t re, *re_ptr;
|
88
|
+
|
89
|
+
if ((error = regcomp(&re, name, regex_flags)) != 0) {
|
90
|
+
/* TODO: warning about bad regex instead of failure */
|
91
|
+
error = giterr_set_regex(&re, error);
|
92
|
+
regfree(&re);
|
93
|
+
return error;
|
94
|
+
}
|
95
|
+
|
96
|
+
re_ptr = git_array_alloc(drv->fn_patterns);
|
97
|
+
GITERR_CHECK_ALLOC(re_ptr);
|
98
|
+
|
99
|
+
memcpy(re_ptr, &re, sizeof(re));
|
100
|
+
return 0;
|
101
|
+
}
|
102
|
+
|
103
|
+
static int diff_driver_xfuncname(const git_config_entry *entry, void *payload)
|
104
|
+
{
|
105
|
+
return diff_driver_add_funcname(payload, entry->value, REG_EXTENDED);
|
106
|
+
}
|
107
|
+
|
108
|
+
static int diff_driver_funcname(const git_config_entry *entry, void *payload)
|
109
|
+
{
|
110
|
+
return diff_driver_add_funcname(payload, entry->value, 0);
|
111
|
+
}
|
112
|
+
|
113
|
+
static git_diff_driver_registry *git_repository_driver_registry(
|
114
|
+
git_repository *repo)
|
115
|
+
{
|
116
|
+
if (!repo->diff_drivers) {
|
117
|
+
git_diff_driver_registry *reg = git_diff_driver_registry_new();
|
118
|
+
reg = git__compare_and_swap(&repo->diff_drivers, NULL, reg);
|
119
|
+
|
120
|
+
if (reg != NULL) /* if we race, free losing allocation */
|
121
|
+
git_diff_driver_registry_free(reg);
|
122
|
+
}
|
123
|
+
|
124
|
+
if (!repo->diff_drivers)
|
125
|
+
giterr_set(GITERR_REPOSITORY, "Unable to create diff driver registry");
|
126
|
+
|
127
|
+
return repo->diff_drivers;
|
128
|
+
}
|
129
|
+
|
130
|
+
static int git_diff_driver_load(
|
131
|
+
git_diff_driver **out, git_repository *repo, const char *driver_name)
|
132
|
+
{
|
133
|
+
int error = 0, bval;
|
134
|
+
git_diff_driver_registry *reg;
|
135
|
+
git_diff_driver *drv;
|
136
|
+
size_t namelen = strlen(driver_name);
|
137
|
+
khiter_t pos;
|
138
|
+
git_config *cfg;
|
139
|
+
git_buf name = GIT_BUF_INIT;
|
140
|
+
const char *val;
|
141
|
+
bool found_driver = false;
|
142
|
+
|
143
|
+
reg = git_repository_driver_registry(repo);
|
144
|
+
if (!reg)
|
145
|
+
return -1;
|
146
|
+
else {
|
147
|
+
pos = git_strmap_lookup_index(reg->drivers, driver_name);
|
148
|
+
if (git_strmap_valid_index(reg->drivers, pos)) {
|
149
|
+
*out = git_strmap_value_at(reg->drivers, pos);
|
150
|
+
return 0;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
/* if you can't read config for repo, just use default driver */
|
155
|
+
if (git_repository_config__weakptr(&cfg, repo) < 0) {
|
156
|
+
giterr_clear();
|
157
|
+
return GIT_ENOTFOUND;
|
158
|
+
}
|
159
|
+
|
160
|
+
drv = git__calloc(1, sizeof(git_diff_driver) + namelen + 1);
|
161
|
+
GITERR_CHECK_ALLOC(drv);
|
162
|
+
drv->type = DIFF_DRIVER_AUTO;
|
163
|
+
memcpy(drv->name, driver_name, namelen);
|
164
|
+
|
165
|
+
if ((error = git_buf_printf(&name, "diff.%s.binary", driver_name)) < 0)
|
166
|
+
goto done;
|
167
|
+
if ((error = git_config_get_string(&val, cfg, name.ptr)) < 0) {
|
168
|
+
if (error != GIT_ENOTFOUND)
|
169
|
+
goto done;
|
170
|
+
/* diff.<driver>.binary unspecified, so just continue */
|
171
|
+
giterr_clear();
|
172
|
+
} else if (git_config_parse_bool(&bval, val) < 0) {
|
173
|
+
/* TODO: warn that diff.<driver>.binary has invalid value */
|
174
|
+
giterr_clear();
|
175
|
+
} else if (bval) {
|
176
|
+
/* if diff.<driver>.binary is true, just return the binary driver */
|
177
|
+
*out = &global_drivers[DIFF_DRIVER_BINARY];
|
178
|
+
goto done;
|
179
|
+
} else {
|
180
|
+
/* if diff.<driver>.binary is false, force binary checks off */
|
181
|
+
/* but still may have custom function context patterns, etc. */
|
182
|
+
drv->binary_flags = GIT_DIFF_FORCE_TEXT;
|
183
|
+
found_driver = true;
|
184
|
+
}
|
185
|
+
|
186
|
+
/* TODO: warn if diff.<name>.command or diff.<name>.textconv are set */
|
187
|
+
|
188
|
+
git_buf_truncate(&name, namelen + strlen("diff.."));
|
189
|
+
git_buf_put(&name, "xfuncname", strlen("xfuncname"));
|
190
|
+
if ((error = git_config_get_multivar(
|
191
|
+
cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) {
|
192
|
+
if (error != GIT_ENOTFOUND)
|
193
|
+
goto done;
|
194
|
+
giterr_clear(); /* no diff.<driver>.xfuncname, so just continue */
|
195
|
+
}
|
196
|
+
|
197
|
+
git_buf_truncate(&name, namelen + strlen("diff.."));
|
198
|
+
git_buf_put(&name, "funcname", strlen("funcname"));
|
199
|
+
if ((error = git_config_get_multivar(
|
200
|
+
cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) {
|
201
|
+
if (error != GIT_ENOTFOUND)
|
202
|
+
goto done;
|
203
|
+
giterr_clear(); /* no diff.<driver>.funcname, so just continue */
|
204
|
+
}
|
205
|
+
|
206
|
+
/* if we found any patterns, set driver type to use correct callback */
|
207
|
+
if (git_array_size(drv->fn_patterns) > 0) {
|
208
|
+
drv->type = DIFF_DRIVER_PATTERNLIST;
|
209
|
+
found_driver = true;
|
210
|
+
}
|
211
|
+
|
212
|
+
git_buf_truncate(&name, namelen + strlen("diff.."));
|
213
|
+
git_buf_put(&name, "wordregex", strlen("wordregex"));
|
214
|
+
if ((error = git_config_get_string(&val, cfg, name.ptr)) < 0) {
|
215
|
+
if (error != GIT_ENOTFOUND)
|
216
|
+
goto done;
|
217
|
+
giterr_clear(); /* no diff.<driver>.wordregex, so just continue */
|
218
|
+
} else if ((error = regcomp(&drv->word_pattern, val, REG_EXTENDED)) != 0) {
|
219
|
+
/* TODO: warning about bad regex instead of failure */
|
220
|
+
error = giterr_set_regex(&drv->word_pattern, error);
|
221
|
+
goto done;
|
222
|
+
} else {
|
223
|
+
found_driver = true;
|
224
|
+
}
|
225
|
+
|
226
|
+
/* TODO: look up diff.<driver>.algorithm to turn on minimal / patience
|
227
|
+
* diff in drv->other_flags
|
228
|
+
*/
|
229
|
+
|
230
|
+
/* if no driver config found at all, fall back on AUTO driver */
|
231
|
+
if (!found_driver)
|
232
|
+
goto done;
|
233
|
+
|
234
|
+
/* store driver in registry */
|
235
|
+
git_strmap_insert(reg->drivers, drv->name, drv, error);
|
236
|
+
if (error < 0)
|
237
|
+
goto done;
|
238
|
+
|
239
|
+
*out = drv;
|
240
|
+
|
241
|
+
done:
|
242
|
+
git_buf_free(&name);
|
243
|
+
|
244
|
+
if (!*out)
|
245
|
+
*out = &global_drivers[DIFF_DRIVER_AUTO];
|
246
|
+
|
247
|
+
if (drv && drv != *out)
|
248
|
+
git_diff_driver_free(drv);
|
249
|
+
|
250
|
+
return error;
|
251
|
+
}
|
252
|
+
|
253
|
+
int git_diff_driver_lookup(
|
254
|
+
git_diff_driver **out, git_repository *repo, const char *path)
|
255
|
+
{
|
256
|
+
int error = 0;
|
257
|
+
const char *value;
|
258
|
+
|
259
|
+
assert(out);
|
260
|
+
|
261
|
+
if (!repo || !path || !strlen(path))
|
262
|
+
goto use_auto;
|
263
|
+
|
264
|
+
if ((error = git_attr_get(&value, repo, 0, path, "diff")) < 0)
|
265
|
+
return error;
|
266
|
+
|
267
|
+
if (GIT_ATTR_UNSPECIFIED(value))
|
268
|
+
/* just use the auto value */;
|
269
|
+
else if (GIT_ATTR_FALSE(value))
|
270
|
+
*out = &global_drivers[DIFF_DRIVER_BINARY];
|
271
|
+
else if (GIT_ATTR_TRUE(value))
|
272
|
+
*out = &global_drivers[DIFF_DRIVER_TEXT];
|
273
|
+
|
274
|
+
/* otherwise look for driver information in config and build driver */
|
275
|
+
else if ((error = git_diff_driver_load(out, repo, value)) < 0) {
|
276
|
+
if (error != GIT_ENOTFOUND)
|
277
|
+
return error;
|
278
|
+
else
|
279
|
+
giterr_clear();
|
280
|
+
}
|
281
|
+
|
282
|
+
use_auto:
|
283
|
+
if (!*out)
|
284
|
+
*out = &global_drivers[DIFF_DRIVER_AUTO];
|
285
|
+
|
286
|
+
return 0;
|
287
|
+
}
|
288
|
+
|
289
|
+
void git_diff_driver_free(git_diff_driver *driver)
|
290
|
+
{
|
291
|
+
size_t i;
|
292
|
+
|
293
|
+
if (!driver)
|
294
|
+
return;
|
295
|
+
|
296
|
+
for (i = 0; i < git_array_size(driver->fn_patterns); ++i)
|
297
|
+
regfree(git_array_get(driver->fn_patterns, i));
|
298
|
+
git_array_clear(driver->fn_patterns);
|
299
|
+
|
300
|
+
regfree(&driver->word_pattern);
|
301
|
+
|
302
|
+
git__free(driver);
|
303
|
+
}
|
304
|
+
|
305
|
+
void git_diff_driver_update_options(
|
306
|
+
uint32_t *option_flags, git_diff_driver *driver)
|
307
|
+
{
|
308
|
+
if ((*option_flags & FORCE_DIFFABLE) == 0)
|
309
|
+
*option_flags |= driver->binary_flags;
|
310
|
+
|
311
|
+
*option_flags |= driver->other_flags;
|
312
|
+
}
|
313
|
+
|
314
|
+
int git_diff_driver_content_is_binary(
|
315
|
+
git_diff_driver *driver, const char *content, size_t content_len)
|
316
|
+
{
|
317
|
+
const git_buf search = { (char *)content, 0, min(content_len, 4000) };
|
318
|
+
|
319
|
+
GIT_UNUSED(driver);
|
320
|
+
|
321
|
+
/* TODO: provide encoding / binary detection callbacks that can
|
322
|
+
* be UTF-8 aware, etc. For now, instead of trying to be smart,
|
323
|
+
* let's just use the simple NUL-byte detection that core git uses.
|
324
|
+
*/
|
325
|
+
|
326
|
+
/* previously was: if (git_buf_text_is_binary(&search)) */
|
327
|
+
if (git_buf_text_contains_nul(&search))
|
328
|
+
return 1;
|
329
|
+
|
330
|
+
return 0;
|
331
|
+
}
|
332
|
+
|
333
|
+
static int diff_context_line__simple(
|
334
|
+
git_diff_driver *driver, const char *line, size_t line_len)
|
335
|
+
{
|
336
|
+
GIT_UNUSED(driver);
|
337
|
+
GIT_UNUSED(line_len);
|
338
|
+
return (git__isalpha(*line) || *line == '_' || *line == '$');
|
339
|
+
}
|
340
|
+
|
341
|
+
static int diff_context_line__pattern_match(
|
342
|
+
git_diff_driver *driver, const char *line, size_t line_len)
|
343
|
+
{
|
344
|
+
size_t i;
|
345
|
+
|
346
|
+
GIT_UNUSED(line_len);
|
347
|
+
|
348
|
+
for (i = 0; i < git_array_size(driver->fn_patterns); ++i) {
|
349
|
+
if (!regexec(git_array_get(driver->fn_patterns, i), line, 0, NULL, 0))
|
350
|
+
return true;
|
351
|
+
}
|
352
|
+
|
353
|
+
return false;
|
354
|
+
}
|
355
|
+
|
356
|
+
static long diff_context_find(
|
357
|
+
const char *line,
|
358
|
+
long line_len,
|
359
|
+
char *out,
|
360
|
+
long out_size,
|
361
|
+
void *payload)
|
362
|
+
{
|
363
|
+
git_diff_find_context_payload *ctxt = payload;
|
364
|
+
|
365
|
+
if (git_buf_set(&ctxt->line, line, (size_t)line_len) < 0)
|
366
|
+
return -1;
|
367
|
+
git_buf_rtrim(&ctxt->line);
|
368
|
+
|
369
|
+
if (!ctxt->line.size)
|
370
|
+
return -1;
|
371
|
+
|
372
|
+
if (!ctxt->match_line ||
|
373
|
+
!ctxt->match_line(ctxt->driver, ctxt->line.ptr, ctxt->line.size))
|
374
|
+
return -1;
|
375
|
+
|
376
|
+
git_buf_truncate(&ctxt->line, (size_t)out_size);
|
377
|
+
git_buf_copy_cstr(out, (size_t)out_size, &ctxt->line);
|
378
|
+
|
379
|
+
return (long)ctxt->line.size;
|
380
|
+
}
|
381
|
+
|
382
|
+
void git_diff_find_context_init(
|
383
|
+
git_diff_find_context_fn *findfn_out,
|
384
|
+
git_diff_find_context_payload *payload_out,
|
385
|
+
git_diff_driver *driver)
|
386
|
+
{
|
387
|
+
*findfn_out = driver ? diff_context_find : NULL;
|
388
|
+
|
389
|
+
memset(payload_out, 0, sizeof(*payload_out));
|
390
|
+
if (driver) {
|
391
|
+
payload_out->driver = driver;
|
392
|
+
payload_out->match_line = (driver->type == DIFF_DRIVER_PATTERNLIST) ?
|
393
|
+
diff_context_line__pattern_match : diff_context_line__simple;
|
394
|
+
git_buf_init(&payload_out->line, 0);
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
void git_diff_find_context_clear(git_diff_find_context_payload *payload)
|
399
|
+
{
|
400
|
+
if (payload) {
|
401
|
+
git_buf_free(&payload->line);
|
402
|
+
payload->driver = NULL;
|
403
|
+
}
|
404
|
+
}
|
405
|
+
|