Skip to content

Commit 4e970f6

Browse files
committed
xdiff - from git 2.40.1
This is the version of the xdiff file differential library used by git. This project began life as LibXDiff by Davide Libenzi: http://www.xmailserver.org/xdiff-lib.html, but has been modified to suit the git project's needs. Some unnecessary functionality has been removed and some new functionality has been added. Fundamentally, this library is _meant for git_ but has been extracted into a standalone library for compatibility with other git-like projects, for example, libgit2 (https://github.com/libgit2/libgit2). This repository tracks the git project as an upstream, and makes only minimal (with a goal of _zero_) changes to xdiff itself.
0 parents  commit 4e970f6

21 files changed

+4631
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.5.1)
2+
3+
project(xdiff VERSION "0.1" LANGUAGES C)
4+
5+
file(GLOB SRC "*.c" "*.h")
6+
list(SORT SRC)
7+
8+
add_library(xdiff OBJECT ${SRC})

COPYING

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
LibXDiff by Davide Libenzi ( File Differential Library )
2+
Copyright (C) 2003 Davide Libenzi
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, see
16+
<http://www.gnu.org/licenses/>.
17+
18+
Davide Libenzi <[email protected]>

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
xdiff (via git)
2+
===============
3+
4+
This is the version of the xdiff file differential library used by [git](https://github.com/git/git).
5+
6+
This project began life as [LibXDiff](http://www.xmailserver.org/xdiff-lib.html) by Davide Libenzi, but has been modified to suit the git project's needs. Some unnecessary functionality has been removed and some new functionality has been added.
7+
8+
Fundamentally, this library is _meant for git_ but has been extracted into a standalone library for compatibility with other git-like projects, for example, [libgit2](https://github.com/libgit2/libgit2).
9+
10+
This repository tracks the git project as an upstream, and makes only minimal (with a goal of _zero_) changes to xdiff itself.
11+
12+
Inclusion in your application
13+
-----------------------------
14+
15+
Although this project _is used by git_, it has no git-specific code explicitly inside it. git -- and other callers -- add application-specific code through the `git-xdiff.h` file. For example, if your application uses a custom `malloc`, then you can configure it in the `git-xdiff.h` file.
16+
17+
Contributions
18+
-------------
19+
20+
Contributions to improve the build or compatibility of this library _as a standalone work of art_ are welcome. Contributions that change the diff functionality, however, _[should be made to git project itself](https://github.com/git/git/blob/master/Documentation/SubmittingPatches)_. (Once those changes land in git, thehy will be included here.)
21+
22+
Credits
23+
-------
24+
25+
Many thanks to Davide Libenzi, the original author of LibXDiff, as well as the numerous contributors to git and libgit2 who have improved xdiff over the years.

git-2.40.1.patch

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
diff --git a/git-xdiff.h b/git-xdiff.h
2+
new file mode 100644
3+
index 0000000..d812d0d
4+
--- /dev/null
5+
+++ b/git-xdiff.h
6+
@@ -0,0 +1,63 @@
7+
+/*
8+
+ * This file provides the necessary indirection between xdiff and
9+
+ * the calling application. Callers can use this file to avoid modifying
10+
+ * xdiff itself with application-specific code, while still using their
11+
+ * bespoke runtime. For example: callers may wish to use a specific
12+
+ * `malloc` function, and can do so by defining `xdl_malloc` in this
13+
+ * file.
14+
+ */
15+
+
16+
+#ifndef __GIT_XDIFF_H__
17+
+#define __GIT_XDIFF_H__
18+
+
19+
+#include <ctype.h>
20+
+#include <limits.h>
21+
+#include <stdlib.h>
22+
+#include <stdint.h>
23+
+#include <stdio.h>
24+
+#include <string.h>
25+
+#include <regex.h>
26+
+
27+
+/* Work around C90-conformance issues */
28+
+#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
29+
+# if defined(_MSC_VER)
30+
+# define inline __inline
31+
+# elif defined(__GNUC__)
32+
+# define inline __inline__
33+
+# else
34+
+# define inline
35+
+# endif
36+
+#endif
37+
+
38+
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \
39+
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= (4 << 16) + 5)
40+
+# define XDL_UNUSED __attribute__((unused)) \
41+
+ __attribute__((deprecated ("parameter declared as UNUSED")))
42+
+#elif defined(__GNUC__)
43+
+# define XDL_UNUSED __attribute__((unused)) \
44+
+ __attribute__((deprecated))
45+
+#else
46+
+# define XDL_UNUSED
47+
+#endif
48+
+
49+
+#define xdl_malloc(x) malloc(x)
50+
+#define xdl_calloc(n, sz) calloc(n, sz)
51+
+#define xdl_free(ptr) free(ptr)
52+
+#define xdl_realloc(ptr, x) realloc(ptr, x)
53+
+
54+
+#define XDL_BUG(msg) do { fprintf(stderr, "fatal: %s\n", msg); exit(128); } while(0)
55+
+
56+
+#define xdl_regex_t regex_t
57+
+#define xdl_regmatch_t regmatch_t
58+
+
59+
+inline int xdl_regexec_buf(
60+
+ const xdl_regex_t *preg, const char *buf, size_t size,
61+
+ size_t nmatch, xdl_regmatch_t pmatch[], int eflags)
62+
+{
63+
+ pmatch[0].rm_so = 0;
64+
+ pmatch[0].rm_eo = size;
65+
+
66+
+ return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
67+
+}
68+
+
69+
+#endif
70+
diff --git a/xdiff.h b/xdiff.h
71+
index bb56b23..fb47f63 100644
72+
--- a/xdiff.h
73+
+++ b/xdiff.h
74+
@@ -27,6 +27,8 @@
75+
extern "C" {
76+
#endif /* #ifdef __cplusplus */
77+
78+
+#include "git-xdiff.h"
79+
+
80+
/* xpparm_t.flags */
81+
#define XDF_NEED_MINIMAL (1 << 0)
82+
83+
@@ -82,7 +84,7 @@ typedef struct s_xpparam {
84+
unsigned long flags;
85+
86+
/* -I<regex> */
87+
- regex_t **ignore_regex;
88+
+ xdl_regex_t **ignore_regex;
89+
size_t ignore_regex_nr;
90+
91+
/* See Documentation/diff-options.txt. */
92+
@@ -119,11 +121,6 @@ typedef struct s_bdiffparam {
93+
} bdiffparam_t;
94+
95+
96+
-#define xdl_malloc(x) xmalloc(x)
97+
-#define xdl_calloc(n, sz) xcalloc(n, sz)
98+
-#define xdl_free(ptr) free(ptr)
99+
-#define xdl_realloc(ptr,x) xrealloc(ptr,x)
100+
-
101+
void *xdl_mmfile_first(mmfile_t *mmf, long *size);
102+
long xdl_mmfile_size(mmfile_t *mmf);
103+
104+
diff --git a/xdiffi.c b/xdiffi.c
105+
index 344c2df..ea36143 100644
106+
--- a/xdiffi.c
107+
+++ b/xdiffi.c
108+
@@ -833,7 +833,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
109+
/* Shift the group backward as much as possible: */
110+
while (!group_slide_up(xdf, &g))
111+
if (group_previous(xdfo, &go))
112+
- BUG("group sync broken sliding up");
113+
+ XDL_BUG("group sync broken sliding up");
114+
115+
/*
116+
* This is this highest that this group can be shifted.
117+
@@ -849,7 +849,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
118+
if (group_slide_down(xdf, &g))
119+
break;
120+
if (group_next(xdfo, &go))
121+
- BUG("group sync broken sliding down");
122+
+ XDL_BUG("group sync broken sliding down");
123+
124+
if (go.end > go.start)
125+
end_matching_other = g.end;
126+
@@ -874,9 +874,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
127+
*/
128+
while (go.end == go.start) {
129+
if (group_slide_up(xdf, &g))
130+
- BUG("match disappeared");
131+
+ XDL_BUG("match disappeared");
132+
if (group_previous(xdfo, &go))
133+
- BUG("group sync broken sliding to match");
134+
+ XDL_BUG("group sync broken sliding to match");
135+
}
136+
} else if (flags & XDF_INDENT_HEURISTIC) {
137+
/*
138+
@@ -917,9 +917,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
139+
140+
while (g.end > best_shift) {
141+
if (group_slide_up(xdf, &g))
142+
- BUG("best shift unreached");
143+
+ XDL_BUG("best shift unreached");
144+
if (group_previous(xdfo, &go))
145+
- BUG("group sync broken sliding to blank line");
146+
+ XDL_BUG("group sync broken sliding to blank line");
147+
}
148+
}
149+
150+
@@ -928,11 +928,11 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
151+
if (group_next(xdf, &g))
152+
break;
153+
if (group_next(xdfo, &go))
154+
- BUG("group sync broken moving to next group");
155+
+ XDL_BUG("group sync broken moving to next group");
156+
}
157+
158+
if (!group_next(xdfo, &go))
159+
- BUG("group sync broken at end of file");
160+
+ XDL_BUG("group sync broken at end of file");
161+
162+
return 0;
163+
}
164+
@@ -973,7 +973,7 @@ void xdl_free_script(xdchange_t *xscr) {
165+
}
166+
}
167+
168+
-static int xdl_call_hunk_func(xdfenv_t *xe UNUSED, xdchange_t *xscr, xdemitcb_t *ecb,
169+
+static int xdl_call_hunk_func(xdfenv_t *xe XDL_UNUSED, xdchange_t *xscr, xdemitcb_t *ecb,
170+
xdemitconf_t const *xecfg)
171+
{
172+
xdchange_t *xch, *xche;
173+
@@ -1012,11 +1012,11 @@ static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags)
174+
}
175+
176+
static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) {
177+
- regmatch_t regmatch;
178+
+ xdl_regmatch_t regmatch;
179+
int i;
180+
181+
for (i = 0; i < xpp->ignore_regex_nr; i++)
182+
- if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1,
183+
+ if (!xdl_regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1,
184+
&regmatch, 0))
185+
return 1;
186+
187+
diff --git a/xinclude.h b/xinclude.h
188+
index a4285ac..75db1d8 100644
189+
--- a/xinclude.h
190+
+++ b/xinclude.h
191+
@@ -23,7 +23,7 @@
192+
#if !defined(XINCLUDE_H)
193+
#define XINCLUDE_H
194+
195+
-#include "git-compat-util.h"
196+
+#include "git-xdiff.h"
197+
#include "xmacros.h"
198+
#include "xdiff.h"
199+
#include "xtypes.h"

git-xdiff.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file provides the necessary indirection between xdiff and
3+
* the calling application. Callers can use this file to avoid modifying
4+
* xdiff itself with application-specific code, while still using their
5+
* bespoke runtime. For example: callers may wish to use a specific
6+
* `malloc` function, and can do so by defining `xdl_malloc` in this
7+
* file.
8+
*/
9+
10+
#ifndef __GIT_XDIFF_H__
11+
#define __GIT_XDIFF_H__
12+
13+
#include <ctype.h>
14+
#include <limits.h>
15+
#include <stdlib.h>
16+
#include <stdint.h>
17+
#include <stdio.h>
18+
#include <string.h>
19+
#include <regex.h>
20+
21+
/* Work around C90-conformance issues */
22+
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
23+
# if defined(_MSC_VER)
24+
# define inline __inline
25+
# elif defined(__GNUC__)
26+
# define inline __inline__
27+
# else
28+
# define inline
29+
# endif
30+
#endif
31+
32+
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \
33+
((__GNUC__ << 16) + __GNUC_MINOR__ >= (4 << 16) + 5)
34+
# define XDL_UNUSED __attribute__((unused)) \
35+
__attribute__((deprecated ("parameter declared as UNUSED")))
36+
#elif defined(__GNUC__)
37+
# define XDL_UNUSED __attribute__((unused)) \
38+
__attribute__((deprecated))
39+
#else
40+
# define XDL_UNUSED
41+
#endif
42+
43+
#define xdl_malloc(x) malloc(x)
44+
#define xdl_calloc(n, sz) calloc(n, sz)
45+
#define xdl_free(ptr) free(ptr)
46+
#define xdl_realloc(ptr, x) realloc(ptr, x)
47+
48+
#define XDL_BUG(msg) do { fprintf(stderr, "fatal: %s\n", msg); exit(128); } while(0)
49+
50+
#define xdl_regex_t regex_t
51+
#define xdl_regmatch_t regmatch_t
52+
53+
inline int xdl_regexec_buf(
54+
const xdl_regex_t *preg, const char *buf, size_t size,
55+
size_t nmatch, xdl_regmatch_t pmatch[], int eflags)
56+
{
57+
pmatch[0].rm_so = 0;
58+
pmatch[0].rm_eo = size;
59+
60+
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
61+
}
62+
63+
#endif

0 commit comments

Comments
 (0)