rugged 0.23.0b2 → 0.23.0b4
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.
- checksums.yaml +4 -4
- data/ext/rugged/rugged_blob.c +39 -0
- data/ext/rugged/rugged_diff.c +7 -3
- data/ext/rugged/rugged_index.c +2 -2
- data/ext/rugged/rugged_remote.c +27 -148
- data/ext/rugged/rugged_remote_collection.c +134 -12
- data/ext/rugged/rugged_repo.c +74 -5
- data/ext/rugged/rugged_submodule.c +18 -208
- data/ext/rugged/rugged_submodule_collection.c +148 -0
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/AUTHORS +1 -0
- data/vendor/libgit2/CMakeLists.txt +33 -25
- data/vendor/libgit2/deps/winhttp/winhttp.def +29 -29
- data/vendor/libgit2/include/git2.h +1 -1
- data/vendor/libgit2/include/git2/blob.h +4 -6
- data/vendor/libgit2/include/git2/checkout.h +10 -1
- data/vendor/libgit2/include/git2/clone.h +6 -7
- data/vendor/libgit2/include/git2/commit.h +11 -0
- data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
- data/vendor/libgit2/include/git2/describe.h +1 -1
- data/vendor/libgit2/include/git2/diff.h +68 -11
- data/vendor/libgit2/include/git2/errors.h +4 -1
- data/vendor/libgit2/include/git2/filter.h +16 -0
- data/vendor/libgit2/include/git2/index.h +38 -11
- data/vendor/libgit2/include/git2/odb.h +1 -1
- data/vendor/libgit2/include/git2/odb_backend.h +2 -2
- data/vendor/libgit2/include/git2/remote.h +300 -207
- data/vendor/libgit2/include/git2/reset.h +1 -0
- data/vendor/libgit2/include/git2/stash.h +135 -4
- data/vendor/libgit2/include/git2/status.h +1 -0
- data/vendor/libgit2/include/git2/submodule.h +46 -75
- data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
- data/vendor/libgit2/include/git2/sys/stream.h +2 -0
- data/vendor/libgit2/include/git2/sys/transport.h +1 -21
- data/vendor/libgit2/include/git2/transport.h +27 -0
- data/vendor/libgit2/include/git2/types.h +20 -10
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/libgit2.pc.in +4 -2
- data/vendor/libgit2/src/attr.c +2 -1
- data/vendor/libgit2/src/attr_file.c +18 -37
- data/vendor/libgit2/src/blame.c +2 -2
- data/vendor/libgit2/src/blob.c +4 -3
- data/vendor/libgit2/src/branch.c +6 -3
- data/vendor/libgit2/src/buf_text.c +4 -6
- data/vendor/libgit2/src/buf_text.h +1 -2
- data/vendor/libgit2/src/buffer.c +8 -6
- data/vendor/libgit2/src/buffer.h +1 -1
- data/vendor/libgit2/src/cache.c +1 -0
- data/vendor/libgit2/src/checkout.c +34 -20
- data/vendor/libgit2/src/clone.c +29 -29
- data/vendor/libgit2/src/commit.c +65 -0
- data/vendor/libgit2/src/common.h +5 -0
- data/vendor/libgit2/src/config.c +20 -0
- data/vendor/libgit2/src/config.h +6 -0
- data/vendor/libgit2/src/config_file.c +2 -2
- data/vendor/libgit2/src/crlf.c +39 -17
- data/vendor/libgit2/src/curl_stream.c +257 -0
- data/vendor/libgit2/src/curl_stream.h +14 -0
- data/vendor/libgit2/src/diff.c +223 -88
- data/vendor/libgit2/src/diff.h +21 -1
- data/vendor/libgit2/src/diff_file.c +23 -13
- data/vendor/libgit2/src/diff_file.h +4 -2
- data/vendor/libgit2/src/diff_patch.c +266 -71
- data/vendor/libgit2/src/diff_patch.h +36 -0
- data/vendor/libgit2/src/diff_print.c +156 -126
- data/vendor/libgit2/src/diff_tform.c +32 -54
- data/vendor/libgit2/src/fetch.c +27 -10
- data/vendor/libgit2/src/fetch.h +2 -2
- data/vendor/libgit2/src/filebuf.c +1 -1
- data/vendor/libgit2/src/fileops.c +6 -2
- data/vendor/libgit2/src/filter.c +28 -7
- data/vendor/libgit2/src/fnmatch.c +5 -5
- data/vendor/libgit2/src/global.c +16 -0
- data/vendor/libgit2/src/ident.c +2 -2
- data/vendor/libgit2/src/ignore.c +1 -0
- data/vendor/libgit2/src/index.c +338 -80
- data/vendor/libgit2/src/index.h +4 -1
- data/vendor/libgit2/src/indexer.c +19 -5
- data/vendor/libgit2/src/iterator.c +118 -11
- data/vendor/libgit2/src/iterator.h +25 -0
- data/vendor/libgit2/src/merge.c +96 -106
- data/vendor/libgit2/src/merge.h +14 -4
- data/vendor/libgit2/src/netops.c +3 -3
- data/vendor/libgit2/src/odb.c +17 -9
- data/vendor/libgit2/src/odb.h +1 -1
- data/vendor/libgit2/src/odb_loose.c +2 -2
- data/vendor/libgit2/src/odb_pack.c +1 -1
- data/vendor/libgit2/src/openssl_stream.c +118 -27
- data/vendor/libgit2/src/pack-objects.c +28 -0
- data/vendor/libgit2/src/pack-objects.h +1 -0
- data/vendor/libgit2/src/pack.c +18 -10
- data/vendor/libgit2/src/path.c +16 -11
- data/vendor/libgit2/src/path.h +1 -1
- data/vendor/libgit2/src/push.c +26 -42
- data/vendor/libgit2/src/push.h +2 -34
- data/vendor/libgit2/src/rebase.c +1 -1
- data/vendor/libgit2/src/refs.c +1 -1
- data/vendor/libgit2/src/refspec.c +6 -0
- data/vendor/libgit2/src/remote.c +381 -274
- data/vendor/libgit2/src/remote.h +0 -4
- data/vendor/libgit2/src/repository.c +33 -12
- data/vendor/libgit2/src/repository.h +0 -1
- data/vendor/libgit2/src/reset.c +1 -0
- data/vendor/libgit2/src/stash.c +439 -17
- data/vendor/libgit2/src/status.c +6 -0
- data/vendor/libgit2/src/stransport_stream.c +58 -21
- data/vendor/libgit2/src/stream.h +15 -0
- data/vendor/libgit2/src/submodule.c +410 -664
- data/vendor/libgit2/src/submodule.h +0 -24
- data/vendor/libgit2/src/transaction.c +1 -0
- data/vendor/libgit2/src/transports/cred.c +55 -1
- data/vendor/libgit2/src/transports/http.c +18 -2
- data/vendor/libgit2/src/transports/local.c +60 -59
- data/vendor/libgit2/src/transports/smart.h +1 -1
- data/vendor/libgit2/src/transports/smart_protocol.c +11 -11
- data/vendor/libgit2/src/transports/ssh.c +46 -7
- data/vendor/libgit2/src/unix/posix.h +4 -0
- data/vendor/libgit2/src/util.c +9 -9
- data/vendor/libgit2/src/util.h +9 -0
- data/vendor/libgit2/src/win32/posix.h +3 -0
- data/vendor/libgit2/src/win32/posix_w32.c +38 -0
- data/vendor/libgit2/src/win32/w32_util.h +10 -0
- metadata +4 -3
- data/vendor/libgit2/include/git2/push.h +0 -94
|
@@ -13,6 +13,40 @@
|
|
|
13
13
|
#include "array.h"
|
|
14
14
|
#include "git2/patch.h"
|
|
15
15
|
|
|
16
|
+
/* cached information about a hunk in a diff */
|
|
17
|
+
typedef struct diff_patch_hunk {
|
|
18
|
+
git_diff_hunk hunk;
|
|
19
|
+
size_t line_start;
|
|
20
|
+
size_t line_count;
|
|
21
|
+
} diff_patch_hunk;
|
|
22
|
+
|
|
23
|
+
enum {
|
|
24
|
+
GIT_DIFF_PATCH_ALLOCATED = (1 << 0),
|
|
25
|
+
GIT_DIFF_PATCH_INITIALIZED = (1 << 1),
|
|
26
|
+
GIT_DIFF_PATCH_LOADED = (1 << 2),
|
|
27
|
+
/* the two sides are different */
|
|
28
|
+
GIT_DIFF_PATCH_DIFFABLE = (1 << 3),
|
|
29
|
+
/* the difference between the two sides has been computed */
|
|
30
|
+
GIT_DIFF_PATCH_DIFFED = (1 << 4),
|
|
31
|
+
GIT_DIFF_PATCH_FLATTENED = (1 << 5),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
struct git_patch {
|
|
35
|
+
git_refcount rc;
|
|
36
|
+
git_diff *diff; /* for refcount purposes, maybe NULL for blob diffs */
|
|
37
|
+
git_diff_options diff_opts;
|
|
38
|
+
git_diff_delta *delta;
|
|
39
|
+
size_t delta_index;
|
|
40
|
+
git_diff_file_content ofile;
|
|
41
|
+
git_diff_file_content nfile;
|
|
42
|
+
uint32_t flags;
|
|
43
|
+
git_diff_binary binary;
|
|
44
|
+
git_array_t(diff_patch_hunk) hunks;
|
|
45
|
+
git_array_t(git_diff_line) lines;
|
|
46
|
+
size_t content_size, context_size, header_size;
|
|
47
|
+
git_pool flattened;
|
|
48
|
+
};
|
|
49
|
+
|
|
16
50
|
extern git_diff *git_patch__diff(git_patch *);
|
|
17
51
|
|
|
18
52
|
extern git_diff_driver *git_patch__driver(git_patch *);
|
|
@@ -23,6 +57,7 @@ extern void git_patch__new_data(char **, size_t *, git_patch *);
|
|
|
23
57
|
extern int git_patch__invoke_callbacks(
|
|
24
58
|
git_patch *patch,
|
|
25
59
|
git_diff_file_cb file_cb,
|
|
60
|
+
git_diff_binary_cb binary_cb,
|
|
26
61
|
git_diff_hunk_cb hunk_cb,
|
|
27
62
|
git_diff_line_cb line_cb,
|
|
28
63
|
void *payload);
|
|
@@ -31,6 +66,7 @@ typedef struct git_diff_output git_diff_output;
|
|
|
31
66
|
struct git_diff_output {
|
|
32
67
|
/* these callbacks are issued with the diff data */
|
|
33
68
|
git_diff_file_cb file_cb;
|
|
69
|
+
git_diff_binary_cb binary_cb;
|
|
34
70
|
git_diff_hunk_cb hunk_cb;
|
|
35
71
|
git_diff_line_cb data_cb;
|
|
36
72
|
void *payload;
|
|
@@ -22,50 +22,92 @@ typedef struct {
|
|
|
22
22
|
uint32_t flags;
|
|
23
23
|
int oid_strlen;
|
|
24
24
|
git_diff_line line;
|
|
25
|
+
unsigned int
|
|
26
|
+
content_loaded : 1,
|
|
27
|
+
content_allocated : 1;
|
|
28
|
+
git_diff_file_content *ofile;
|
|
29
|
+
git_diff_file_content *nfile;
|
|
25
30
|
} diff_print_info;
|
|
26
31
|
|
|
27
|
-
static int
|
|
32
|
+
static int diff_print_info_init__common(
|
|
28
33
|
diff_print_info *pi,
|
|
29
34
|
git_buf *out,
|
|
30
|
-
|
|
35
|
+
git_repository *repo,
|
|
31
36
|
git_diff_format_t format,
|
|
32
37
|
git_diff_line_cb cb,
|
|
33
38
|
void *payload)
|
|
34
39
|
{
|
|
35
|
-
pi->
|
|
36
|
-
pi->format = format;
|
|
40
|
+
pi->format = format;
|
|
37
41
|
pi->print_cb = cb;
|
|
38
|
-
pi->payload
|
|
39
|
-
pi->buf
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
pi->
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
pi->oid_strlen = diff->opts.id_abbrev;
|
|
48
|
-
else if (!diff || !diff->repo)
|
|
49
|
-
pi->oid_strlen = GIT_ABBREV_DEFAULT;
|
|
50
|
-
else if (git_repository__cvar(
|
|
51
|
-
&pi->oid_strlen, diff->repo, GIT_CVAR_ABBREV) < 0)
|
|
52
|
-
return -1;
|
|
42
|
+
pi->payload = payload;
|
|
43
|
+
pi->buf = out;
|
|
44
|
+
|
|
45
|
+
if (!pi->oid_strlen) {
|
|
46
|
+
if (!repo)
|
|
47
|
+
pi->oid_strlen = GIT_ABBREV_DEFAULT;
|
|
48
|
+
else if (git_repository__cvar(&pi->oid_strlen, repo, GIT_CVAR_ABBREV) < 0)
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
53
51
|
|
|
54
52
|
pi->oid_strlen += 1; /* for NUL byte */
|
|
55
53
|
|
|
56
|
-
if (pi->oid_strlen
|
|
57
|
-
pi->oid_strlen = 2;
|
|
58
|
-
else if (pi->oid_strlen > GIT_OID_HEXSZ + 1)
|
|
54
|
+
if (pi->oid_strlen > GIT_OID_HEXSZ + 1)
|
|
59
55
|
pi->oid_strlen = GIT_OID_HEXSZ + 1;
|
|
60
56
|
|
|
61
57
|
memset(&pi->line, 0, sizeof(pi->line));
|
|
62
58
|
pi->line.old_lineno = -1;
|
|
63
59
|
pi->line.new_lineno = -1;
|
|
64
|
-
pi->line.num_lines
|
|
60
|
+
pi->line.num_lines = 1;
|
|
65
61
|
|
|
66
62
|
return 0;
|
|
67
63
|
}
|
|
68
64
|
|
|
65
|
+
static int diff_print_info_init_fromdiff(
|
|
66
|
+
diff_print_info *pi,
|
|
67
|
+
git_buf *out,
|
|
68
|
+
git_diff *diff,
|
|
69
|
+
git_diff_format_t format,
|
|
70
|
+
git_diff_line_cb cb,
|
|
71
|
+
void *payload)
|
|
72
|
+
{
|
|
73
|
+
git_repository *repo = diff ? diff->repo : NULL;
|
|
74
|
+
|
|
75
|
+
memset(pi, 0, sizeof(diff_print_info));
|
|
76
|
+
|
|
77
|
+
pi->diff = diff;
|
|
78
|
+
|
|
79
|
+
if (diff) {
|
|
80
|
+
pi->flags = diff->opts.flags;
|
|
81
|
+
pi->oid_strlen = diff->opts.id_abbrev;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return diff_print_info_init__common(pi, out, repo, format, cb, payload);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static int diff_print_info_init_frompatch(
|
|
88
|
+
diff_print_info *pi,
|
|
89
|
+
git_buf *out,
|
|
90
|
+
git_patch *patch,
|
|
91
|
+
git_diff_format_t format,
|
|
92
|
+
git_diff_line_cb cb,
|
|
93
|
+
void *payload)
|
|
94
|
+
{
|
|
95
|
+
git_repository *repo = patch && patch->diff ? patch->diff->repo : NULL;
|
|
96
|
+
|
|
97
|
+
memset(pi, 0, sizeof(diff_print_info));
|
|
98
|
+
|
|
99
|
+
pi->diff = patch->diff;
|
|
100
|
+
|
|
101
|
+
pi->flags = patch->diff_opts.flags;
|
|
102
|
+
pi->oid_strlen = patch->diff_opts.id_abbrev;
|
|
103
|
+
|
|
104
|
+
pi->content_loaded = 1;
|
|
105
|
+
pi->ofile = &patch->ofile;
|
|
106
|
+
pi->nfile = &patch->nfile;
|
|
107
|
+
|
|
108
|
+
return diff_print_info_init__common(pi, out, repo, format, cb, payload);
|
|
109
|
+
}
|
|
110
|
+
|
|
69
111
|
static char diff_pick_suffix(int mode)
|
|
70
112
|
{
|
|
71
113
|
if (S_ISDIR(mode))
|
|
@@ -283,66 +325,21 @@ int git_diff_delta__format_file_header(
|
|
|
283
325
|
return git_buf_oom(out) ? -1 : 0;
|
|
284
326
|
}
|
|
285
327
|
|
|
286
|
-
static int
|
|
328
|
+
static int format_binary(
|
|
329
|
+
diff_print_info *pi,
|
|
330
|
+
git_diff_binary_t type,
|
|
331
|
+
const char *data,
|
|
332
|
+
size_t datalen,
|
|
333
|
+
size_t inflatedlen)
|
|
287
334
|
{
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
unsigned long delta_data_len, inflated_len;
|
|
292
|
-
const char *out_type = "literal";
|
|
293
|
-
char *scan, *end;
|
|
294
|
-
int error;
|
|
295
|
-
|
|
296
|
-
old_data = old ? git_blob_rawcontent(old) : NULL;
|
|
297
|
-
new_data = new ? git_blob_rawcontent(new) : NULL;
|
|
298
|
-
|
|
299
|
-
old_data_len = old ? git_blob_rawsize(old) : 0;
|
|
300
|
-
new_data_len = new ? git_blob_rawsize(new) : 0;
|
|
301
|
-
|
|
302
|
-
/* The git_delta function accepts unsigned long only */
|
|
303
|
-
if (!git__is_ulong(old_data_len) || !git__is_ulong(new_data_len))
|
|
304
|
-
return GIT_EBUFS;
|
|
305
|
-
|
|
306
|
-
out = &deflate;
|
|
307
|
-
inflated_len = (unsigned long)new_data_len;
|
|
308
|
-
|
|
309
|
-
if ((error = git_zstream_deflatebuf(
|
|
310
|
-
out, new_data, (size_t)new_data_len)) < 0)
|
|
311
|
-
goto done;
|
|
312
|
-
|
|
313
|
-
/* The git_delta function accepts unsigned long only */
|
|
314
|
-
if (!git__is_ulong((git_off_t)deflate.size)) {
|
|
315
|
-
error = GIT_EBUFS;
|
|
316
|
-
goto done;
|
|
317
|
-
}
|
|
335
|
+
const char *typename = type == GIT_DIFF_BINARY_DELTA ?
|
|
336
|
+
"delta" : "literal";
|
|
337
|
+
const char *scan, *end;
|
|
318
338
|
|
|
319
|
-
|
|
320
|
-
void *delta_data = git_delta(
|
|
321
|
-
old_data, (unsigned long)old_data_len,
|
|
322
|
-
new_data, (unsigned long)new_data_len,
|
|
323
|
-
&delta_data_len, (unsigned long)deflate.size);
|
|
324
|
-
|
|
325
|
-
if (delta_data) {
|
|
326
|
-
error = git_zstream_deflatebuf(
|
|
327
|
-
&delta, delta_data, (size_t)delta_data_len);
|
|
328
|
-
|
|
329
|
-
git__free(delta_data);
|
|
330
|
-
|
|
331
|
-
if (error < 0)
|
|
332
|
-
goto done;
|
|
333
|
-
|
|
334
|
-
if (delta.size < deflate.size) {
|
|
335
|
-
out = δ
|
|
336
|
-
out_type = "delta";
|
|
337
|
-
inflated_len = delta_data_len;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
git_buf_printf(pi->buf, "%s %lu\n", out_type, inflated_len);
|
|
339
|
+
git_buf_printf(pi->buf, "%s %lu\n", typename, inflatedlen);
|
|
343
340
|
pi->line.num_lines++;
|
|
344
341
|
|
|
345
|
-
for (scan =
|
|
342
|
+
for (scan = data, end = data + datalen; scan < end; ) {
|
|
346
343
|
size_t chunk_len = end - scan;
|
|
347
344
|
if (chunk_len > 52)
|
|
348
345
|
chunk_len = 52;
|
|
@@ -355,51 +352,74 @@ static int print_binary_hunk(diff_print_info *pi, git_blob *old, git_blob *new)
|
|
|
355
352
|
git_buf_encode_base85(pi->buf, scan, chunk_len);
|
|
356
353
|
git_buf_putc(pi->buf, '\n');
|
|
357
354
|
|
|
358
|
-
if (git_buf_oom(pi->buf))
|
|
359
|
-
|
|
360
|
-
goto done;
|
|
361
|
-
}
|
|
355
|
+
if (git_buf_oom(pi->buf))
|
|
356
|
+
return -1;
|
|
362
357
|
|
|
363
358
|
scan += chunk_len;
|
|
364
359
|
pi->line.num_lines++;
|
|
365
360
|
}
|
|
366
361
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
git_buf_free(&delta);
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
370
364
|
|
|
371
|
-
|
|
365
|
+
static int diff_print_load_content(
|
|
366
|
+
diff_print_info *pi,
|
|
367
|
+
git_diff_delta *delta)
|
|
368
|
+
{
|
|
369
|
+
git_diff_file_content *ofile, *nfile;
|
|
370
|
+
int error;
|
|
371
|
+
|
|
372
|
+
assert(pi->diff);
|
|
373
|
+
|
|
374
|
+
ofile = git__calloc(1, sizeof(git_diff_file_content));
|
|
375
|
+
nfile = git__calloc(1, sizeof(git_diff_file_content));
|
|
376
|
+
|
|
377
|
+
GITERR_CHECK_ALLOC(ofile);
|
|
378
|
+
GITERR_CHECK_ALLOC(nfile);
|
|
379
|
+
|
|
380
|
+
if ((error = git_diff_file_content__init_from_diff(
|
|
381
|
+
ofile, pi->diff, delta, true)) < 0 ||
|
|
382
|
+
(error = git_diff_file_content__init_from_diff(
|
|
383
|
+
nfile, pi->diff, delta, true)) < 0) {
|
|
384
|
+
|
|
385
|
+
git__free(ofile);
|
|
386
|
+
git__free(nfile);
|
|
387
|
+
return error;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
pi->content_loaded = 1;
|
|
391
|
+
pi->content_allocated = 1;
|
|
392
|
+
pi->ofile = ofile;
|
|
393
|
+
pi->nfile = nfile;
|
|
394
|
+
|
|
395
|
+
return 0;
|
|
372
396
|
}
|
|
373
397
|
|
|
374
|
-
/* git diff --binary 8d7523f~2 8d7523f~1 */
|
|
375
398
|
static int diff_print_patch_file_binary(
|
|
376
|
-
diff_print_info *pi,
|
|
377
|
-
const char *
|
|
399
|
+
diff_print_info *pi, git_diff_delta *delta,
|
|
400
|
+
const char *old_pfx, const char *new_pfx,
|
|
401
|
+
const git_diff_binary *binary)
|
|
378
402
|
{
|
|
379
|
-
git_blob *old = NULL, *new = NULL;
|
|
380
|
-
const git_oid *old_id, *new_id;
|
|
381
|
-
int error;
|
|
382
403
|
size_t pre_binary_size;
|
|
404
|
+
int error;
|
|
383
405
|
|
|
384
406
|
if ((pi->flags & GIT_DIFF_SHOW_BINARY) == 0)
|
|
385
407
|
goto noshow;
|
|
386
408
|
|
|
409
|
+
if (!pi->content_loaded &&
|
|
410
|
+
(error = diff_print_load_content(pi, delta)) < 0)
|
|
411
|
+
return error;
|
|
412
|
+
|
|
387
413
|
pre_binary_size = pi->buf->size;
|
|
388
414
|
git_buf_printf(pi->buf, "GIT binary patch\n");
|
|
389
415
|
pi->line.num_lines++;
|
|
390
416
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (old_id && (error = git_blob_lookup(&old, pi->diff->repo, old_id)) < 0)
|
|
395
|
-
goto done;
|
|
396
|
-
if (new_id && (error = git_blob_lookup(&new, pi->diff->repo,new_id)) < 0)
|
|
397
|
-
goto done;
|
|
398
|
-
|
|
399
|
-
if ((error = print_binary_hunk(pi, old, new)) < 0 ||
|
|
417
|
+
if ((error = format_binary(pi, binary->new_file.type, binary->new_file.data,
|
|
418
|
+
binary->new_file.datalen, binary->new_file.inflatedlen)) < 0 ||
|
|
400
419
|
(error = git_buf_putc(pi->buf, '\n')) < 0 ||
|
|
401
|
-
(error =
|
|
402
|
-
|
|
420
|
+
(error = format_binary(pi, binary->old_file.type, binary->old_file.data,
|
|
421
|
+
binary->old_file.datalen, binary->old_file.inflatedlen)) < 0) {
|
|
422
|
+
|
|
403
423
|
if (error == GIT_EBUFS) {
|
|
404
424
|
giterr_clear();
|
|
405
425
|
git_buf_truncate(pi->buf, pre_binary_size);
|
|
@@ -408,17 +428,12 @@ static int diff_print_patch_file_binary(
|
|
|
408
428
|
}
|
|
409
429
|
|
|
410
430
|
pi->line.num_lines++;
|
|
411
|
-
|
|
412
|
-
done:
|
|
413
|
-
git_blob_free(old);
|
|
414
|
-
git_blob_free(new);
|
|
415
|
-
|
|
416
431
|
return error;
|
|
417
432
|
|
|
418
433
|
noshow:
|
|
419
434
|
pi->line.num_lines = 1;
|
|
420
435
|
return diff_delta_format_with_paths(
|
|
421
|
-
pi->buf, delta,
|
|
436
|
+
pi->buf, delta, old_pfx, new_pfx,
|
|
422
437
|
"Binary files %s%s and %s%s differ\n");
|
|
423
438
|
}
|
|
424
439
|
|
|
@@ -432,7 +447,8 @@ static int diff_print_patch_file(
|
|
|
432
447
|
const char *newpfx =
|
|
433
448
|
pi->diff ? pi->diff->opts.new_prefix : DIFF_NEW_PREFIX_DEFAULT;
|
|
434
449
|
|
|
435
|
-
bool binary =
|
|
450
|
+
bool binary = (delta->flags & GIT_DIFF_FLAG_BINARY) ||
|
|
451
|
+
(pi->flags & GIT_DIFF_FORCE_BINARY);
|
|
436
452
|
bool show_binary = !!(pi->flags & GIT_DIFF_SHOW_BINARY);
|
|
437
453
|
int oid_strlen = binary && show_binary ?
|
|
438
454
|
GIT_OID_HEXSZ + 1 : pi->oid_strlen;
|
|
@@ -455,19 +471,29 @@ static int diff_print_patch_file(
|
|
|
455
471
|
pi->line.content = git_buf_cstr(pi->buf);
|
|
456
472
|
pi->line.content_len = git_buf_len(pi->buf);
|
|
457
473
|
|
|
458
|
-
|
|
459
|
-
|
|
474
|
+
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
|
|
475
|
+
}
|
|
460
476
|
|
|
461
|
-
|
|
462
|
-
|
|
477
|
+
static int diff_print_patch_binary(
|
|
478
|
+
const git_diff_delta *delta,
|
|
479
|
+
const git_diff_binary *binary,
|
|
480
|
+
void *data)
|
|
481
|
+
{
|
|
482
|
+
diff_print_info *pi = data;
|
|
483
|
+
const char *old_pfx =
|
|
484
|
+
pi->diff ? pi->diff->opts.old_prefix : DIFF_OLD_PREFIX_DEFAULT;
|
|
485
|
+
const char *new_pfx =
|
|
486
|
+
pi->diff ? pi->diff->opts.new_prefix : DIFF_NEW_PREFIX_DEFAULT;
|
|
487
|
+
int error;
|
|
463
488
|
|
|
464
489
|
git_buf_clear(pi->buf);
|
|
465
490
|
|
|
466
|
-
if ((error = diff_print_patch_file_binary(
|
|
491
|
+
if ((error = diff_print_patch_file_binary(
|
|
492
|
+
pi, (git_diff_delta *)delta, old_pfx, new_pfx, binary)) < 0)
|
|
467
493
|
return error;
|
|
468
494
|
|
|
469
|
-
pi->line.origin
|
|
470
|
-
pi->line.content
|
|
495
|
+
pi->line.origin = GIT_DIFF_LINE_BINARY;
|
|
496
|
+
pi->line.content = git_buf_cstr(pi->buf);
|
|
471
497
|
pi->line.content_len = git_buf_len(pi->buf);
|
|
472
498
|
|
|
473
499
|
return pi->print_cb(delta, NULL, &pi->line, pi->payload);
|
|
@@ -515,12 +541,14 @@ int git_diff_print(
|
|
|
515
541
|
git_buf buf = GIT_BUF_INIT;
|
|
516
542
|
diff_print_info pi;
|
|
517
543
|
git_diff_file_cb print_file = NULL;
|
|
544
|
+
git_diff_binary_cb print_binary = NULL;
|
|
518
545
|
git_diff_hunk_cb print_hunk = NULL;
|
|
519
546
|
git_diff_line_cb print_line = NULL;
|
|
520
547
|
|
|
521
548
|
switch (format) {
|
|
522
549
|
case GIT_DIFF_FORMAT_PATCH:
|
|
523
550
|
print_file = diff_print_patch_file;
|
|
551
|
+
print_binary = diff_print_patch_binary;
|
|
524
552
|
print_hunk = diff_print_patch_hunk;
|
|
525
553
|
print_line = diff_print_patch_line;
|
|
526
554
|
break;
|
|
@@ -541,16 +569,18 @@ int git_diff_print(
|
|
|
541
569
|
return -1;
|
|
542
570
|
}
|
|
543
571
|
|
|
544
|
-
if (!(error =
|
|
545
|
-
&pi, &buf, diff, format, print_cb, payload)))
|
|
546
|
-
{
|
|
572
|
+
if (!(error = diff_print_info_init_fromdiff(
|
|
573
|
+
&pi, &buf, diff, format, print_cb, payload))) {
|
|
547
574
|
error = git_diff_foreach(
|
|
548
|
-
diff, print_file, print_hunk, print_line, &pi);
|
|
575
|
+
diff, print_file, print_binary, print_hunk, print_line, &pi);
|
|
549
576
|
|
|
550
577
|
if (error) /* make sure error message is set */
|
|
551
578
|
giterr_set_after_callback_function(error, "git_diff_print");
|
|
552
579
|
}
|
|
553
580
|
|
|
581
|
+
git__free(pi.nfile);
|
|
582
|
+
git__free(pi.ofile);
|
|
583
|
+
|
|
554
584
|
git_buf_free(&buf);
|
|
555
585
|
|
|
556
586
|
return error;
|
|
@@ -568,13 +598,13 @@ int git_patch_print(
|
|
|
568
598
|
|
|
569
599
|
assert(patch && print_cb);
|
|
570
600
|
|
|
571
|
-
if (!(error =
|
|
572
|
-
&pi, &temp,
|
|
601
|
+
if (!(error = diff_print_info_init_frompatch(
|
|
602
|
+
&pi, &temp, patch,
|
|
573
603
|
GIT_DIFF_FORMAT_PATCH, print_cb, payload)))
|
|
574
604
|
{
|
|
575
605
|
error = git_patch__invoke_callbacks(
|
|
576
|
-
patch, diff_print_patch_file,
|
|
577
|
-
diff_print_patch_line, &pi);
|
|
606
|
+
patch, diff_print_patch_file, diff_print_patch_binary,
|
|
607
|
+
diff_print_patch_hunk, diff_print_patch_line, &pi);
|
|
578
608
|
|
|
579
609
|
if (error) /* make sure error message is set */
|
|
580
610
|
giterr_set_after_callback_function(error, "git_patch_print");
|