rugged 0.17.0.b7 → 0.18.0.b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -1
- data/README.md +88 -32
- data/ext/rugged/extconf.rb +4 -2
- data/ext/rugged/rugged.c +72 -10
- data/ext/rugged/rugged.h +14 -10
- data/ext/rugged/rugged_blob.c +8 -10
- data/ext/rugged/rugged_branch.c +11 -14
- data/ext/rugged/rugged_commit.c +31 -24
- data/ext/rugged/rugged_config.c +2 -2
- data/ext/rugged/rugged_index.c +133 -198
- data/ext/rugged/rugged_note.c +372 -0
- data/ext/rugged/rugged_object.c +50 -22
- data/ext/rugged/rugged_reference.c +122 -130
- data/ext/rugged/rugged_remote.c +72 -29
- data/ext/rugged/rugged_repo.c +402 -20
- data/ext/rugged/rugged_revwalk.c +7 -3
- data/ext/rugged/rugged_settings.c +110 -0
- data/ext/rugged/rugged_signature.c +23 -7
- data/ext/rugged/rugged_tag.c +32 -16
- data/ext/rugged/rugged_tree.c +44 -15
- data/lib/rugged.rb +1 -0
- data/lib/rugged/index.rb +8 -0
- data/lib/rugged/remote.rb +13 -0
- data/lib/rugged/repository.rb +3 -3
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +13 -15
- data/test/branch_test.rb +32 -67
- data/test/commit_test.rb +50 -12
- data/test/config_test.rb +12 -11
- data/test/coverage/HEAD.json +1 -1
- data/test/coverage/cover.rb +40 -21
- data/test/errors_test.rb +34 -0
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
- data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
- data/test/index_test.rb +65 -69
- data/test/lib_test.rb +76 -11
- data/test/note_test.rb +158 -0
- data/test/object_test.rb +8 -11
- data/test/reference_test.rb +77 -85
- data/test/remote_test.rb +86 -8
- data/test/repo_pack_test.rb +9 -7
- data/test/repo_reset_test.rb +80 -0
- data/test/repo_test.rb +176 -53
- data/test/tag_test.rb +44 -7
- data/test/test_helper.rb +63 -35
- data/test/tree_test.rb +34 -13
- data/test/walker_test.rb +14 -14
- data/vendor/libgit2/Makefile.embed +1 -1
- data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
- data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
- data/vendor/libgit2/deps/regex/regcomp.c +7 -6
- data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
- data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
- data/vendor/libgit2/deps/regex/regexec.c +5 -5
- data/vendor/libgit2/include/git2.h +5 -1
- data/vendor/libgit2/include/git2/attr.h +4 -2
- data/vendor/libgit2/include/git2/blob.h +39 -12
- data/vendor/libgit2/include/git2/branch.h +123 -35
- data/vendor/libgit2/include/git2/checkout.h +206 -48
- data/vendor/libgit2/include/git2/clone.h +72 -27
- data/vendor/libgit2/include/git2/commit.h +20 -17
- data/vendor/libgit2/include/git2/common.h +67 -1
- data/vendor/libgit2/include/git2/config.h +81 -60
- data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
- data/vendor/libgit2/include/git2/diff.h +459 -150
- data/vendor/libgit2/include/git2/errors.h +9 -1
- data/vendor/libgit2/include/git2/graph.h +41 -0
- data/vendor/libgit2/include/git2/ignore.h +7 -6
- data/vendor/libgit2/include/git2/index.h +323 -97
- data/vendor/libgit2/include/git2/indexer.h +27 -59
- data/vendor/libgit2/include/git2/inttypes.h +4 -0
- data/vendor/libgit2/include/git2/merge.h +13 -3
- data/vendor/libgit2/include/git2/message.h +14 -8
- data/vendor/libgit2/include/git2/net.h +9 -7
- data/vendor/libgit2/include/git2/notes.h +88 -29
- data/vendor/libgit2/include/git2/object.h +16 -6
- data/vendor/libgit2/include/git2/odb.h +80 -17
- data/vendor/libgit2/include/git2/odb_backend.h +47 -11
- data/vendor/libgit2/include/git2/oid.h +26 -17
- data/vendor/libgit2/include/git2/pack.h +62 -8
- data/vendor/libgit2/include/git2/push.h +131 -0
- data/vendor/libgit2/include/git2/refdb.h +103 -0
- data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
- data/vendor/libgit2/include/git2/reflog.h +30 -21
- data/vendor/libgit2/include/git2/refs.h +215 -193
- data/vendor/libgit2/include/git2/refspec.h +22 -2
- data/vendor/libgit2/include/git2/remote.h +158 -37
- data/vendor/libgit2/include/git2/repository.h +150 -31
- data/vendor/libgit2/include/git2/reset.h +43 -9
- data/vendor/libgit2/include/git2/revparse.h +48 -4
- data/vendor/libgit2/include/git2/revwalk.h +25 -10
- data/vendor/libgit2/include/git2/signature.h +20 -12
- data/vendor/libgit2/include/git2/stash.h +121 -0
- data/vendor/libgit2/include/git2/status.h +122 -53
- data/vendor/libgit2/include/git2/strarray.h +17 -11
- data/vendor/libgit2/include/git2/submodule.h +42 -7
- data/vendor/libgit2/include/git2/tag.h +72 -59
- data/vendor/libgit2/include/git2/threads.h +4 -2
- data/vendor/libgit2/include/git2/trace.h +68 -0
- data/vendor/libgit2/include/git2/transport.h +328 -0
- data/vendor/libgit2/include/git2/tree.h +149 -120
- data/vendor/libgit2/include/git2/types.h +13 -12
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/src/amiga/map.c +2 -2
- data/vendor/libgit2/src/attr.c +58 -48
- data/vendor/libgit2/src/attr.h +4 -18
- data/vendor/libgit2/src/attr_file.c +30 -6
- data/vendor/libgit2/src/attr_file.h +6 -8
- data/vendor/libgit2/src/attrcache.h +24 -0
- data/vendor/libgit2/src/blob.c +30 -7
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +361 -68
- data/vendor/libgit2/src/branch.h +17 -0
- data/vendor/libgit2/src/bswap.h +1 -1
- data/vendor/libgit2/src/buf_text.c +291 -0
- data/vendor/libgit2/src/buf_text.h +122 -0
- data/vendor/libgit2/src/buffer.c +27 -101
- data/vendor/libgit2/src/buffer.h +54 -39
- data/vendor/libgit2/src/cache.c +15 -6
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/cc-compat.h +3 -1
- data/vendor/libgit2/src/checkout.c +1165 -222
- data/vendor/libgit2/src/checkout.h +24 -0
- data/vendor/libgit2/src/clone.c +171 -86
- data/vendor/libgit2/src/commit.c +44 -45
- data/vendor/libgit2/src/commit.h +3 -3
- data/vendor/libgit2/src/commit_list.c +194 -0
- data/vendor/libgit2/src/commit_list.h +49 -0
- data/vendor/libgit2/src/common.h +44 -10
- data/vendor/libgit2/src/compress.c +1 -1
- data/vendor/libgit2/src/compress.h +1 -1
- data/vendor/libgit2/src/config.c +211 -124
- data/vendor/libgit2/src/config.h +23 -4
- data/vendor/libgit2/src/config_cache.c +2 -2
- data/vendor/libgit2/src/config_file.c +129 -53
- data/vendor/libgit2/src/config_file.h +10 -8
- data/vendor/libgit2/src/crlf.c +66 -67
- data/vendor/libgit2/src/date.c +12 -12
- data/vendor/libgit2/src/delta-apply.c +14 -1
- data/vendor/libgit2/src/delta-apply.h +18 -1
- data/vendor/libgit2/src/delta.c +40 -107
- data/vendor/libgit2/src/delta.h +19 -17
- data/vendor/libgit2/src/diff.c +347 -496
- data/vendor/libgit2/src/diff.h +27 -1
- data/vendor/libgit2/src/diff_output.c +564 -249
- data/vendor/libgit2/src/diff_output.h +15 -8
- data/vendor/libgit2/src/diff_tform.c +687 -0
- data/vendor/libgit2/src/errors.c +27 -36
- data/vendor/libgit2/src/fetch.c +13 -351
- data/vendor/libgit2/src/fetch.h +13 -3
- data/vendor/libgit2/src/fetchhead.c +295 -0
- data/vendor/libgit2/src/fetchhead.h +34 -0
- data/vendor/libgit2/src/filebuf.c +42 -15
- data/vendor/libgit2/src/filebuf.h +4 -2
- data/vendor/libgit2/src/fileops.c +466 -113
- data/vendor/libgit2/src/fileops.h +154 -28
- data/vendor/libgit2/src/filter.c +3 -75
- data/vendor/libgit2/src/filter.h +1 -29
- data/vendor/libgit2/src/fnmatch.c +1 -1
- data/vendor/libgit2/src/fnmatch.h +1 -1
- data/vendor/libgit2/src/global.c +54 -10
- data/vendor/libgit2/src/global.h +10 -1
- data/vendor/libgit2/src/graph.c +178 -0
- data/vendor/libgit2/src/hash.c +25 -52
- data/vendor/libgit2/src/hash.h +21 -9
- data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
- data/vendor/libgit2/src/hash/hash_generic.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
- data/vendor/libgit2/src/hash/hash_win32.c +291 -0
- data/vendor/libgit2/src/hash/hash_win32.h +140 -0
- data/vendor/libgit2/src/hashsig.c +368 -0
- data/vendor/libgit2/src/hashsig.h +72 -0
- data/vendor/libgit2/src/ignore.c +22 -15
- data/vendor/libgit2/src/ignore.h +6 -1
- data/vendor/libgit2/src/index.c +770 -171
- data/vendor/libgit2/src/index.h +13 -5
- data/vendor/libgit2/src/indexer.c +286 -431
- data/vendor/libgit2/src/iterator.c +854 -466
- data/vendor/libgit2/src/iterator.h +134 -109
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +296 -0
- data/vendor/libgit2/src/merge.h +22 -0
- data/vendor/libgit2/src/message.c +1 -1
- data/vendor/libgit2/src/message.h +1 -1
- data/vendor/libgit2/src/mwindow.c +35 -30
- data/vendor/libgit2/src/mwindow.h +2 -2
- data/vendor/libgit2/src/netops.c +162 -98
- data/vendor/libgit2/src/netops.h +50 -15
- data/vendor/libgit2/src/notes.c +109 -58
- data/vendor/libgit2/src/notes.h +2 -1
- data/vendor/libgit2/src/object.c +46 -57
- data/vendor/libgit2/src/object.h +1 -8
- data/vendor/libgit2/src/odb.c +151 -40
- data/vendor/libgit2/src/odb.h +5 -1
- data/vendor/libgit2/src/odb_loose.c +4 -5
- data/vendor/libgit2/src/odb_pack.c +122 -80
- data/vendor/libgit2/src/offmap.h +65 -0
- data/vendor/libgit2/src/oid.c +12 -4
- data/vendor/libgit2/src/oidmap.h +1 -1
- data/vendor/libgit2/src/pack-objects.c +88 -61
- data/vendor/libgit2/src/pack-objects.h +8 -8
- data/vendor/libgit2/src/pack.c +293 -28
- data/vendor/libgit2/src/pack.h +49 -4
- data/vendor/libgit2/src/path.c +103 -14
- data/vendor/libgit2/src/path.h +23 -7
- data/vendor/libgit2/src/pathspec.c +168 -0
- data/vendor/libgit2/src/pathspec.h +40 -0
- data/vendor/libgit2/src/pool.c +29 -4
- data/vendor/libgit2/src/pool.h +8 -1
- data/vendor/libgit2/src/posix.c +26 -27
- data/vendor/libgit2/src/posix.h +2 -3
- data/vendor/libgit2/src/pqueue.c +23 -1
- data/vendor/libgit2/src/pqueue.h +23 -1
- data/vendor/libgit2/src/push.c +653 -0
- data/vendor/libgit2/src/push.h +51 -0
- data/vendor/libgit2/src/refdb.c +185 -0
- data/vendor/libgit2/src/refdb.h +46 -0
- data/vendor/libgit2/src/refdb_fs.c +1024 -0
- data/vendor/libgit2/src/refdb_fs.h +15 -0
- data/vendor/libgit2/src/reflog.c +77 -45
- data/vendor/libgit2/src/reflog.h +1 -3
- data/vendor/libgit2/src/refs.c +366 -1326
- data/vendor/libgit2/src/refs.h +22 -13
- data/vendor/libgit2/src/refspec.c +46 -7
- data/vendor/libgit2/src/refspec.h +11 -1
- data/vendor/libgit2/src/remote.c +758 -120
- data/vendor/libgit2/src/remote.h +10 -5
- data/vendor/libgit2/src/repo_template.h +6 -6
- data/vendor/libgit2/src/repository.c +315 -96
- data/vendor/libgit2/src/repository.h +5 -3
- data/vendor/libgit2/src/reset.c +99 -81
- data/vendor/libgit2/src/revparse.c +157 -84
- data/vendor/libgit2/src/revwalk.c +68 -470
- data/vendor/libgit2/src/revwalk.h +44 -0
- data/vendor/libgit2/src/sha1_lookup.c +1 -1
- data/vendor/libgit2/src/sha1_lookup.h +1 -1
- data/vendor/libgit2/src/signature.c +68 -200
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/stash.c +663 -0
- data/vendor/libgit2/src/status.c +101 -79
- data/vendor/libgit2/src/strmap.h +1 -1
- data/vendor/libgit2/src/submodule.c +67 -51
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/tag.c +35 -29
- data/vendor/libgit2/src/tag.h +1 -1
- data/vendor/libgit2/src/thread-utils.c +1 -1
- data/vendor/libgit2/src/thread-utils.h +2 -2
- data/vendor/libgit2/src/trace.c +39 -0
- data/vendor/libgit2/src/trace.h +56 -0
- data/vendor/libgit2/src/transport.c +81 -34
- data/vendor/libgit2/src/transports/cred.c +60 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
- data/vendor/libgit2/src/transports/git.c +234 -127
- data/vendor/libgit2/src/transports/http.c +761 -433
- data/vendor/libgit2/src/transports/local.c +460 -64
- data/vendor/libgit2/src/transports/smart.c +345 -0
- data/vendor/libgit2/src/transports/smart.h +179 -0
- data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
- data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
- data/vendor/libgit2/src/transports/winhttp.c +1136 -0
- data/vendor/libgit2/src/tree-cache.c +2 -2
- data/vendor/libgit2/src/tree-cache.h +1 -1
- data/vendor/libgit2/src/tree.c +239 -166
- data/vendor/libgit2/src/tree.h +11 -2
- data/vendor/libgit2/src/tsort.c +39 -23
- data/vendor/libgit2/src/unix/map.c +1 -1
- data/vendor/libgit2/src/unix/posix.h +12 -2
- data/vendor/libgit2/src/unix/realpath.c +30 -0
- data/vendor/libgit2/src/util.c +250 -13
- data/vendor/libgit2/src/util.h +71 -14
- data/vendor/libgit2/src/vector.c +123 -60
- data/vendor/libgit2/src/vector.h +24 -22
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/dir.h +1 -1
- data/vendor/libgit2/src/win32/error.c +77 -0
- data/vendor/libgit2/src/win32/error.h +13 -0
- data/vendor/libgit2/src/win32/findfile.c +143 -54
- data/vendor/libgit2/src/win32/findfile.h +10 -6
- data/vendor/libgit2/src/win32/map.c +1 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
- data/vendor/libgit2/src/win32/posix.h +10 -1
- data/vendor/libgit2/src/win32/posix_w32.c +132 -63
- data/vendor/libgit2/src/win32/precompiled.c +1 -1
- data/vendor/libgit2/src/win32/pthread.c +1 -1
- data/vendor/libgit2/src/win32/pthread.h +1 -1
- data/vendor/libgit2/src/win32/utf-conv.c +5 -5
- data/vendor/libgit2/src/win32/utf-conv.h +3 -3
- data/vendor/libgit2/src/win32/version.h +20 -0
- metadata +308 -252
- data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
- data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
- data/test/index_test.rb~ +0 -218
- data/vendor/libgit2/src/pkt.h +0 -91
- data/vendor/libgit2/src/ppc/sha1.c +0 -70
- data/vendor/libgit2/src/ppc/sha1.h +0 -26
- data/vendor/libgit2/src/protocol.c +0 -110
- data/vendor/libgit2/src/protocol.h +0 -21
- data/vendor/libgit2/src/sha1.h +0 -33
- data/vendor/libgit2/src/transport.h +0 -148
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (C)
|
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
|
@@ -27,12 +27,12 @@ typedef struct {
|
|
|
27
27
|
git_repository *repo;
|
|
28
28
|
git_diff_list *diff;
|
|
29
29
|
const git_diff_options *opts;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
void *
|
|
34
|
-
int
|
|
35
|
-
git_diff_range
|
|
30
|
+
git_diff_file_cb file_cb;
|
|
31
|
+
git_diff_hunk_cb hunk_cb;
|
|
32
|
+
git_diff_data_cb data_cb;
|
|
33
|
+
void *payload;
|
|
34
|
+
int error;
|
|
35
|
+
git_diff_range range;
|
|
36
36
|
xdemitconf_t xdiff_config;
|
|
37
37
|
xpparam_t xdiff_params;
|
|
38
38
|
} diff_context;
|
|
@@ -42,7 +42,7 @@ typedef struct diff_patch_line diff_patch_line;
|
|
|
42
42
|
struct diff_patch_line {
|
|
43
43
|
const char *ptr;
|
|
44
44
|
size_t len;
|
|
45
|
-
|
|
45
|
+
size_t lines, oldno, newno;
|
|
46
46
|
char origin;
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -72,6 +72,7 @@ struct git_diff_patch {
|
|
|
72
72
|
size_t hunks_asize, hunks_size;
|
|
73
73
|
diff_patch_line *lines;
|
|
74
74
|
size_t lines_asize, lines_size;
|
|
75
|
+
size_t oldno, newno;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
/* context for performing diff on a single delta */
|
|
@@ -83,4 +84,10 @@ typedef struct {
|
|
|
83
84
|
uint32_t diffed : 1;
|
|
84
85
|
} diff_delta_context;
|
|
85
86
|
|
|
87
|
+
extern int git_diff__paired_foreach(
|
|
88
|
+
git_diff_list *idx2head,
|
|
89
|
+
git_diff_list *wd2idx,
|
|
90
|
+
int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload),
|
|
91
|
+
void *payload);
|
|
92
|
+
|
|
86
93
|
#endif
|
|
@@ -0,0 +1,687 @@
|
|
|
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
|
+
#include "diff.h"
|
|
9
|
+
#include "git2/config.h"
|
|
10
|
+
#include "git2/blob.h"
|
|
11
|
+
#include "hashsig.h"
|
|
12
|
+
|
|
13
|
+
static git_diff_delta *diff_delta__dup(
|
|
14
|
+
const git_diff_delta *d, git_pool *pool)
|
|
15
|
+
{
|
|
16
|
+
git_diff_delta *delta = git__malloc(sizeof(git_diff_delta));
|
|
17
|
+
if (!delta)
|
|
18
|
+
return NULL;
|
|
19
|
+
|
|
20
|
+
memcpy(delta, d, sizeof(git_diff_delta));
|
|
21
|
+
|
|
22
|
+
delta->old_file.path = git_pool_strdup(pool, d->old_file.path);
|
|
23
|
+
if (delta->old_file.path == NULL)
|
|
24
|
+
goto fail;
|
|
25
|
+
|
|
26
|
+
if (d->new_file.path != d->old_file.path) {
|
|
27
|
+
delta->new_file.path = git_pool_strdup(pool, d->new_file.path);
|
|
28
|
+
if (delta->new_file.path == NULL)
|
|
29
|
+
goto fail;
|
|
30
|
+
} else {
|
|
31
|
+
delta->new_file.path = delta->old_file.path;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return delta;
|
|
35
|
+
|
|
36
|
+
fail:
|
|
37
|
+
git__free(delta);
|
|
38
|
+
return NULL;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static git_diff_delta *diff_delta__merge_like_cgit(
|
|
42
|
+
const git_diff_delta *a, const git_diff_delta *b, git_pool *pool)
|
|
43
|
+
{
|
|
44
|
+
git_diff_delta *dup;
|
|
45
|
+
|
|
46
|
+
/* Emulate C git for merging two diffs (a la 'git diff <sha>').
|
|
47
|
+
*
|
|
48
|
+
* When C git does a diff between the work dir and a tree, it actually
|
|
49
|
+
* diffs with the index but uses the workdir contents. This emulates
|
|
50
|
+
* those choices so we can emulate the type of diff.
|
|
51
|
+
*
|
|
52
|
+
* We have three file descriptions here, let's call them:
|
|
53
|
+
* f1 = a->old_file
|
|
54
|
+
* f2 = a->new_file AND b->old_file
|
|
55
|
+
* f3 = b->new_file
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/* if f2 == f3 or f2 is deleted, then just dup the 'a' diff */
|
|
59
|
+
if (b->status == GIT_DELTA_UNMODIFIED || a->status == GIT_DELTA_DELETED)
|
|
60
|
+
return diff_delta__dup(a, pool);
|
|
61
|
+
|
|
62
|
+
/* otherwise, base this diff on the 'b' diff */
|
|
63
|
+
if ((dup = diff_delta__dup(b, pool)) == NULL)
|
|
64
|
+
return NULL;
|
|
65
|
+
|
|
66
|
+
/* If 'a' status is uninteresting, then we're done */
|
|
67
|
+
if (a->status == GIT_DELTA_UNMODIFIED)
|
|
68
|
+
return dup;
|
|
69
|
+
|
|
70
|
+
assert(a->status != GIT_DELTA_UNMODIFIED);
|
|
71
|
+
assert(b->status != GIT_DELTA_UNMODIFIED);
|
|
72
|
+
|
|
73
|
+
/* A cgit exception is that the diff of a file that is only in the
|
|
74
|
+
* index (i.e. not in HEAD nor workdir) is given as empty.
|
|
75
|
+
*/
|
|
76
|
+
if (dup->status == GIT_DELTA_DELETED) {
|
|
77
|
+
if (a->status == GIT_DELTA_ADDED)
|
|
78
|
+
dup->status = GIT_DELTA_UNMODIFIED;
|
|
79
|
+
/* else don't overwrite DELETE status */
|
|
80
|
+
} else {
|
|
81
|
+
dup->status = a->status;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
git_oid_cpy(&dup->old_file.oid, &a->old_file.oid);
|
|
85
|
+
dup->old_file.mode = a->old_file.mode;
|
|
86
|
+
dup->old_file.size = a->old_file.size;
|
|
87
|
+
dup->old_file.flags = a->old_file.flags;
|
|
88
|
+
|
|
89
|
+
return dup;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
int git_diff_merge(
|
|
93
|
+
git_diff_list *onto,
|
|
94
|
+
const git_diff_list *from)
|
|
95
|
+
{
|
|
96
|
+
int error = 0;
|
|
97
|
+
git_pool onto_pool;
|
|
98
|
+
git_vector onto_new;
|
|
99
|
+
git_diff_delta *delta;
|
|
100
|
+
bool ignore_case = false;
|
|
101
|
+
unsigned int i, j;
|
|
102
|
+
|
|
103
|
+
assert(onto && from);
|
|
104
|
+
|
|
105
|
+
if (!from->deltas.length)
|
|
106
|
+
return 0;
|
|
107
|
+
|
|
108
|
+
if (git_vector_init(
|
|
109
|
+
&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
|
|
110
|
+
git_pool_init(&onto_pool, 1, 0) < 0)
|
|
111
|
+
return -1;
|
|
112
|
+
|
|
113
|
+
if ((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 ||
|
|
114
|
+
(from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0)
|
|
115
|
+
{
|
|
116
|
+
ignore_case = true;
|
|
117
|
+
|
|
118
|
+
/* This function currently only supports merging diff lists that
|
|
119
|
+
* are sorted identically. */
|
|
120
|
+
assert((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 &&
|
|
121
|
+
(from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
|
|
125
|
+
git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i);
|
|
126
|
+
const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j);
|
|
127
|
+
int cmp = !f ? -1 : !o ? 1 : STRCMP_CASESELECT(ignore_case, o->old_file.path, f->old_file.path);
|
|
128
|
+
|
|
129
|
+
if (cmp < 0) {
|
|
130
|
+
delta = diff_delta__dup(o, &onto_pool);
|
|
131
|
+
i++;
|
|
132
|
+
} else if (cmp > 0) {
|
|
133
|
+
delta = diff_delta__dup(f, &onto_pool);
|
|
134
|
+
j++;
|
|
135
|
+
} else {
|
|
136
|
+
delta = diff_delta__merge_like_cgit(o, f, &onto_pool);
|
|
137
|
+
i++;
|
|
138
|
+
j++;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* the ignore rules for the target may not match the source
|
|
142
|
+
* or the result of a merged delta could be skippable...
|
|
143
|
+
*/
|
|
144
|
+
if (git_diff_delta__should_skip(&onto->opts, delta)) {
|
|
145
|
+
git__free(delta);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if ((error = !delta ? -1 : git_vector_insert(&onto_new, delta)) < 0)
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!error) {
|
|
154
|
+
git_vector_swap(&onto->deltas, &onto_new);
|
|
155
|
+
git_pool_swap(&onto->pool, &onto_pool);
|
|
156
|
+
onto->new_src = from->new_src;
|
|
157
|
+
|
|
158
|
+
/* prefix strings also come from old pool, so recreate those.*/
|
|
159
|
+
onto->opts.old_prefix =
|
|
160
|
+
git_pool_strdup_safe(&onto->pool, onto->opts.old_prefix);
|
|
161
|
+
onto->opts.new_prefix =
|
|
162
|
+
git_pool_strdup_safe(&onto->pool, onto->opts.new_prefix);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
git_vector_foreach(&onto_new, i, delta)
|
|
166
|
+
git__free(delta);
|
|
167
|
+
git_vector_free(&onto_new);
|
|
168
|
+
git_pool_clear(&onto_pool);
|
|
169
|
+
|
|
170
|
+
return error;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static int find_similar__hashsig_for_file(
|
|
174
|
+
void **out, const git_diff_file *f, const char *path, void *p)
|
|
175
|
+
{
|
|
176
|
+
git_hashsig_option_t opt = (git_hashsig_option_t)p;
|
|
177
|
+
int error = 0;
|
|
178
|
+
|
|
179
|
+
GIT_UNUSED(f);
|
|
180
|
+
error = git_hashsig_create_fromfile((git_hashsig **)out, path, opt);
|
|
181
|
+
|
|
182
|
+
if (error == GIT_EBUFS) {
|
|
183
|
+
error = 0;
|
|
184
|
+
giterr_clear();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return error;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static int find_similar__hashsig_for_buf(
|
|
191
|
+
void **out, const git_diff_file *f, const char *buf, size_t len, void *p)
|
|
192
|
+
{
|
|
193
|
+
git_hashsig_option_t opt = (git_hashsig_option_t)p;
|
|
194
|
+
int error = 0;
|
|
195
|
+
|
|
196
|
+
GIT_UNUSED(f);
|
|
197
|
+
error = git_hashsig_create((git_hashsig **)out, buf, len, opt);
|
|
198
|
+
|
|
199
|
+
if (error == GIT_EBUFS) {
|
|
200
|
+
error = 0;
|
|
201
|
+
giterr_clear();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return error;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static void find_similar__hashsig_free(void *sig, void *payload)
|
|
208
|
+
{
|
|
209
|
+
GIT_UNUSED(payload);
|
|
210
|
+
git_hashsig_free(sig);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static int find_similar__calc_similarity(
|
|
214
|
+
int *score, void *siga, void *sigb, void *payload)
|
|
215
|
+
{
|
|
216
|
+
GIT_UNUSED(payload);
|
|
217
|
+
*score = git_hashsig_compare(siga, sigb);
|
|
218
|
+
return 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
#define DEFAULT_THRESHOLD 50
|
|
222
|
+
#define DEFAULT_BREAK_REWRITE_THRESHOLD 60
|
|
223
|
+
#define DEFAULT_TARGET_LIMIT 200
|
|
224
|
+
|
|
225
|
+
static int normalize_find_opts(
|
|
226
|
+
git_diff_list *diff,
|
|
227
|
+
git_diff_find_options *opts,
|
|
228
|
+
git_diff_find_options *given)
|
|
229
|
+
{
|
|
230
|
+
git_config *cfg = NULL;
|
|
231
|
+
|
|
232
|
+
if (diff->repo != NULL &&
|
|
233
|
+
git_repository_config__weakptr(&cfg, diff->repo) < 0)
|
|
234
|
+
return -1;
|
|
235
|
+
|
|
236
|
+
if (given != NULL)
|
|
237
|
+
memcpy(opts, given, sizeof(*opts));
|
|
238
|
+
else {
|
|
239
|
+
const char *val = NULL;
|
|
240
|
+
|
|
241
|
+
GIT_INIT_STRUCTURE(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
|
|
242
|
+
|
|
243
|
+
opts->flags = GIT_DIFF_FIND_RENAMES;
|
|
244
|
+
|
|
245
|
+
if (git_config_get_string(&val, cfg, "diff.renames") < 0)
|
|
246
|
+
giterr_clear();
|
|
247
|
+
else if (val &&
|
|
248
|
+
(!strcasecmp(val, "copies") || !strcasecmp(val, "copy")))
|
|
249
|
+
opts->flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
GITERR_CHECK_VERSION(opts, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options");
|
|
253
|
+
|
|
254
|
+
/* some flags imply others */
|
|
255
|
+
|
|
256
|
+
if (opts->flags & GIT_DIFF_FIND_RENAMES_FROM_REWRITES)
|
|
257
|
+
opts->flags |= GIT_DIFF_FIND_RENAMES;
|
|
258
|
+
|
|
259
|
+
if (opts->flags & GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED)
|
|
260
|
+
opts->flags |= GIT_DIFF_FIND_COPIES;
|
|
261
|
+
|
|
262
|
+
#define USE_DEFAULT(X) ((X) == 0 || (X) > 100)
|
|
263
|
+
|
|
264
|
+
if (USE_DEFAULT(opts->rename_threshold))
|
|
265
|
+
opts->rename_threshold = DEFAULT_THRESHOLD;
|
|
266
|
+
|
|
267
|
+
if (USE_DEFAULT(opts->rename_from_rewrite_threshold))
|
|
268
|
+
opts->rename_from_rewrite_threshold = DEFAULT_THRESHOLD;
|
|
269
|
+
|
|
270
|
+
if (USE_DEFAULT(opts->copy_threshold))
|
|
271
|
+
opts->copy_threshold = DEFAULT_THRESHOLD;
|
|
272
|
+
|
|
273
|
+
if (USE_DEFAULT(opts->break_rewrite_threshold))
|
|
274
|
+
opts->break_rewrite_threshold = DEFAULT_BREAK_REWRITE_THRESHOLD;
|
|
275
|
+
|
|
276
|
+
#undef USE_DEFAULT
|
|
277
|
+
|
|
278
|
+
if (!opts->target_limit) {
|
|
279
|
+
int32_t limit = 0;
|
|
280
|
+
|
|
281
|
+
opts->target_limit = DEFAULT_TARGET_LIMIT;
|
|
282
|
+
|
|
283
|
+
if (git_config_get_int32(&limit, cfg, "diff.renameLimit") < 0)
|
|
284
|
+
giterr_clear();
|
|
285
|
+
else if (limit > 0)
|
|
286
|
+
opts->target_limit = limit;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/* assign the internal metric with whitespace flag as payload */
|
|
290
|
+
if (!opts->metric) {
|
|
291
|
+
opts->metric = git__malloc(sizeof(git_diff_similarity_metric));
|
|
292
|
+
GITERR_CHECK_ALLOC(opts->metric);
|
|
293
|
+
|
|
294
|
+
opts->metric->file_signature = find_similar__hashsig_for_file;
|
|
295
|
+
opts->metric->buffer_signature = find_similar__hashsig_for_buf;
|
|
296
|
+
opts->metric->free_signature = find_similar__hashsig_free;
|
|
297
|
+
opts->metric->similarity = find_similar__calc_similarity;
|
|
298
|
+
|
|
299
|
+
if (opts->flags & GIT_DIFF_FIND_IGNORE_WHITESPACE)
|
|
300
|
+
opts->metric->payload = (void *)GIT_HASHSIG_IGNORE_WHITESPACE;
|
|
301
|
+
else if (opts->flags & GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE)
|
|
302
|
+
opts->metric->payload = (void *)GIT_HASHSIG_NORMAL;
|
|
303
|
+
else
|
|
304
|
+
opts->metric->payload = (void *)GIT_HASHSIG_SMART_WHITESPACE;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
|
|
311
|
+
{
|
|
312
|
+
git_vector onto = GIT_VECTOR_INIT;
|
|
313
|
+
size_t i;
|
|
314
|
+
git_diff_delta *delta;
|
|
315
|
+
|
|
316
|
+
if (git_vector_init(&onto, expected_size, git_diff_delta__cmp) < 0)
|
|
317
|
+
return -1;
|
|
318
|
+
|
|
319
|
+
/* build new delta list without TO_DELETE and splitting TO_SPLIT */
|
|
320
|
+
git_vector_foreach(&diff->deltas, i, delta) {
|
|
321
|
+
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
|
|
322
|
+
continue;
|
|
323
|
+
|
|
324
|
+
if ((delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0) {
|
|
325
|
+
git_diff_delta *deleted = diff_delta__dup(delta, &diff->pool);
|
|
326
|
+
if (!deleted)
|
|
327
|
+
goto on_error;
|
|
328
|
+
|
|
329
|
+
deleted->status = GIT_DELTA_DELETED;
|
|
330
|
+
memset(&deleted->new_file, 0, sizeof(deleted->new_file));
|
|
331
|
+
deleted->new_file.path = deleted->old_file.path;
|
|
332
|
+
deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
|
333
|
+
|
|
334
|
+
if (git_vector_insert(&onto, deleted) < 0)
|
|
335
|
+
goto on_error;
|
|
336
|
+
|
|
337
|
+
delta->status = GIT_DELTA_ADDED;
|
|
338
|
+
memset(&delta->old_file, 0, sizeof(delta->old_file));
|
|
339
|
+
delta->old_file.path = delta->new_file.path;
|
|
340
|
+
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (git_vector_insert(&onto, delta) < 0)
|
|
344
|
+
goto on_error;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/* cannot return an error past this point */
|
|
348
|
+
git_vector_foreach(&diff->deltas, i, delta)
|
|
349
|
+
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
|
|
350
|
+
git__free(delta);
|
|
351
|
+
|
|
352
|
+
/* swap new delta list into place */
|
|
353
|
+
git_vector_sort(&onto);
|
|
354
|
+
git_vector_swap(&diff->deltas, &onto);
|
|
355
|
+
git_vector_free(&onto);
|
|
356
|
+
|
|
357
|
+
return 0;
|
|
358
|
+
|
|
359
|
+
on_error:
|
|
360
|
+
git_vector_foreach(&onto, i, delta)
|
|
361
|
+
git__free(delta);
|
|
362
|
+
|
|
363
|
+
git_vector_free(&onto);
|
|
364
|
+
|
|
365
|
+
return -1;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
GIT_INLINE(git_diff_file *) similarity_get_file(git_diff_list *diff, size_t idx)
|
|
369
|
+
{
|
|
370
|
+
git_diff_delta *delta = git_vector_get(&diff->deltas, idx / 2);
|
|
371
|
+
return (idx & 1) ? &delta->new_file : &delta->old_file;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
static int similarity_calc(
|
|
375
|
+
git_diff_list *diff,
|
|
376
|
+
git_diff_find_options *opts,
|
|
377
|
+
size_t file_idx,
|
|
378
|
+
void **cache)
|
|
379
|
+
{
|
|
380
|
+
int error = 0;
|
|
381
|
+
git_diff_file *file = similarity_get_file(diff, file_idx);
|
|
382
|
+
git_iterator_type_t src = (file_idx & 1) ? diff->old_src : diff->new_src;
|
|
383
|
+
|
|
384
|
+
if (src == GIT_ITERATOR_TYPE_WORKDIR) { /* compute hashsig from file */
|
|
385
|
+
git_buf path = GIT_BUF_INIT;
|
|
386
|
+
|
|
387
|
+
/* TODO: apply wd-to-odb filters to file data if necessary */
|
|
388
|
+
|
|
389
|
+
if (!(error = git_buf_joinpath(
|
|
390
|
+
&path, git_repository_workdir(diff->repo), file->path)))
|
|
391
|
+
error = opts->metric->file_signature(
|
|
392
|
+
&cache[file_idx], file, path.ptr, opts->metric->payload);
|
|
393
|
+
|
|
394
|
+
git_buf_free(&path);
|
|
395
|
+
} else { /* compute hashsig from blob buffer */
|
|
396
|
+
git_blob *blob = NULL;
|
|
397
|
+
git_off_t blobsize;
|
|
398
|
+
|
|
399
|
+
/* TODO: add max size threshold a la diff? */
|
|
400
|
+
|
|
401
|
+
if ((error = git_blob_lookup(&blob, diff->repo, &file->oid)) < 0)
|
|
402
|
+
return error;
|
|
403
|
+
|
|
404
|
+
blobsize = git_blob_rawsize(blob);
|
|
405
|
+
if (!git__is_sizet(blobsize)) /* ? what to do ? */
|
|
406
|
+
blobsize = (size_t)-1;
|
|
407
|
+
|
|
408
|
+
error = opts->metric->buffer_signature(
|
|
409
|
+
&cache[file_idx], file, git_blob_rawcontent(blob),
|
|
410
|
+
(size_t)blobsize, opts->metric->payload);
|
|
411
|
+
|
|
412
|
+
git_blob_free(blob);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return error;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
static int similarity_measure(
|
|
419
|
+
git_diff_list *diff,
|
|
420
|
+
git_diff_find_options *opts,
|
|
421
|
+
void **cache,
|
|
422
|
+
size_t a_idx,
|
|
423
|
+
size_t b_idx)
|
|
424
|
+
{
|
|
425
|
+
int score = 0;
|
|
426
|
+
git_diff_file *a_file = similarity_get_file(diff, a_idx);
|
|
427
|
+
git_diff_file *b_file = similarity_get_file(diff, b_idx);
|
|
428
|
+
|
|
429
|
+
if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode))
|
|
430
|
+
return 0;
|
|
431
|
+
|
|
432
|
+
if (git_oid_cmp(&a_file->oid, &b_file->oid) == 0)
|
|
433
|
+
return 100;
|
|
434
|
+
|
|
435
|
+
/* update signature cache if needed */
|
|
436
|
+
if (!cache[a_idx] && similarity_calc(diff, opts, a_idx, cache) < 0)
|
|
437
|
+
return -1;
|
|
438
|
+
if (!cache[b_idx] && similarity_calc(diff, opts, b_idx, cache) < 0)
|
|
439
|
+
return -1;
|
|
440
|
+
|
|
441
|
+
/* some metrics may not wish to process this file (too big / too small) */
|
|
442
|
+
if (!cache[a_idx] || !cache[b_idx])
|
|
443
|
+
return 0;
|
|
444
|
+
|
|
445
|
+
/* compare signatures */
|
|
446
|
+
if (opts->metric->similarity(
|
|
447
|
+
&score, cache[a_idx], cache[b_idx], opts->metric->payload) < 0)
|
|
448
|
+
return -1;
|
|
449
|
+
|
|
450
|
+
/* clip score */
|
|
451
|
+
if (score < 0)
|
|
452
|
+
score = 0;
|
|
453
|
+
else if (score > 100)
|
|
454
|
+
score = 100;
|
|
455
|
+
|
|
456
|
+
return score;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
#define FLAG_SET(opts,flag_name) ((opts.flags & flag_name) != 0)
|
|
460
|
+
|
|
461
|
+
int git_diff_find_similar(
|
|
462
|
+
git_diff_list *diff,
|
|
463
|
+
git_diff_find_options *given_opts)
|
|
464
|
+
{
|
|
465
|
+
size_t i, j, cache_size, *matches;
|
|
466
|
+
int error = 0, similarity;
|
|
467
|
+
git_diff_delta *from, *to;
|
|
468
|
+
git_diff_find_options opts;
|
|
469
|
+
size_t tried_targets, num_rewrites = 0;
|
|
470
|
+
void **cache;
|
|
471
|
+
|
|
472
|
+
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
|
|
473
|
+
return error;
|
|
474
|
+
|
|
475
|
+
/* TODO: maybe abort if deltas.length > target_limit ??? */
|
|
476
|
+
|
|
477
|
+
cache_size = diff->deltas.length * 2; /* must store b/c length may change */
|
|
478
|
+
cache = git__calloc(cache_size, sizeof(void *));
|
|
479
|
+
GITERR_CHECK_ALLOC(cache);
|
|
480
|
+
|
|
481
|
+
matches = git__calloc(diff->deltas.length, sizeof(size_t));
|
|
482
|
+
GITERR_CHECK_ALLOC(matches);
|
|
483
|
+
|
|
484
|
+
/* first break MODIFIED records that are too different (if requested) */
|
|
485
|
+
|
|
486
|
+
if (FLAG_SET(opts, GIT_DIFF_FIND_AND_BREAK_REWRITES)) {
|
|
487
|
+
git_vector_foreach(&diff->deltas, i, from) {
|
|
488
|
+
if (from->status != GIT_DELTA_MODIFIED)
|
|
489
|
+
continue;
|
|
490
|
+
|
|
491
|
+
similarity = similarity_measure(
|
|
492
|
+
diff, &opts, cache, 2 * i, 2 * i + 1);
|
|
493
|
+
|
|
494
|
+
if (similarity < 0) {
|
|
495
|
+
error = similarity;
|
|
496
|
+
goto cleanup;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if ((unsigned int)similarity < opts.break_rewrite_threshold) {
|
|
500
|
+
from->flags |= GIT_DIFF_FLAG__TO_SPLIT;
|
|
501
|
+
num_rewrites++;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/* next find the most similar delta for each rename / copy candidate */
|
|
507
|
+
|
|
508
|
+
git_vector_foreach(&diff->deltas, i, from) {
|
|
509
|
+
tried_targets = 0;
|
|
510
|
+
|
|
511
|
+
/* skip things that aren't blobs */
|
|
512
|
+
if (GIT_MODE_TYPE(from->old_file.mode) !=
|
|
513
|
+
GIT_MODE_TYPE(GIT_FILEMODE_BLOB))
|
|
514
|
+
continue;
|
|
515
|
+
|
|
516
|
+
/* don't check UNMODIFIED files as source unless given option */
|
|
517
|
+
if (from->status == GIT_DELTA_UNMODIFIED &&
|
|
518
|
+
!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED))
|
|
519
|
+
continue;
|
|
520
|
+
|
|
521
|
+
/* skip all but DELETED files unless copy detection is on */
|
|
522
|
+
if (!FLAG_SET(opts, GIT_DIFF_FIND_COPIES) &&
|
|
523
|
+
from->status != GIT_DELTA_DELETED &&
|
|
524
|
+
(from->flags & GIT_DIFF_FLAG__TO_SPLIT) == 0)
|
|
525
|
+
continue;
|
|
526
|
+
|
|
527
|
+
git_vector_foreach(&diff->deltas, j, to) {
|
|
528
|
+
if (i == j)
|
|
529
|
+
continue;
|
|
530
|
+
|
|
531
|
+
/* skip things that aren't blobs */
|
|
532
|
+
if (GIT_MODE_TYPE(to->new_file.mode) !=
|
|
533
|
+
GIT_MODE_TYPE(GIT_FILEMODE_BLOB))
|
|
534
|
+
continue;
|
|
535
|
+
|
|
536
|
+
switch (to->status) {
|
|
537
|
+
case GIT_DELTA_ADDED:
|
|
538
|
+
case GIT_DELTA_UNTRACKED:
|
|
539
|
+
case GIT_DELTA_RENAMED:
|
|
540
|
+
case GIT_DELTA_COPIED:
|
|
541
|
+
break;
|
|
542
|
+
case GIT_DELTA_MODIFIED:
|
|
543
|
+
if ((to->flags & GIT_DIFF_FLAG__TO_SPLIT) == 0)
|
|
544
|
+
continue;
|
|
545
|
+
break;
|
|
546
|
+
default:
|
|
547
|
+
/* only the above status values should be checked */
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/* cap on maximum files we'll examine (per "from" file) */
|
|
552
|
+
if (++tried_targets > opts.target_limit)
|
|
553
|
+
break;
|
|
554
|
+
|
|
555
|
+
/* calculate similarity and see if this pair beats the
|
|
556
|
+
* similarity score of the current best pair.
|
|
557
|
+
*/
|
|
558
|
+
similarity = similarity_measure(
|
|
559
|
+
diff, &opts, cache, 2 * i, 2 * j + 1);
|
|
560
|
+
|
|
561
|
+
if (similarity < 0) {
|
|
562
|
+
error = similarity;
|
|
563
|
+
goto cleanup;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (to->similarity < (unsigned int)similarity) {
|
|
567
|
+
to->similarity = (unsigned int)similarity;
|
|
568
|
+
matches[j] = i + 1;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/* next rewrite the diffs with renames / copies */
|
|
574
|
+
|
|
575
|
+
git_vector_foreach(&diff->deltas, j, to) {
|
|
576
|
+
if (!matches[j]) {
|
|
577
|
+
assert(to->similarity == 0);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
i = matches[j] - 1;
|
|
582
|
+
from = GIT_VECTOR_GET(&diff->deltas, i);
|
|
583
|
+
assert(from);
|
|
584
|
+
|
|
585
|
+
/* four possible outcomes here:
|
|
586
|
+
* 1. old DELETED and if over rename threshold,
|
|
587
|
+
* new becomes RENAMED and old goes away
|
|
588
|
+
* 2. old SPLIT and if over rename threshold,
|
|
589
|
+
* new becomes RENAMED and old becomes ADDED (clear SPLIT)
|
|
590
|
+
* 3. old was MODIFIED but FIND_RENAMES_FROM_REWRITES is on and
|
|
591
|
+
* old is more similar to new than it is to itself, in which
|
|
592
|
+
* case, new becomes RENAMED and old becomed ADDED
|
|
593
|
+
* 4. otherwise if over copy threshold, new becomes COPIED
|
|
594
|
+
*/
|
|
595
|
+
|
|
596
|
+
if (from->status == GIT_DELTA_DELETED) {
|
|
597
|
+
if (to->similarity < opts.rename_threshold) {
|
|
598
|
+
to->similarity = 0;
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
to->status = GIT_DELTA_RENAMED;
|
|
603
|
+
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
|
604
|
+
|
|
605
|
+
from->flags |= GIT_DIFF_FLAG__TO_DELETE;
|
|
606
|
+
num_rewrites++;
|
|
607
|
+
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (from->status == GIT_DELTA_MODIFIED &&
|
|
612
|
+
(from->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0)
|
|
613
|
+
{
|
|
614
|
+
if (to->similarity < opts.rename_threshold) {
|
|
615
|
+
to->similarity = 0;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
to->status = GIT_DELTA_RENAMED;
|
|
620
|
+
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
|
621
|
+
|
|
622
|
+
from->status = GIT_DELTA_ADDED;
|
|
623
|
+
from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
|
624
|
+
memset(&from->old_file, 0, sizeof(from->old_file));
|
|
625
|
+
num_rewrites--;
|
|
626
|
+
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (from->status == GIT_DELTA_MODIFIED &&
|
|
631
|
+
FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES) &&
|
|
632
|
+
to->similarity > opts.rename_threshold)
|
|
633
|
+
{
|
|
634
|
+
similarity = similarity_measure(
|
|
635
|
+
diff, &opts, cache, 2 * i, 2 * i + 1);
|
|
636
|
+
|
|
637
|
+
if (similarity < 0) {
|
|
638
|
+
error = similarity;
|
|
639
|
+
goto cleanup;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if ((unsigned int)similarity < opts.rename_from_rewrite_threshold) {
|
|
643
|
+
to->status = GIT_DELTA_RENAMED;
|
|
644
|
+
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
|
645
|
+
|
|
646
|
+
from->status = GIT_DELTA_ADDED;
|
|
647
|
+
memset(&from->old_file, 0, sizeof(from->old_file));
|
|
648
|
+
from->old_file.path = to->old_file.path;
|
|
649
|
+
from->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
|
650
|
+
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
if (to->similarity < opts.copy_threshold) {
|
|
656
|
+
to->similarity = 0;
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/* convert "to" to a COPIED record */
|
|
661
|
+
to->status = GIT_DELTA_COPIED;
|
|
662
|
+
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (num_rewrites > 0) {
|
|
666
|
+
assert(num_rewrites < diff->deltas.length);
|
|
667
|
+
|
|
668
|
+
error = apply_splits_and_deletes(
|
|
669
|
+
diff, diff->deltas.length - num_rewrites);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
cleanup:
|
|
673
|
+
git__free(matches);
|
|
674
|
+
|
|
675
|
+
for (i = 0; i < cache_size; ++i) {
|
|
676
|
+
if (cache[i] != NULL)
|
|
677
|
+
opts.metric->free_signature(cache[i], opts.metric->payload);
|
|
678
|
+
}
|
|
679
|
+
git__free(cache);
|
|
680
|
+
|
|
681
|
+
if (!given_opts || !given_opts->metric)
|
|
682
|
+
git__free(opts.metric);
|
|
683
|
+
|
|
684
|
+
return error;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
#undef FLAG_SET
|