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
@@ -0,0 +1,166 @@
|
|
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 "diff_driver.h"
|
10
|
+
#include "diff_patch.h"
|
11
|
+
#include "diff_xdiff.h"
|
12
|
+
|
13
|
+
static int git_xdiff_scan_int(const char **str, int *value)
|
14
|
+
{
|
15
|
+
const char *scan = *str;
|
16
|
+
int v = 0, digits = 0;
|
17
|
+
/* find next digit */
|
18
|
+
for (scan = *str; *scan && !git__isdigit(*scan); scan++);
|
19
|
+
/* parse next number */
|
20
|
+
for (; git__isdigit(*scan); scan++, digits++)
|
21
|
+
v = (v * 10) + (*scan - '0');
|
22
|
+
*str = scan;
|
23
|
+
*value = v;
|
24
|
+
return (digits > 0) ? 0 : -1;
|
25
|
+
}
|
26
|
+
|
27
|
+
static int git_xdiff_parse_hunk(git_diff_range *range, const char *header)
|
28
|
+
{
|
29
|
+
/* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */
|
30
|
+
if (*header != '@')
|
31
|
+
return -1;
|
32
|
+
if (git_xdiff_scan_int(&header, &range->old_start) < 0)
|
33
|
+
return -1;
|
34
|
+
if (*header == ',') {
|
35
|
+
if (git_xdiff_scan_int(&header, &range->old_lines) < 0)
|
36
|
+
return -1;
|
37
|
+
} else
|
38
|
+
range->old_lines = 1;
|
39
|
+
if (git_xdiff_scan_int(&header, &range->new_start) < 0)
|
40
|
+
return -1;
|
41
|
+
if (*header == ',') {
|
42
|
+
if (git_xdiff_scan_int(&header, &range->new_lines) < 0)
|
43
|
+
return -1;
|
44
|
+
} else
|
45
|
+
range->new_lines = 1;
|
46
|
+
if (range->old_start < 0 || range->new_start < 0)
|
47
|
+
return -1;
|
48
|
+
|
49
|
+
return 0;
|
50
|
+
}
|
51
|
+
|
52
|
+
typedef struct {
|
53
|
+
git_xdiff_output *xo;
|
54
|
+
git_diff_patch *patch;
|
55
|
+
git_diff_range range;
|
56
|
+
} git_xdiff_info;
|
57
|
+
|
58
|
+
static int git_xdiff_cb(void *priv, mmbuffer_t *bufs, int len)
|
59
|
+
{
|
60
|
+
git_xdiff_info *info = priv;
|
61
|
+
git_diff_patch *patch = info->patch;
|
62
|
+
const git_diff_delta *delta = git_diff_patch_delta(patch);
|
63
|
+
git_diff_output *output = &info->xo->output;
|
64
|
+
|
65
|
+
if (len == 1) {
|
66
|
+
output->error = git_xdiff_parse_hunk(&info->range, bufs[0].ptr);
|
67
|
+
if (output->error < 0)
|
68
|
+
return output->error;
|
69
|
+
|
70
|
+
if (output->hunk_cb != NULL &&
|
71
|
+
output->hunk_cb(delta, &info->range,
|
72
|
+
bufs[0].ptr, bufs[0].size, output->payload))
|
73
|
+
output->error = GIT_EUSER;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (len == 2 || len == 3) {
|
77
|
+
/* expect " "/"-"/"+", then data */
|
78
|
+
char origin =
|
79
|
+
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION :
|
80
|
+
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION :
|
81
|
+
GIT_DIFF_LINE_CONTEXT;
|
82
|
+
|
83
|
+
if (output->data_cb != NULL &&
|
84
|
+
output->data_cb(delta, &info->range,
|
85
|
+
origin, bufs[1].ptr, bufs[1].size, output->payload))
|
86
|
+
output->error = GIT_EUSER;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (len == 3 && !output->error) {
|
90
|
+
/* If we have a '+' and a third buf, then we have added a line
|
91
|
+
* without a newline and the old code had one, so DEL_EOFNL.
|
92
|
+
* If we have a '-' and a third buf, then we have removed a line
|
93
|
+
* with out a newline but added a blank line, so ADD_EOFNL.
|
94
|
+
*/
|
95
|
+
char origin =
|
96
|
+
(*bufs[0].ptr == '+') ? GIT_DIFF_LINE_DEL_EOFNL :
|
97
|
+
(*bufs[0].ptr == '-') ? GIT_DIFF_LINE_ADD_EOFNL :
|
98
|
+
GIT_DIFF_LINE_CONTEXT_EOFNL;
|
99
|
+
|
100
|
+
if (output->data_cb != NULL &&
|
101
|
+
output->data_cb(delta, &info->range,
|
102
|
+
origin, bufs[2].ptr, bufs[2].size, output->payload))
|
103
|
+
output->error = GIT_EUSER;
|
104
|
+
}
|
105
|
+
|
106
|
+
return output->error;
|
107
|
+
}
|
108
|
+
|
109
|
+
static int git_xdiff(git_diff_output *output, git_diff_patch *patch)
|
110
|
+
{
|
111
|
+
git_xdiff_output *xo = (git_xdiff_output *)output;
|
112
|
+
git_xdiff_info info;
|
113
|
+
git_diff_find_context_payload findctxt;
|
114
|
+
mmfile_t xd_old_data, xd_new_data;
|
115
|
+
|
116
|
+
memset(&info, 0, sizeof(info));
|
117
|
+
info.patch = patch;
|
118
|
+
info.xo = xo;
|
119
|
+
|
120
|
+
xo->callback.priv = &info;
|
121
|
+
|
122
|
+
git_diff_find_context_init(
|
123
|
+
&xo->config.find_func, &findctxt, git_diff_patch__driver(patch));
|
124
|
+
xo->config.find_func_priv = &findctxt;
|
125
|
+
|
126
|
+
if (xo->config.find_func != NULL)
|
127
|
+
xo->config.flags |= XDL_EMIT_FUNCNAMES;
|
128
|
+
else
|
129
|
+
xo->config.flags &= ~XDL_EMIT_FUNCNAMES;
|
130
|
+
|
131
|
+
/* TODO: check ofile.opts_flags to see if driver-specific per-file
|
132
|
+
* updates are needed to xo->params.flags
|
133
|
+
*/
|
134
|
+
|
135
|
+
git_diff_patch__old_data(&xd_old_data.ptr, &xd_old_data.size, patch);
|
136
|
+
git_diff_patch__new_data(&xd_new_data.ptr, &xd_new_data.size, patch);
|
137
|
+
|
138
|
+
xdl_diff(&xd_old_data, &xd_new_data,
|
139
|
+
&xo->params, &xo->config, &xo->callback);
|
140
|
+
|
141
|
+
git_diff_find_context_clear(&findctxt);
|
142
|
+
|
143
|
+
return xo->output.error;
|
144
|
+
}
|
145
|
+
|
146
|
+
void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
|
147
|
+
{
|
148
|
+
uint32_t flags = opts ? opts->flags : GIT_DIFF_NORMAL;
|
149
|
+
|
150
|
+
xo->output.diff_cb = git_xdiff;
|
151
|
+
|
152
|
+
memset(&xo->config, 0, sizeof(xo->config));
|
153
|
+
xo->config.ctxlen = opts ? opts->context_lines : 3;
|
154
|
+
xo->config.interhunkctxlen = opts ? opts->interhunk_lines : 0;
|
155
|
+
|
156
|
+
memset(&xo->params, 0, sizeof(xo->params));
|
157
|
+
if (flags & GIT_DIFF_IGNORE_WHITESPACE)
|
158
|
+
xo->params.flags |= XDF_WHITESPACE_FLAGS;
|
159
|
+
if (flags & GIT_DIFF_IGNORE_WHITESPACE_CHANGE)
|
160
|
+
xo->params.flags |= XDF_IGNORE_WHITESPACE_CHANGE;
|
161
|
+
if (flags & GIT_DIFF_IGNORE_WHITESPACE_EOL)
|
162
|
+
xo->params.flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
|
163
|
+
|
164
|
+
memset(&xo->callback, 0, sizeof(xo->callback));
|
165
|
+
xo->callback.outf = git_xdiff_cb;
|
166
|
+
}
|
@@ -0,0 +1,28 @@
|
|
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
|
+
#ifndef INCLUDE_diff_xdiff_h__
|
8
|
+
#define INCLUDE_diff_xdiff_h__
|
9
|
+
|
10
|
+
#include "diff.h"
|
11
|
+
#include "diff_patch.h"
|
12
|
+
#include "xdiff/xdiff.h"
|
13
|
+
|
14
|
+
/* A git_xdiff_output is a git_diff_output with extra fields necessary
|
15
|
+
* to use libxdiff. Calling git_xdiff_init() will set the diff_cb field
|
16
|
+
* of the output to use xdiff to generate the diffs.
|
17
|
+
*/
|
18
|
+
typedef struct {
|
19
|
+
git_diff_output output;
|
20
|
+
|
21
|
+
xdemitconf_t config;
|
22
|
+
xpparam_t params;
|
23
|
+
xdemitcb_t callback;
|
24
|
+
} git_xdiff_output;
|
25
|
+
|
26
|
+
void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts);
|
27
|
+
|
28
|
+
#endif
|
data/vendor/libgit2/src/fetch.c
CHANGED
@@ -16,6 +16,8 @@
|
|
16
16
|
#include "pack.h"
|
17
17
|
#include "fetch.h"
|
18
18
|
#include "netops.h"
|
19
|
+
#include "repository.h"
|
20
|
+
#include "refs.h"
|
19
21
|
|
20
22
|
struct filter_payload {
|
21
23
|
git_remote *remote;
|
@@ -34,10 +36,16 @@ static int filter_ref__cb(git_remote_head *head, void *payload)
|
|
34
36
|
|
35
37
|
if (!p->found_head && strcmp(head->name, GIT_HEAD_FILE) == 0)
|
36
38
|
p->found_head = 1;
|
37
|
-
else if (
|
39
|
+
else if (p->remote->download_tags == GIT_REMOTE_DOWNLOAD_TAGS_ALL) {
|
40
|
+
/*
|
41
|
+
* If tagopt is --tags, then we only use the default
|
42
|
+
* tags refspec and ignore the remote's
|
43
|
+
*/
|
44
|
+
if (git_refspec_src_matches(p->tagspec, head->name))
|
38
45
|
match = 1;
|
39
|
-
|
40
|
-
|
46
|
+
else
|
47
|
+
return 0;
|
48
|
+
} else if (git_remote__matching_refspec(p->remote, head->name))
|
41
49
|
match = 1;
|
42
50
|
|
43
51
|
if (!match)
|
@@ -68,7 +76,6 @@ static int filter_wants(git_remote *remote)
|
|
68
76
|
* not interested in any particular branch but just the remote's
|
69
77
|
* HEAD, which will be stored in FETCH_HEAD after the fetch.
|
70
78
|
*/
|
71
|
-
p.spec = git_remote_fetchspec(remote);
|
72
79
|
p.tagspec = &tagspec;
|
73
80
|
p.found_head = 0;
|
74
81
|
p.remote = remote;
|
@@ -61,9 +61,11 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
|
|
61
61
|
wchar_t buf[GIT_WIN_PATH];
|
62
62
|
|
63
63
|
git__utf8_to_16(buf, GIT_WIN_PATH, path);
|
64
|
-
fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC |
|
64
|
+
fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC |
|
65
|
+
O_EXCL | O_BINARY | O_CLOEXEC, mode);
|
65
66
|
#else
|
66
|
-
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC |
|
67
|
+
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC |
|
68
|
+
O_EXCL | O_BINARY | O_CLOEXEC, mode);
|
67
69
|
#endif
|
68
70
|
|
69
71
|
if (fd < 0) {
|
@@ -202,6 +204,32 @@ int git_futils_readbuffer(git_buf *buf, const char *path)
|
|
202
204
|
return git_futils_readbuffer_updated(buf, path, NULL, NULL, NULL);
|
203
205
|
}
|
204
206
|
|
207
|
+
int git_futils_writebuffer(
|
208
|
+
const git_buf *buf, const char *path, int flags, mode_t mode)
|
209
|
+
{
|
210
|
+
int fd, error = 0;
|
211
|
+
|
212
|
+
if (flags <= 0)
|
213
|
+
flags = O_CREAT | O_TRUNC | O_WRONLY;
|
214
|
+
if (!mode)
|
215
|
+
mode = GIT_FILEMODE_BLOB;
|
216
|
+
|
217
|
+
if ((fd = p_open(path, flags, mode)) < 0) {
|
218
|
+
giterr_set(GITERR_OS, "Could not open '%s' for writing", path);
|
219
|
+
return fd;
|
220
|
+
}
|
221
|
+
|
222
|
+
if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
|
223
|
+
giterr_set(GITERR_OS, "Could not write to '%s'", path);
|
224
|
+
(void)p_close(fd);
|
225
|
+
}
|
226
|
+
|
227
|
+
if ((error = p_close(fd)) < 0)
|
228
|
+
giterr_set(GITERR_OS, "Error while closing '%s'", path);
|
229
|
+
|
230
|
+
return error;
|
231
|
+
}
|
232
|
+
|
205
233
|
int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
|
206
234
|
{
|
207
235
|
if (git_futils_mkpath2file(to, dirmode) < 0)
|
@@ -253,8 +281,9 @@ int git_futils_mkdir(
|
|
253
281
|
{
|
254
282
|
int error = -1;
|
255
283
|
git_buf make_path = GIT_BUF_INIT;
|
256
|
-
ssize_t root = 0;
|
257
|
-
char lastch, *tail;
|
284
|
+
ssize_t root = 0, min_root_len;
|
285
|
+
char lastch = '/', *tail;
|
286
|
+
struct stat st;
|
258
287
|
|
259
288
|
/* build path and find "root" where we should start calling mkdir */
|
260
289
|
if (git_path_join_unrooted(&make_path, path, base, &root) < 0)
|
@@ -262,7 +291,7 @@ int git_futils_mkdir(
|
|
262
291
|
|
263
292
|
if (make_path.size == 0) {
|
264
293
|
giterr_set(GITERR_OS, "Attempt to create empty path");
|
265
|
-
goto
|
294
|
+
goto done;
|
266
295
|
}
|
267
296
|
|
268
297
|
/* remove trailing slashes on path */
|
@@ -279,19 +308,32 @@ int git_futils_mkdir(
|
|
279
308
|
if ((flags & GIT_MKDIR_SKIP_LAST) != 0)
|
280
309
|
git_buf_rtruncate_at_char(&make_path, '/');
|
281
310
|
|
311
|
+
/* if nothing left after truncation, then we're done! */
|
312
|
+
if (!make_path.size) {
|
313
|
+
error = 0;
|
314
|
+
goto done;
|
315
|
+
}
|
316
|
+
|
282
317
|
/* if we are not supposed to make the whole path, reset root */
|
283
318
|
if ((flags & GIT_MKDIR_PATH) == 0)
|
284
319
|
root = git_buf_rfind(&make_path, '/');
|
285
320
|
|
321
|
+
/* advance root past drive name or network mount prefix */
|
322
|
+
min_root_len = git_path_root(make_path.ptr);
|
323
|
+
if (root < min_root_len)
|
324
|
+
root = min_root_len;
|
325
|
+
while (root >= 0 && make_path.ptr[root] == '/')
|
326
|
+
++root;
|
327
|
+
|
286
328
|
/* clip root to make_path length */
|
287
|
-
if (root
|
288
|
-
root = (ssize_t)make_path.size
|
329
|
+
if (root > (ssize_t)make_path.size)
|
330
|
+
root = (ssize_t)make_path.size; /* i.e. NUL byte of string */
|
289
331
|
if (root < 0)
|
290
332
|
root = 0;
|
291
333
|
|
292
|
-
tail
|
334
|
+
/* walk down tail of path making each directory */
|
335
|
+
for (tail = &make_path.ptr[root]; *tail; *tail = lastch) {
|
293
336
|
|
294
|
-
while (*tail) {
|
295
337
|
/* advance tail to include next path component */
|
296
338
|
while (*tail == '/')
|
297
339
|
tail++;
|
@@ -301,68 +343,48 @@ int git_futils_mkdir(
|
|
301
343
|
/* truncate path at next component */
|
302
344
|
lastch = *tail;
|
303
345
|
*tail = '\0';
|
346
|
+
st.st_mode = 0;
|
304
347
|
|
305
348
|
/* make directory */
|
306
349
|
if (p_mkdir(make_path.ptr, mode) < 0) {
|
307
|
-
int
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
GITERR_OS, "Existing path is not a directory '%s'",
|
315
|
-
make_path.ptr);
|
316
|
-
error = GIT_ENOTFOUND;
|
317
|
-
goto fail;
|
318
|
-
}
|
319
|
-
|
320
|
-
already_exists = 1;
|
321
|
-
break;
|
322
|
-
case ENOSYS:
|
323
|
-
/* Solaris can generate this error if you try to mkdir
|
324
|
-
* a path which is already a mount point. In that case,
|
325
|
-
* the path does already exist; but it's not implied by
|
326
|
-
* the definition of the error, so let's recheck */
|
327
|
-
if (git_path_isdir(make_path.ptr)) {
|
328
|
-
already_exists = 1;
|
329
|
-
break;
|
330
|
-
}
|
331
|
-
|
332
|
-
/* Fall through */
|
333
|
-
errno = ENOSYS;
|
334
|
-
default:
|
335
|
-
giterr_set(GITERR_OS, "Failed to make directory '%s'",
|
336
|
-
make_path.ptr);
|
337
|
-
goto fail;
|
350
|
+
int tmp_errno = errno;
|
351
|
+
|
352
|
+
/* ignore error if directory already exists */
|
353
|
+
if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
|
354
|
+
errno = tmp_errno;
|
355
|
+
giterr_set(GITERR_OS, "Failed to make directory '%s'", make_path.ptr);
|
356
|
+
goto done;
|
338
357
|
}
|
339
358
|
|
340
|
-
|
341
|
-
|
342
|
-
|
359
|
+
/* with exclusive create, existing dir is an error */
|
360
|
+
if ((flags & GIT_MKDIR_EXCL) != 0) {
|
361
|
+
giterr_set(GITERR_OS, "Directory already exists '%s'", make_path.ptr);
|
343
362
|
error = GIT_EEXISTS;
|
344
|
-
goto
|
363
|
+
goto done;
|
345
364
|
}
|
346
365
|
}
|
347
366
|
|
348
|
-
/* chmod if requested */
|
349
|
-
if ((flags & GIT_MKDIR_CHMOD_PATH) != 0 ||
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
goto fail;
|
356
|
-
}
|
367
|
+
/* chmod if requested and necessary */
|
368
|
+
if (((flags & GIT_MKDIR_CHMOD_PATH) != 0 ||
|
369
|
+
(lastch == '\0' && (flags & GIT_MKDIR_CHMOD) != 0)) &&
|
370
|
+
st.st_mode != mode &&
|
371
|
+
(error = p_chmod(make_path.ptr, mode)) < 0) {
|
372
|
+
giterr_set(GITERR_OS, "Failed to set permissions on '%s'", make_path.ptr);
|
373
|
+
goto done;
|
357
374
|
}
|
358
|
-
|
359
|
-
*tail = lastch;
|
360
375
|
}
|
361
376
|
|
362
|
-
|
363
|
-
return 0;
|
377
|
+
error = 0;
|
364
378
|
|
365
|
-
|
379
|
+
/* check that full path really is a directory if requested & needed */
|
380
|
+
if ((flags & GIT_MKDIR_VERIFY_DIR) != 0 &&
|
381
|
+
lastch != '\0' &&
|
382
|
+
(p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode))) {
|
383
|
+
giterr_set(GITERR_OS, "Path is not a directory '%s'", make_path.ptr);
|
384
|
+
error = GIT_ENOTFOUND;
|
385
|
+
}
|
386
|
+
|
387
|
+
done:
|
366
388
|
git_buf_free(&make_path);
|
367
389
|
return error;
|
368
390
|
}
|
@@ -444,7 +466,7 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
|
|
444
466
|
|
445
467
|
if (data->error < 0) {
|
446
468
|
if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 &&
|
447
|
-
(errno == ENOTEMPTY || errno == EEXIST))
|
469
|
+
(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
|
448
470
|
data->error = 0;
|
449
471
|
else
|
450
472
|
futils__error_cannot_rmdir(path->ptr, NULL);
|
@@ -480,7 +502,7 @@ static int futils__rmdir_empty_parent(void *opaque, git_buf *path)
|
|
480
502
|
if (en == ENOENT || en == ENOTDIR) {
|
481
503
|
giterr_clear();
|
482
504
|
error = 0;
|
483
|
-
} else if (en == ENOTEMPTY || en == EEXIST) {
|
505
|
+
} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
|
484
506
|
giterr_clear();
|
485
507
|
error = GIT_ITEROVER;
|
486
508
|
} else {
|
@@ -988,8 +1010,10 @@ int git_futils_filestamp_check(
|
|
988
1010
|
if (stamp == NULL)
|
989
1011
|
return 1;
|
990
1012
|
|
991
|
-
if (p_stat(path, &st) < 0)
|
1013
|
+
if (p_stat(path, &st) < 0) {
|
1014
|
+
giterr_set(GITERR_OS, "Could not stat '%s'", path);
|
992
1015
|
return GIT_ENOTFOUND;
|
1016
|
+
}
|
993
1017
|
|
994
1018
|
if (stamp->mtime == (git_time_t)st.st_mtime &&
|
995
1019
|
stamp->size == (git_off_t)st.st_size &&
|