Skip to content

Commit 1458fb5

Browse files
committed
xdiff: include new xdiff from git
Update to the xdiff used in git v2.35.0, with updates to our build configuration to ignore the sort of warnings that we normally care about (signed/unsigned mismatch, unused, etc.) Any git-specific abstraction bits are now redefined for our use in `git-xdiff.h`. It is a (wildly optimistic) hope that we can use that indirection layer to standardize on a shared xdiff implementation.
1 parent 12c2eef commit 1458fb5

File tree

16 files changed

+494
-401
lines changed

16 files changed

+494
-401
lines changed

src/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,17 @@ endif()
206206
# errors for the xdiff sources until we've sorted them out
207207
if(MSVC)
208208
set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-)
209+
set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS -WX-)
210+
set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS -WX-)
211+
set_source_files_properties(xdiff/xmerge.c PROPERTIES COMPILE_FLAGS -WX-)
209212
set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-)
213+
set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS -WX-)
214+
else()
215+
set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter")
216+
set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter")
217+
set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
218+
set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
219+
set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
210220
endif()
211221

212222
# Determine architecture of the machine

src/blame_git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void fill_origin_blob(git_blame__origin *o, mmfile_t *file)
393393
memset(file, 0, sizeof(*file));
394394
if (o->blob) {
395395
file->ptr = (char*)git_blob_rawcontent(o->blob);
396-
file->size = (size_t)git_blob_rawsize(o->blob);
396+
file->size = (long)git_blob_rawsize(o->blob);
397397
}
398398
}
399399

src/diff_xdiff.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,9 @@ static int git_xdiff(git_patch_generated_output *output, git_patch_generated *pa
218218
* updates are needed to xo->params.flags
219219
*/
220220

221-
git_patch_generated_old_data(&info.xd_old_data.ptr, &info.xd_old_data.size, patch);
222-
git_patch_generated_new_data(&info.xd_new_data.ptr, &info.xd_new_data.size, patch);
223-
224-
if (info.xd_old_data.size > GIT_XDIFF_MAX_SIZE ||
225-
info.xd_new_data.size > GIT_XDIFF_MAX_SIZE) {
226-
git_error_set(GIT_ERROR_INVALID, "files too large for diff");
221+
if (git_patch_generated_old_data(&info.xd_old_data.ptr, &info.xd_old_data.size, patch) < 0 ||
222+
git_patch_generated_new_data(&info.xd_new_data.ptr, &info.xd_new_data.size, patch) < 0)
227223
return -1;
228-
}
229224

230225
xdl_diff(&info.xd_old_data, &info.xd_new_data,
231226
&xo->params, &xo->config, &xo->callback);
@@ -261,5 +256,5 @@ void git_xdiff_init(git_xdiff_output *xo, const git_diff_options *opts)
261256
if (flags & GIT_DIFF_IGNORE_BLANK_LINES)
262257
xo->params.flags |= XDF_IGNORE_BLANK_LINES;
263258

264-
xo->callback.outf = git_xdiff_cb;
259+
xo->callback.out_line = git_xdiff_cb;
265260
}

src/merge_file.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,30 @@ static int merge_file__xdiff(
8686

8787
memset(&xmparam, 0x0, sizeof(xmparam_t));
8888

89+
if (ours->size > LONG_MAX ||
90+
theirs->size > LONG_MAX ||
91+
(ancestor && ancestor->size > LONG_MAX)) {
92+
git_error_set(GIT_ERROR_MERGE, "failed to merge files");
93+
error = -1;
94+
goto done;
95+
}
96+
8997
if (ancestor) {
9098
xmparam.ancestor = (options.ancestor_label) ?
9199
options.ancestor_label : ancestor->path;
92100
ancestor_mmfile.ptr = (char *)ancestor->ptr;
93-
ancestor_mmfile.size = ancestor->size;
101+
ancestor_mmfile.size = (long)ancestor->size;
94102
}
95103

96104
xmparam.file1 = (options.our_label) ?
97105
options.our_label : ours->path;
98106
our_mmfile.ptr = (char *)ours->ptr;
99-
our_mmfile.size = ours->size;
107+
our_mmfile.size = (long)ours->size;
100108

101109
xmparam.file2 = (options.their_label) ?
102110
options.their_label : theirs->path;
103111
their_mmfile.ptr = (char *)theirs->ptr;
104-
their_mmfile.size = theirs->size;
112+
their_mmfile.size = (long)theirs->size;
105113

106114
if (options.favor == GIT_MERGE_FILE_FAVOR_OURS)
107115
xmparam.favor = XDL_MERGE_FAVOR_OURS;

src/patch_generate.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,18 +750,34 @@ git_diff_driver *git_patch_generated_driver(git_patch_generated *patch)
750750
return patch->ofile.driver;
751751
}
752752

753-
void git_patch_generated_old_data(
754-
char **ptr, size_t *len, git_patch_generated *patch)
753+
int git_patch_generated_old_data(
754+
char **ptr, long *len, git_patch_generated *patch)
755755
{
756+
if (patch->ofile.map.len > LONG_MAX ||
757+
patch->ofile.map.len > GIT_XDIFF_MAX_SIZE) {
758+
git_error_set(GIT_ERROR_INVALID, "files too large for diff");
759+
return -1;
760+
}
761+
756762
*ptr = patch->ofile.map.data;
757-
*len = patch->ofile.map.len;
763+
*len = (long)patch->ofile.map.len;
764+
765+
return 0;
758766
}
759767

