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
@@ -5,10 +5,14 @@
|
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
6
6
|
*/
|
7
7
|
#include "common.h"
|
8
|
-
|
8
|
+
|
9
9
|
#include "git2/config.h"
|
10
10
|
#include "git2/blob.h"
|
11
|
+
|
12
|
+
#include "diff.h"
|
11
13
|
#include "hashsig.h"
|
14
|
+
#include "path.h"
|
15
|
+
#include "fileops.h"
|
12
16
|
|
13
17
|
static git_diff_delta *diff_delta__dup(
|
14
18
|
const git_diff_delta *d, git_pool *pool)
|
@@ -18,12 +22,15 @@ static git_diff_delta *diff_delta__dup(
|
|
18
22
|
return NULL;
|
19
23
|
|
20
24
|
memcpy(delta, d, sizeof(git_diff_delta));
|
25
|
+
GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags);
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
if (d->old_file.path != NULL) {
|
28
|
+
delta->old_file.path = git_pool_strdup(pool, d->old_file.path);
|
29
|
+
if (delta->old_file.path == NULL)
|
30
|
+
goto fail;
|
31
|
+
}
|
25
32
|
|
26
|
-
if (d->new_file.path != d->old_file.path) {
|
33
|
+
if (d->new_file.path != d->old_file.path && d->new_file.path != NULL) {
|
27
34
|
delta->new_file.path = git_pool_strdup(pool, d->new_file.path);
|
28
35
|
if (delta->new_file.path == NULL)
|
29
36
|
goto fail;
|
@@ -170,7 +177,7 @@ int git_diff_merge(
|
|
170
177
|
return error;
|
171
178
|
}
|
172
179
|
|
173
|
-
|
180
|
+
int git_diff_find_similar__hashsig_for_file(
|
174
181
|
void **out, const git_diff_file *f, const char *path, void *p)
|
175
182
|
{
|
176
183
|
git_hashsig_option_t opt = (git_hashsig_option_t)p;
|
@@ -178,7 +185,7 @@ static int find_similar__hashsig_for_file(
|
|
178
185
|
|
179
186
|
GIT_UNUSED(f);
|
180
187
|
error = git_hashsig_create_fromfile((git_hashsig **)out, path, opt);
|
181
|
-
|
188
|
+
|
182
189
|
if (error == GIT_EBUFS) {
|
183
190
|
error = 0;
|
184
191
|
giterr_clear();
|
@@ -187,15 +194,15 @@ static int find_similar__hashsig_for_file(
|
|
187
194
|
return error;
|
188
195
|
}
|
189
196
|
|
190
|
-
|
197
|
+
int git_diff_find_similar__hashsig_for_buf(
|
191
198
|
void **out, const git_diff_file *f, const char *buf, size_t len, void *p)
|
192
199
|
{
|
193
200
|
git_hashsig_option_t opt = (git_hashsig_option_t)p;
|
194
201
|
int error = 0;
|
195
|
-
|
202
|
+
|
196
203
|
GIT_UNUSED(f);
|
197
204
|
error = git_hashsig_create((git_hashsig **)out, buf, len, opt);
|
198
|
-
|
205
|
+
|
199
206
|
if (error == GIT_EBUFS) {
|
200
207
|
error = 0;
|
201
208
|
giterr_clear();
|
@@ -204,13 +211,13 @@ static int find_similar__hashsig_for_buf(
|
|
204
211
|
return error;
|
205
212
|
}
|
206
213
|
|
207
|
-
|
214
|
+
void git_diff_find_similar__hashsig_free(void *sig, void *payload)
|
208
215
|
{
|
209
216
|
GIT_UNUSED(payload);
|
210
217
|
git_hashsig_free(sig);
|
211
218
|
}
|
212
219
|
|
213
|
-
|
220
|
+
int git_diff_find_similar__calc_similarity(
|
214
221
|
int *score, void *siga, void *sigb, void *payload)
|
215
222
|
{
|
216
223
|
GIT_UNUSED(payload);
|
@@ -220,7 +227,7 @@ static int find_similar__calc_similarity(
|
|
220
227
|
|
221
228
|
#define DEFAULT_THRESHOLD 50
|
222
229
|
#define DEFAULT_BREAK_REWRITE_THRESHOLD 60
|
223
|
-
#define
|
230
|
+
#define DEFAULT_RENAME_LIMIT 200
|
224
231
|
|
225
232
|
static int normalize_find_opts(
|
226
233
|
git_diff_list *diff,
|
@@ -253,12 +260,25 @@ static int normalize_find_opts(
|
|
253
260
|
|
254
261
|
/* some flags imply others */
|
255
262
|
|
263
|
+
if (opts->flags & GIT_DIFF_FIND_EXACT_MATCH_ONLY) {
|
264
|
+
/* if we are only looking for exact matches, then don't turn
|
265
|
+
* MODIFIED items into ADD/DELETE pairs because it's too picky
|
266
|
+
*/
|
267
|
+
opts->flags &= ~(GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES);
|
268
|
+
|
269
|
+
/* similarly, don't look for self-rewrites to split */
|
270
|
+
opts->flags &= ~GIT_DIFF_FIND_RENAMES_FROM_REWRITES;
|
271
|
+
}
|
272
|
+
|
256
273
|
if (opts->flags & GIT_DIFF_FIND_RENAMES_FROM_REWRITES)
|
257
274
|
opts->flags |= GIT_DIFF_FIND_RENAMES;
|
258
275
|
|
259
276
|
if (opts->flags & GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED)
|
260
277
|
opts->flags |= GIT_DIFF_FIND_COPIES;
|
261
278
|
|
279
|
+
if (opts->flags & GIT_DIFF_BREAK_REWRITES)
|
280
|
+
opts->flags |= GIT_DIFF_FIND_REWRITES;
|
281
|
+
|
262
282
|
#define USE_DEFAULT(X) ((X) == 0 || (X) > 100)
|
263
283
|
|
264
284
|
if (USE_DEFAULT(opts->rename_threshold))
|
@@ -275,15 +295,15 @@ static int normalize_find_opts(
|
|
275
295
|
|
276
296
|
#undef USE_DEFAULT
|
277
297
|
|
278
|
-
if (!opts->
|
298
|
+
if (!opts->rename_limit) {
|
279
299
|
int32_t limit = 0;
|
280
300
|
|
281
|
-
opts->
|
301
|
+
opts->rename_limit = DEFAULT_RENAME_LIMIT;
|
282
302
|
|
283
303
|
if (git_config_get_int32(&limit, cfg, "diff.renameLimit") < 0)
|
284
304
|
giterr_clear();
|
285
305
|
else if (limit > 0)
|
286
|
-
opts->
|
306
|
+
opts->rename_limit = limit;
|
287
307
|
}
|
288
308
|
|
289
309
|
/* assign the internal metric with whitespace flag as payload */
|
@@ -291,10 +311,10 @@ static int normalize_find_opts(
|
|
291
311
|
opts->metric = git__malloc(sizeof(git_diff_similarity_metric));
|
292
312
|
GITERR_CHECK_ALLOC(opts->metric);
|
293
313
|
|
294
|
-
opts->metric->file_signature =
|
295
|
-
opts->metric->buffer_signature =
|
296
|
-
opts->metric->free_signature =
|
297
|
-
opts->metric->similarity =
|
314
|
+
opts->metric->file_signature = git_diff_find_similar__hashsig_for_file;
|
315
|
+
opts->metric->buffer_signature = git_diff_find_similar__hashsig_for_buf;
|
316
|
+
opts->metric->free_signature = git_diff_find_similar__hashsig_free;
|
317
|
+
opts->metric->similarity = git_diff_find_similar__calc_similarity;
|
298
318
|
|
299
319
|
if (opts->flags & GIT_DIFF_FIND_IGNORE_WHITESPACE)
|
300
320
|
opts->metric->payload = (void *)GIT_HASHSIG_IGNORE_WHITESPACE;
|
@@ -307,11 +327,12 @@ static int normalize_find_opts(
|
|
307
327
|
return 0;
|
308
328
|
}
|
309
329
|
|
310
|
-
static int apply_splits_and_deletes(
|
330
|
+
static int apply_splits_and_deletes(
|
331
|
+
git_diff_list *diff, size_t expected_size, bool actually_split)
|
311
332
|
{
|
312
333
|
git_vector onto = GIT_VECTOR_INIT;
|
313
334
|
size_t i;
|
314
|
-
git_diff_delta *delta;
|
335
|
+
git_diff_delta *delta, *deleted;
|
315
336
|
|
316
337
|
if (git_vector_init(&onto, expected_size, git_diff_delta__cmp) < 0)
|
317
338
|
return -1;
|
@@ -321,9 +342,11 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
|
|
321
342
|
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
|
322
343
|
continue;
|
323
344
|
|
324
|
-
if ((delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0) {
|
325
|
-
|
326
|
-
|
345
|
+
if ((delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0 && actually_split) {
|
346
|
+
delta->similarity = 0;
|
347
|
+
|
348
|
+
/* make new record for DELETED side of split */
|
349
|
+
if (!(deleted = diff_delta__dup(delta, &diff->pool)))
|
327
350
|
goto on_error;
|
328
351
|
|
329
352
|
deleted->status = GIT_DELTA_DELETED;
|
@@ -334,32 +357,46 @@ static int apply_splits_and_deletes(git_diff_list *diff, size_t expected_size)
|
|
334
357
|
if (git_vector_insert(&onto, deleted) < 0)
|
335
358
|
goto on_error;
|
336
359
|
|
337
|
-
|
360
|
+
if (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR)
|
361
|
+
delta->status = GIT_DELTA_UNTRACKED;
|
362
|
+
else
|
363
|
+
delta->status = GIT_DELTA_ADDED;
|
338
364
|
memset(&delta->old_file, 0, sizeof(delta->old_file));
|
339
365
|
delta->old_file.path = delta->new_file.path;
|
340
366
|
delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
341
367
|
}
|
342
368
|
|
369
|
+
/* clean up delta before inserting into new list */
|
370
|
+
GIT_DIFF_FLAG__CLEAR_INTERNAL(delta->flags);
|
371
|
+
|
372
|
+
if (delta->status != GIT_DELTA_COPIED &&
|
373
|
+
delta->status != GIT_DELTA_RENAMED &&
|
374
|
+
(delta->status != GIT_DELTA_MODIFIED || actually_split))
|
375
|
+
delta->similarity = 0;
|
376
|
+
|
377
|
+
/* insert into new list */
|
343
378
|
if (git_vector_insert(&onto, delta) < 0)
|
344
379
|
goto on_error;
|
345
380
|
}
|
346
381
|
|
347
382
|
/* cannot return an error past this point */
|
348
|
-
|
383
|
+
|
384
|
+
/* free deltas from old list that didn't make it to the new one */
|
385
|
+
git_vector_foreach(&diff->deltas, i, delta) {
|
349
386
|
if ((delta->flags & GIT_DIFF_FLAG__TO_DELETE) != 0)
|
350
387
|
git__free(delta);
|
388
|
+
}
|
351
389
|
|
352
390
|
/* swap new delta list into place */
|
353
|
-
git_vector_sort(&onto);
|
354
391
|
git_vector_swap(&diff->deltas, &onto);
|
355
392
|
git_vector_free(&onto);
|
393
|
+
git_vector_sort(&diff->deltas);
|
356
394
|
|
357
395
|
return 0;
|
358
396
|
|
359
397
|
on_error:
|
360
398
|
git_vector_foreach(&onto, i, delta)
|
361
399
|
git__free(delta);
|
362
|
-
|
363
400
|
git_vector_free(&onto);
|
364
401
|
|
365
402
|
return -1;
|
@@ -373,21 +410,25 @@ GIT_INLINE(git_diff_file *) similarity_get_file(git_diff_list *diff, size_t idx)
|
|
373
410
|
|
374
411
|
static int similarity_calc(
|
375
412
|
git_diff_list *diff,
|
376
|
-
git_diff_find_options *opts,
|
413
|
+
const git_diff_find_options *opts,
|
377
414
|
size_t file_idx,
|
378
415
|
void **cache)
|
379
416
|
{
|
380
417
|
int error = 0;
|
381
418
|
git_diff_file *file = similarity_get_file(diff, file_idx);
|
382
|
-
git_iterator_type_t src = (file_idx & 1) ? diff->
|
419
|
+
git_iterator_type_t src = (file_idx & 1) ? diff->new_src : diff->old_src;
|
383
420
|
|
384
421
|
if (src == GIT_ITERATOR_TYPE_WORKDIR) { /* compute hashsig from file */
|
385
422
|
git_buf path = GIT_BUF_INIT;
|
386
423
|
|
387
424
|
/* TODO: apply wd-to-odb filters to file data if necessary */
|
388
425
|
|
389
|
-
if (
|
390
|
-
|
426
|
+
if ((error = git_buf_joinpath(
|
427
|
+
&path, git_repository_workdir(diff->repo), file->path)) < 0)
|
428
|
+
return error;
|
429
|
+
|
430
|
+
/* if path is not a regular file, just skip this item */
|
431
|
+
if (git_path_isfile(path.ptr))
|
391
432
|
error = opts->metric->file_signature(
|
392
433
|
&cache[file_idx], file, path.ptr, opts->metric->payload);
|
393
434
|
|
@@ -398,8 +439,11 @@ static int similarity_calc(
|
|
398
439
|
|
399
440
|
/* TODO: add max size threshold a la diff? */
|
400
441
|
|
401
|
-
if (
|
402
|
-
|
442
|
+
if (git_blob_lookup(&blob, diff->repo, &file->oid) < 0) {
|
443
|
+
/* if lookup fails, just skip this item in similarity calc */
|
444
|
+
giterr_clear();
|
445
|
+
return 0;
|
446
|
+
}
|
403
447
|
|
404
448
|
blobsize = git_blob_rawsize(blob);
|
405
449
|
if (!git__is_sizet(blobsize)) /* ? what to do ? */
|
@@ -415,268 +459,485 @@ static int similarity_calc(
|
|
415
459
|
return error;
|
416
460
|
}
|
417
461
|
|
462
|
+
#define FLAG_SET(opts,flag_name) (((opts)->flags & flag_name) != 0)
|
463
|
+
|
464
|
+
/* - score < 0 means files cannot be compared
|
465
|
+
* - score >= 100 means files are exact match
|
466
|
+
* - score == 0 means files are completely different
|
467
|
+
*/
|
418
468
|
static int similarity_measure(
|
469
|
+
int *score,
|
419
470
|
git_diff_list *diff,
|
420
|
-
git_diff_find_options *opts,
|
471
|
+
const git_diff_find_options *opts,
|
421
472
|
void **cache,
|
422
473
|
size_t a_idx,
|
423
474
|
size_t b_idx)
|
424
475
|
{
|
425
|
-
int score = 0;
|
426
476
|
git_diff_file *a_file = similarity_get_file(diff, a_idx);
|
427
477
|
git_diff_file *b_file = similarity_get_file(diff, b_idx);
|
478
|
+
bool exact_match = FLAG_SET(opts, GIT_DIFF_FIND_EXACT_MATCH_ONLY);
|
428
479
|
|
480
|
+
*score = -1;
|
481
|
+
|
482
|
+
/* don't try to compare files of different types */
|
429
483
|
if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode))
|
430
484
|
return 0;
|
431
485
|
|
432
|
-
if
|
433
|
-
|
486
|
+
/* if exact match is requested, force calculation of missing OIDs now */
|
487
|
+
if (exact_match) {
|
488
|
+
if (git_oid_iszero(&a_file->oid) &&
|
489
|
+
diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
|
490
|
+
!git_diff__oid_for_file(diff->repo, a_file->path,
|
491
|
+
a_file->mode, a_file->size, &a_file->oid))
|
492
|
+
a_file->flags |= GIT_DIFF_FLAG_VALID_OID;
|
493
|
+
|
494
|
+
if (git_oid_iszero(&b_file->oid) &&
|
495
|
+
diff->new_src == GIT_ITERATOR_TYPE_WORKDIR &&
|
496
|
+
!git_diff__oid_for_file(diff->repo, b_file->path,
|
497
|
+
b_file->mode, b_file->size, &b_file->oid))
|
498
|
+
b_file->flags |= GIT_DIFF_FLAG_VALID_OID;
|
499
|
+
}
|
500
|
+
|
501
|
+
/* check OID match as a quick test */
|
502
|
+
if (git_oid__cmp(&a_file->oid, &b_file->oid) == 0) {
|
503
|
+
*score = 100;
|
504
|
+
return 0;
|
505
|
+
}
|
506
|
+
|
507
|
+
/* don't calculate signatures if we are doing exact match */
|
508
|
+
if (exact_match) {
|
509
|
+
*score = 0;
|
510
|
+
return 0;
|
511
|
+
}
|
434
512
|
|
435
513
|
/* update signature cache if needed */
|
436
514
|
if (!cache[a_idx] && similarity_calc(diff, opts, a_idx, cache) < 0)
|
437
515
|
return -1;
|
438
516
|
if (!cache[b_idx] && similarity_calc(diff, opts, b_idx, cache) < 0)
|
439
517
|
return -1;
|
440
|
-
|
518
|
+
|
441
519
|
/* some metrics may not wish to process this file (too big / too small) */
|
442
520
|
if (!cache[a_idx] || !cache[b_idx])
|
443
521
|
return 0;
|
444
522
|
|
445
523
|
/* compare signatures */
|
446
|
-
|
447
|
-
|
448
|
-
|
524
|
+
return opts->metric->similarity(
|
525
|
+
score, cache[a_idx], cache[b_idx], opts->metric->payload);
|
526
|
+
}
|
527
|
+
|
528
|
+
static int calc_self_similarity(
|
529
|
+
git_diff_list *diff,
|
530
|
+
const git_diff_find_options *opts,
|
531
|
+
size_t delta_idx,
|
532
|
+
void **cache)
|
533
|
+
{
|
534
|
+
int error, similarity = -1;
|
535
|
+
git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx);
|
449
536
|
|
450
|
-
|
451
|
-
|
452
|
-
score = 0;
|
453
|
-
else if (score > 100)
|
454
|
-
score = 100;
|
537
|
+
if ((delta->flags & GIT_DIFF_FLAG__HAS_SELF_SIMILARITY) != 0)
|
538
|
+
return 0;
|
455
539
|
|
456
|
-
|
540
|
+
error = similarity_measure(
|
541
|
+
&similarity, diff, opts, cache, 2 * delta_idx, 2 * delta_idx + 1);
|
542
|
+
if (error < 0)
|
543
|
+
return error;
|
544
|
+
|
545
|
+
if (similarity >= 0) {
|
546
|
+
delta->similarity = (uint32_t)similarity;
|
547
|
+
delta->flags |= GIT_DIFF_FLAG__HAS_SELF_SIMILARITY;
|
548
|
+
}
|
549
|
+
|
550
|
+
return 0;
|
457
551
|
}
|
458
552
|
|
459
|
-
|
553
|
+
static bool is_rename_target(
|
554
|
+
git_diff_list *diff,
|
555
|
+
const git_diff_find_options *opts,
|
556
|
+
size_t delta_idx,
|
557
|
+
void **cache)
|
558
|
+
{
|
559
|
+
git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx);
|
560
|
+
|
561
|
+
/* skip things that aren't plain blobs */
|
562
|
+
if (!GIT_MODE_ISBLOB(delta->new_file.mode))
|
563
|
+
return false;
|
564
|
+
|
565
|
+
/* only consider ADDED, RENAMED, COPIED, and split MODIFIED as
|
566
|
+
* targets; maybe include UNTRACKED and IGNORED if requested.
|
567
|
+
*/
|
568
|
+
switch (delta->status) {
|
569
|
+
case GIT_DELTA_UNMODIFIED:
|
570
|
+
case GIT_DELTA_DELETED:
|
571
|
+
return false;
|
572
|
+
|
573
|
+
case GIT_DELTA_MODIFIED:
|
574
|
+
if (!FLAG_SET(opts, GIT_DIFF_FIND_REWRITES) &&
|
575
|
+
!FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES))
|
576
|
+
return false;
|
577
|
+
|
578
|
+
if (calc_self_similarity(diff, opts, delta_idx, cache) < 0)
|
579
|
+
return false;
|
580
|
+
|
581
|
+
if (FLAG_SET(opts, GIT_DIFF_BREAK_REWRITES) &&
|
582
|
+
delta->similarity < opts->break_rewrite_threshold) {
|
583
|
+
delta->flags |= GIT_DIFF_FLAG__TO_SPLIT;
|
584
|
+
break;
|
585
|
+
}
|
586
|
+
if (FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES) &&
|
587
|
+
delta->similarity < opts->rename_from_rewrite_threshold)
|
588
|
+
break;
|
589
|
+
|
590
|
+
return false;
|
591
|
+
|
592
|
+
case GIT_DELTA_UNTRACKED:
|
593
|
+
case GIT_DELTA_IGNORED:
|
594
|
+
if (!FLAG_SET(opts, GIT_DIFF_FIND_FOR_UNTRACKED))
|
595
|
+
return false;
|
596
|
+
break;
|
597
|
+
|
598
|
+
default: /* all other status values should be checked */
|
599
|
+
break;
|
600
|
+
}
|
601
|
+
|
602
|
+
delta->flags |= GIT_DIFF_FLAG__IS_RENAME_TARGET;
|
603
|
+
return true;
|
604
|
+
}
|
605
|
+
|
606
|
+
static bool is_rename_source(
|
607
|
+
git_diff_list *diff,
|
608
|
+
const git_diff_find_options *opts,
|
609
|
+
size_t delta_idx,
|
610
|
+
void **cache)
|
611
|
+
{
|
612
|
+
git_diff_delta *delta = GIT_VECTOR_GET(&diff->deltas, delta_idx);
|
613
|
+
|
614
|
+
/* skip things that aren't blobs */
|
615
|
+
if (!GIT_MODE_ISBLOB(delta->old_file.mode))
|
616
|
+
return false;
|
617
|
+
|
618
|
+
switch (delta->status) {
|
619
|
+
case GIT_DELTA_ADDED:
|
620
|
+
case GIT_DELTA_UNTRACKED:
|
621
|
+
case GIT_DELTA_IGNORED:
|
622
|
+
return false;
|
623
|
+
|
624
|
+
case GIT_DELTA_DELETED:
|
625
|
+
case GIT_DELTA_TYPECHANGE:
|
626
|
+
break;
|
627
|
+
|
628
|
+
case GIT_DELTA_UNMODIFIED:
|
629
|
+
if (!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED))
|
630
|
+
return false;
|
631
|
+
break;
|
632
|
+
|
633
|
+
default: /* MODIFIED, RENAMED, COPIED */
|
634
|
+
/* if we're finding copies, this could be a source */
|
635
|
+
if (FLAG_SET(opts, GIT_DIFF_FIND_COPIES))
|
636
|
+
break;
|
637
|
+
|
638
|
+
/* otherwise, this is only a source if we can split it */
|
639
|
+
if (!FLAG_SET(opts, GIT_DIFF_FIND_REWRITES) &&
|
640
|
+
!FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES))
|
641
|
+
return false;
|
642
|
+
|
643
|
+
if (calc_self_similarity(diff, opts, delta_idx, cache) < 0)
|
644
|
+
return false;
|
645
|
+
|
646
|
+
if (FLAG_SET(opts, GIT_DIFF_BREAK_REWRITES) &&
|
647
|
+
delta->similarity < opts->break_rewrite_threshold) {
|
648
|
+
delta->flags |= GIT_DIFF_FLAG__TO_SPLIT;
|
649
|
+
break;
|
650
|
+
}
|
651
|
+
|
652
|
+
if (FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES) &&
|
653
|
+
delta->similarity < opts->rename_from_rewrite_threshold)
|
654
|
+
break;
|
655
|
+
|
656
|
+
return false;
|
657
|
+
}
|
658
|
+
|
659
|
+
delta->flags |= GIT_DIFF_FLAG__IS_RENAME_SOURCE;
|
660
|
+
return true;
|
661
|
+
}
|
662
|
+
|
663
|
+
GIT_INLINE(bool) delta_is_split(git_diff_delta *delta)
|
664
|
+
{
|
665
|
+
return (delta->status == GIT_DELTA_TYPECHANGE ||
|
666
|
+
(delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0);
|
667
|
+
}
|
668
|
+
|
669
|
+
GIT_INLINE(bool) delta_is_new_only(git_diff_delta *delta)
|
670
|
+
{
|
671
|
+
return (delta->status == GIT_DELTA_ADDED ||
|
672
|
+
delta->status == GIT_DELTA_UNTRACKED ||
|
673
|
+
delta->status == GIT_DELTA_IGNORED);
|
674
|
+
}
|
675
|
+
|
676
|
+
GIT_INLINE(void) delta_make_rename(
|
677
|
+
git_diff_delta *to, const git_diff_delta *from, uint32_t similarity)
|
678
|
+
{
|
679
|
+
to->status = GIT_DELTA_RENAMED;
|
680
|
+
to->similarity = similarity;
|
681
|
+
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
682
|
+
to->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
683
|
+
}
|
684
|
+
|
685
|
+
typedef struct {
|
686
|
+
uint32_t idx;
|
687
|
+
uint32_t similarity;
|
688
|
+
} diff_find_match;
|
460
689
|
|
461
690
|
int git_diff_find_similar(
|
462
691
|
git_diff_list *diff,
|
463
692
|
git_diff_find_options *given_opts)
|
464
693
|
{
|
465
|
-
size_t i, j,
|
694
|
+
size_t i, j, sigcache_size;
|
466
695
|
int error = 0, similarity;
|
467
696
|
git_diff_delta *from, *to;
|
468
697
|
git_diff_find_options opts;
|
469
|
-
size_t
|
470
|
-
|
698
|
+
size_t num_srcs = 0, num_tgts = 0, tried_srcs = 0, tried_tgts = 0;
|
699
|
+
size_t num_rewrites = 0, num_updates = 0, num_bumped = 0;
|
700
|
+
void **sigcache; /* cache of similarity metric file signatures */
|
701
|
+
diff_find_match *match_srcs = NULL, *match_tgts = NULL, *best_match;
|
702
|
+
git_diff_file swap;
|
471
703
|
|
472
704
|
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
|
473
705
|
return error;
|
474
706
|
|
475
|
-
/* TODO: maybe abort if deltas.length >
|
476
|
-
|
477
|
-
|
478
|
-
cache = git__calloc(cache_size, sizeof(void *));
|
479
|
-
GITERR_CHECK_ALLOC(cache);
|
707
|
+
/* TODO: maybe abort if deltas.length > rename_limit ??? */
|
708
|
+
if (!git__is_uint32(diff->deltas.length))
|
709
|
+
return 0;
|
480
710
|
|
481
|
-
|
482
|
-
|
711
|
+
sigcache_size = diff->deltas.length * 2; /* keep size b/c diff may change */
|
712
|
+
sigcache = git__calloc(sigcache_size, sizeof(void *));
|
713
|
+
GITERR_CHECK_ALLOC(sigcache);
|
483
714
|
|
484
|
-
/*
|
715
|
+
/* Label rename sources and targets
|
716
|
+
*
|
717
|
+
* This will also set self-similarity scores for MODIFIED files and
|
718
|
+
* mark them for splitting if break-rewrites is enabled
|
719
|
+
*/
|
720
|
+
git_vector_foreach(&diff->deltas, i, to) {
|
721
|
+
if (is_rename_source(diff, &opts, i, sigcache))
|
722
|
+
++num_srcs;
|
485
723
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
continue;
|
724
|
+
if (is_rename_target(diff, &opts, i, sigcache))
|
725
|
+
++num_tgts;
|
726
|
+
}
|
490
727
|
|
491
|
-
|
492
|
-
|
728
|
+
/* if there are no candidate srcs or tgts, we're done */
|
729
|
+
if (!num_srcs || !num_tgts)
|
730
|
+
goto cleanup;
|
493
731
|
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
732
|
+
match_tgts = git__calloc(diff->deltas.length, sizeof(diff_find_match));
|
733
|
+
GITERR_CHECK_ALLOC(match_tgts);
|
734
|
+
match_srcs = git__calloc(diff->deltas.length, sizeof(diff_find_match));
|
735
|
+
GITERR_CHECK_ALLOC(match_srcs);
|
498
736
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
}
|
503
|
-
}
|
504
|
-
}
|
505
|
-
|
506
|
-
/* next find the most similar delta for each rename / copy candidate */
|
737
|
+
/*
|
738
|
+
* Find best-fit matches for rename / copy candidates
|
739
|
+
*/
|
507
740
|
|
508
|
-
|
509
|
-
|
741
|
+
find_best_matches:
|
742
|
+
tried_tgts = num_bumped = 0;
|
510
743
|
|
511
|
-
|
512
|
-
|
513
|
-
|
744
|
+
git_vector_foreach(&diff->deltas, i, to) {
|
745
|
+
/* skip things that are not rename targets */
|
746
|
+
if ((to->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0)
|
514
747
|
continue;
|
515
748
|
|
516
|
-
|
517
|
-
if (from->status == GIT_DELTA_UNMODIFIED &&
|
518
|
-
!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED))
|
519
|
-
continue;
|
749
|
+
tried_srcs = 0;
|
520
750
|
|
521
|
-
|
522
|
-
|
523
|
-
from->
|
524
|
-
|
525
|
-
continue;
|
751
|
+
git_vector_foreach(&diff->deltas, j, from) {
|
752
|
+
/* skip things that are not rename sources */
|
753
|
+
if ((from->flags & GIT_DIFF_FLAG__IS_RENAME_SOURCE) == 0)
|
754
|
+
continue;
|
526
755
|
|
527
|
-
|
756
|
+
/* calculate similarity for this pair and find best match */
|
528
757
|
if (i == j)
|
529
|
-
|
758
|
+
similarity = -1; /* don't measure self-similarity here */
|
759
|
+
else if ((error = similarity_measure(
|
760
|
+
&similarity, diff, &opts, sigcache, 2 * j, 2 * i + 1)) < 0)
|
761
|
+
goto cleanup;
|
530
762
|
|
531
|
-
/*
|
532
|
-
if (
|
533
|
-
|
534
|
-
|
763
|
+
/* if this pairing is better for the src and the tgt, keep it */
|
764
|
+
if (similarity > 0 &&
|
765
|
+
match_tgts[i].similarity < (uint32_t)similarity &&
|
766
|
+
match_srcs[j].similarity < (uint32_t)similarity)
|
767
|
+
{
|
768
|
+
if (match_tgts[i].similarity > 0) {
|
769
|
+
match_tgts[match_srcs[j].idx].similarity = 0;
|
770
|
+
match_srcs[match_tgts[i].idx].similarity = 0;
|
771
|
+
++num_bumped;
|
772
|
+
}
|
773
|
+
|
774
|
+
match_tgts[i].similarity = (uint32_t)similarity;
|
775
|
+
match_tgts[i].idx = (uint32_t)j;
|
776
|
+
|
777
|
+
match_srcs[j].similarity = (uint32_t)similarity;
|
778
|
+
match_srcs[j].idx = (uint32_t)i;
|
779
|
+
}
|
535
780
|
|
536
|
-
|
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;
|
781
|
+
if (++tried_srcs >= num_srcs)
|
545
782
|
break;
|
546
|
-
default:
|
547
|
-
/* only the above status values should be checked */
|
548
|
-
continue;
|
549
|
-
}
|
550
783
|
|
551
|
-
/* cap on maximum
|
552
|
-
if (
|
784
|
+
/* cap on maximum targets we'll examine (per "to" file) */
|
785
|
+
if (tried_srcs > opts.rename_limit)
|
553
786
|
break;
|
787
|
+
}
|
554
788
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
similarity = similarity_measure(
|
559
|
-
diff, &opts, cache, 2 * i, 2 * j + 1);
|
789
|
+
if (++tried_tgts >= num_tgts)
|
790
|
+
break;
|
791
|
+
}
|
560
792
|
|
561
|
-
|
562
|
-
|
563
|
-
goto cleanup;
|
564
|
-
}
|
793
|
+
if (num_bumped > 0) /* try again if we bumped some items */
|
794
|
+
goto find_best_matches;
|
565
795
|
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
}
|
570
|
-
}
|
571
|
-
}
|
796
|
+
/*
|
797
|
+
* Rewrite the diffs with renames / copies
|
798
|
+
*/
|
572
799
|
|
573
|
-
|
800
|
+
tried_tgts = 0;
|
574
801
|
|
575
|
-
git_vector_foreach(&diff->deltas,
|
576
|
-
|
577
|
-
|
802
|
+
git_vector_foreach(&diff->deltas, i, to) {
|
803
|
+
/* skip things that are not rename targets */
|
804
|
+
if ((to->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0)
|
578
805
|
continue;
|
579
|
-
}
|
580
806
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
*
|
591
|
-
*
|
592
|
-
*
|
593
|
-
* 4.
|
807
|
+
/* check if this delta was the target of a similarity */
|
808
|
+
best_match = &match_tgts[i];
|
809
|
+
if (!best_match->similarity)
|
810
|
+
continue;
|
811
|
+
|
812
|
+
j = best_match->idx;
|
813
|
+
from = GIT_VECTOR_GET(&diff->deltas, j);
|
814
|
+
|
815
|
+
/* possible scenarios:
|
816
|
+
* 1. from DELETE to ADD/UNTRACK/IGNORE = RENAME
|
817
|
+
* 2. from DELETE to SPLIT/TYPECHANGE = RENAME + DELETE
|
818
|
+
* 3. from SPLIT/TYPECHANGE to ADD/UNTRACK/IGNORE = ADD + RENAME
|
819
|
+
* 4. from SPLIT/TYPECHANGE to SPLIT/TYPECHANGE = RENAME + SPLIT
|
820
|
+
* 5. from OTHER to ADD/UNTRACK/IGNORE = OTHER + COPY
|
594
821
|
*/
|
595
822
|
|
596
823
|
if (from->status == GIT_DELTA_DELETED) {
|
597
|
-
if (to->similarity < opts.rename_threshold) {
|
598
|
-
to->similarity = 0;
|
599
|
-
continue;
|
600
|
-
}
|
601
824
|
|
602
|
-
to
|
603
|
-
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
825
|
+
if (delta_is_new_only(to)) {
|
604
826
|
|
605
|
-
|
606
|
-
|
827
|
+
if (best_match->similarity < opts.rename_threshold)
|
828
|
+
continue;
|
607
829
|
|
608
|
-
|
609
|
-
}
|
830
|
+
delta_make_rename(to, from, best_match->similarity);
|
610
831
|
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
to->similarity = 0;
|
616
|
-
continue;
|
617
|
-
}
|
832
|
+
from->flags |= GIT_DIFF_FLAG__TO_DELETE;
|
833
|
+
num_rewrites++;
|
834
|
+
} else {
|
835
|
+
assert(delta_is_split(to));
|
618
836
|
|
619
|
-
|
620
|
-
|
837
|
+
if (best_match->similarity < opts.rename_from_rewrite_threshold)
|
838
|
+
continue;
|
621
839
|
|
622
|
-
|
623
|
-
from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
624
|
-
memset(&from->old_file, 0, sizeof(from->old_file));
|
625
|
-
num_rewrites--;
|
840
|
+
memcpy(&swap, &to->old_file, sizeof(swap));
|
626
841
|
|
627
|
-
|
628
|
-
|
842
|
+
delta_make_rename(to, from, best_match->similarity);
|
843
|
+
num_rewrites--;
|
629
844
|
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
diff, &opts, cache, 2 * i, 2 * i + 1);
|
845
|
+
from->status = GIT_DELTA_DELETED;
|
846
|
+
memcpy(&from->old_file, &swap, sizeof(from->old_file));
|
847
|
+
memset(&from->new_file, 0, sizeof(from->new_file));
|
848
|
+
from->new_file.path = from->old_file.path;
|
849
|
+
from->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
636
850
|
|
637
|
-
|
638
|
-
error = similarity;
|
639
|
-
goto cleanup;
|
851
|
+
num_updates++;
|
640
852
|
}
|
853
|
+
}
|
854
|
+
|
855
|
+
else if (delta_is_split(from)) {
|
856
|
+
|
857
|
+
if (delta_is_new_only(to)) {
|
641
858
|
|
642
|
-
|
643
|
-
|
644
|
-
|
859
|
+
if (best_match->similarity < opts.rename_threshold)
|
860
|
+
continue;
|
861
|
+
|
862
|
+
delta_make_rename(to, from, best_match->similarity);
|
645
863
|
|
646
|
-
from->status =
|
864
|
+
from->status = (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR) ?
|
865
|
+
GIT_DELTA_UNTRACKED : GIT_DELTA_ADDED;
|
647
866
|
memset(&from->old_file, 0, sizeof(from->old_file));
|
648
|
-
from->old_file.path =
|
867
|
+
from->old_file.path = from->new_file.path;
|
649
868
|
from->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
|
650
869
|
|
651
|
-
|
870
|
+
from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
871
|
+
num_rewrites--;
|
872
|
+
|
873
|
+
num_updates++;
|
874
|
+
} else {
|
875
|
+
assert(delta_is_split(from));
|
876
|
+
|
877
|
+
if (best_match->similarity < opts.rename_from_rewrite_threshold)
|
878
|
+
continue;
|
879
|
+
|
880
|
+
memcpy(&swap, &to->old_file, sizeof(swap));
|
881
|
+
|
882
|
+
delta_make_rename(to, from, best_match->similarity);
|
883
|
+
num_rewrites--;
|
884
|
+
num_updates++;
|
885
|
+
|
886
|
+
memcpy(&from->old_file, &swap, sizeof(from->old_file));
|
887
|
+
|
888
|
+
/* if we've just swapped the new element into the correct
|
889
|
+
* place, clear the SPLIT flag
|
890
|
+
*/
|
891
|
+
if (match_tgts[j].idx == i &&
|
892
|
+
match_tgts[j].similarity >
|
893
|
+
opts.rename_from_rewrite_threshold) {
|
894
|
+
|
895
|
+
from->status = GIT_DELTA_RENAMED;
|
896
|
+
from->similarity = match_tgts[j].similarity;
|
897
|
+
match_tgts[j].similarity = 0;
|
898
|
+
from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
|
899
|
+
num_rewrites--;
|
900
|
+
}
|
901
|
+
/* otherwise, if we just overwrote a source, update mapping */
|
902
|
+
else if (j > i && match_srcs[i].similarity > 0) {
|
903
|
+
match_tgts[match_srcs[i].idx].idx = (uint32_t)j;
|
904
|
+
}
|
905
|
+
|
906
|
+
num_updates++;
|
652
907
|
}
|
653
908
|
}
|
654
909
|
|
655
|
-
if (to
|
656
|
-
|
657
|
-
|
658
|
-
|
910
|
+
else if (delta_is_new_only(to)) {
|
911
|
+
if (!FLAG_SET(&opts, GIT_DIFF_FIND_COPIES) ||
|
912
|
+
best_match->similarity < opts.copy_threshold)
|
913
|
+
continue;
|
659
914
|
|
660
|
-
|
661
|
-
|
662
|
-
|
915
|
+
to->status = GIT_DELTA_COPIED;
|
916
|
+
to->similarity = best_match->similarity;
|
917
|
+
memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
|
918
|
+
|
919
|
+
num_updates++;
|
920
|
+
}
|
663
921
|
}
|
664
922
|
|
665
|
-
|
666
|
-
|
923
|
+
/*
|
924
|
+
* Actually split and delete entries as needed
|
925
|
+
*/
|
667
926
|
|
927
|
+
if (num_rewrites > 0 || num_updates > 0)
|
668
928
|
error = apply_splits_and_deletes(
|
669
|
-
diff, diff->deltas.length - num_rewrites
|
670
|
-
|
929
|
+
diff, diff->deltas.length - num_rewrites,
|
930
|
+
FLAG_SET(&opts, GIT_DIFF_BREAK_REWRITES));
|
671
931
|
|
672
932
|
cleanup:
|
673
|
-
git__free(
|
933
|
+
git__free(match_srcs);
|
934
|
+
git__free(match_tgts);
|
674
935
|
|
675
|
-
for (i = 0; i <
|
676
|
-
if (
|
677
|
-
opts.metric->free_signature(
|
936
|
+
for (i = 0; i < sigcache_size; ++i) {
|
937
|
+
if (sigcache[i] != NULL)
|
938
|
+
opts.metric->free_signature(sigcache[i], opts.metric->payload);
|
678
939
|
}
|
679
|
-
git__free(
|
940
|
+
git__free(sigcache);
|
680
941
|
|
681
942
|
if (!given_opts || !given_opts->metric)
|
682
943
|
git__free(opts.metric);
|