760-
void git_patch_generated_new_data(
761-
char **ptr, size_t *len, git_patch_generated *patch)
768+
int git_patch_generated_new_data(
769+
char **ptr, long *len, git_patch_generated *patch)
762770
{
771+
if (patch->ofile.map.len > LONG_MAX ||
772+
patch->ofile.map.len > GIT_XDIFF_MAX_SIZE) {
773+
git_error_set(GIT_ERROR_INVALID, "files too large for diff");
774+
return -1;
775+
}
776+
763777
*ptr = patch->nfile.map.data;
764-
*len = patch->nfile.map.len;
778+
*len = (long)patch->nfile.map.len;
779+
780+
return 0;
765781
}
766782

767783
static int patch_generated_file_cb(

src/patch_generate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ typedef struct git_patch_generated git_patch_generated;
3939

4040
extern git_diff_driver *git_patch_generated_driver(git_patch_generated *);
4141

42-
extern void git_patch_generated_old_data(
43-
char **, size_t *, git_patch_generated *);
44-
extern void git_patch_generated_new_data(
45-
char **, size_t *, git_patch_generated *);
42+
extern int git_patch_generated_old_data(
43+
char **, long *, git_patch_generated *);
44+
extern int git_patch_generated_new_data(
45+
char **, long *, git_patch_generated *);
4646
extern int git_patch_generated_from_diff(
4747
git_patch **, git_diff *, size_t);
4848

src/xdiff/git-xdiff.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
8+
/*
9+
* This file provides the necessary indirection between xdiff and
10+
* libgit2. libgit2-specific functionality should live here, so
11+
* that git and libgit2 can share a common xdiff implementation.
12+
*/
13+
14+
#ifndef INCLUDE_git_xdiff_h__
15+
#define INCLUDE_git_xdiff_h__
16+
17+
#include "regexp.h"
18+
19+
#define xdl_malloc(x) git__malloc(x)
20+
#define xdl_free(ptr) git__free(ptr)
21+
#define xdl_realloc(ptr, x) git__realloc(ptr, x)
22+
23+
#define XDL_BUG(msg) GIT_ASSERT(msg)
24+
25+
#define xdl_regex_t git_regexp
26+
#define xdl_regmatch_t git_regmatch
27+
28+
GIT_INLINE(int) xdl_regexec_buf(
29+
const xdl_regex_t *preg, const char *buf, size_t size,
30+
size_t nmatch, xdl_regmatch_t pmatch[], int eflags)
31+
{
32+
GIT_UNUSED(preg);
33+
GIT_UNUSED(buf);
34+
GIT_UNUSED(size);
35+
GIT_UNUSED(nmatch);
36+
GIT_UNUSED(pmatch);
37+
GIT_UNUSED(eflags);
38+
GIT_ASSERT("not implemented");
39+
return -1;
40+
}
41+
42+
#endif

src/xdiff/xdiff.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#if !defined(XDIFF_H)
2424
#define XDIFF_H
2525

26+
#include "git-xdiff.h"
27+
2628
#ifdef __cplusplus
2729
extern "C" {
2830
#endif /* #ifdef __cplusplus */
@@ -50,16 +52,9 @@ extern "C" {
5052

5153
/* xdemitconf_t.flags */
5254
#define XDL_EMIT_FUNCNAMES (1 << 0)
55+
#define XDL_EMIT_NO_HUNK_HDR (1 << 1)
5356
#define XDL_EMIT_FUNCCONTEXT (1 << 2)
5457

55-
#define XDL_MMB_READONLY (1 << 0)
56-
57-
#define XDL_MMF_ATOMIC (1 << 0)
58-
59-
#define XDL_BDOP_INS 1
60-
#define XDL_BDOP_CPY 2
61-
#define XDL_BDOP_INSB 3
62-
6358
/* merge simplification levels */
6459
#define XDL_MERGE_MINIMAL 0
6560
#define XDL_MERGE_EAGER 1
@@ -73,28 +68,37 @@ extern "C" {
7368

7469
/* merge output styles */
7570
#define XDL_MERGE_DIFF3 1
71+
#define XDL_MERGE_ZEALOUS_DIFF3 2
7672

7773
typedef struct s_mmfile {
7874
char *ptr;
79-
size_t size;
75+
long size;
8076
} mmfile_t;
8177

8278
typedef struct s_mmbuffer {
8379
char *ptr;
84-
size_t size;
80+
long size;
8581
} mmbuffer_t;
8682

8783
typedef struct s_xpparam {
8884
unsigned long flags;
8985

86+
/* -I<regex> */
87+
xdl_regex_t **ignore_regex;
88+
size_t ignore_regex_nr;
89+
9090
/* See Documentation/diff-options.txt. */
9191
char **anchors;
9292
size_t anchors_nr;
9393
} xpparam_t;
9494

9595
typedef struct s_xdemitcb {
9696
void *priv;
97-
int (*outf)(void *, mmbuffer_t *, int);
97+
int (*out_hunk)(void *,
98+
long old_begin, long old_nr,
99+
long new_begin, long new_nr,
100+
const char *func, long funclen);
101+
int (*out_line)(void *, mmbuffer_t *, int);
98102
} xdemitcb_t;
99103

100104
typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv);
@@ -117,10 +121,6 @@ typedef struct s_bdiffparam {
117121
} bdiffparam_t;
118122

119123

120-
#define xdl_malloc(x) git__malloc(x)
121-
#define xdl_free(ptr) git__free(ptr)
122-
#define xdl_realloc(ptr,x) git__realloc(ptr,x)
123-
124124
void *xdl_mmfile_first(mmfile_t *mmf, long *size);
125125
long xdl_mmfile_size(mmfile_t *mmf);
126126

0 commit comments

Comments
 (0)