-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
0 parents
commit 4e970f6
Showing
21 changed files
with
4,631 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.5.1) | ||
|
||
project(xdiff VERSION "0.1" LANGUAGES C) | ||
|
||
file(GLOB SRC "*.c" "*.h") | ||
list(SORT SRC) | ||
|
||
add_library(xdiff OBJECT ${SRC}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
LibXDiff by Davide Libenzi ( File Differential Library ) | ||
Copyright (C) 2003 Davide Libenzi | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, see | ||
<http://www.gnu.org/licenses/>. | ||
|
||
Davide Libenzi <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
xdiff (via git) | ||
=============== | ||
|
||
This is the version of the xdiff file differential library used by [git](https://github.com/git/git). | ||
|
||
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. | ||
|
||
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. | ||
|
||
Inclusion in your application | ||
----------------------------- | ||
|
||
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. | ||
|
||
Contributions | ||
------------- | ||
|
||
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.) | ||
|
||
Credits | ||
------- | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
diff --git a/git-xdiff.h b/git-xdiff.h | ||
new file mode 100644 | ||
index 0000000..d812d0d | ||
--- /dev/null | ||
+++ b/git-xdiff.h | ||
@@ -0,0 +1,63 @@ | ||
+/* | ||
+ * This file provides the necessary indirection between xdiff and | ||
+ * the calling application. Callers can use this file to avoid modifying | ||
+ * xdiff itself with application-specific code, while still using their | ||
+ * bespoke runtime. For example: callers may wish to use a specific | ||
+ * `malloc` function, and can do so by defining `xdl_malloc` in this | ||
+ * file. | ||
+ */ | ||
+ | ||
+#ifndef __GIT_XDIFF_H__ | ||
+#define __GIT_XDIFF_H__ | ||
+ | ||
+#include <ctype.h> | ||
+#include <limits.h> | ||
+#include <stdlib.h> | ||
+#include <stdint.h> | ||
+#include <stdio.h> | ||
+#include <string.h> | ||
+#include <regex.h> | ||
+ | ||
+/* Work around C90-conformance issues */ | ||
+#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) | ||
+# if defined(_MSC_VER) | ||
+# define inline __inline | ||
+# elif defined(__GNUC__) | ||
+# define inline __inline__ | ||
+# else | ||
+# define inline | ||
+# endif | ||
+#endif | ||
+ | ||
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ | ||
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= (4 << 16) + 5) | ||
+# define XDL_UNUSED __attribute__((unused)) \ | ||
+ __attribute__((deprecated ("parameter declared as UNUSED"))) | ||
+#elif defined(__GNUC__) | ||
+# define XDL_UNUSED __attribute__((unused)) \ | ||
+ __attribute__((deprecated)) | ||
+#else | ||
+# define XDL_UNUSED | ||
+#endif | ||
+ | ||
+#define xdl_malloc(x) malloc(x) | ||
+#define xdl_calloc(n, sz) calloc(n, sz) | ||
+#define xdl_free(ptr) free(ptr) | ||
+#define xdl_realloc(ptr, x) realloc(ptr, x) | ||
+ | ||
+#define XDL_BUG(msg) do { fprintf(stderr, "fatal: %s\n", msg); exit(128); } while(0) | ||
+ | ||
+#define xdl_regex_t regex_t | ||
+#define xdl_regmatch_t regmatch_t | ||
+ | ||
+inline int xdl_regexec_buf( | ||
+ const xdl_regex_t *preg, const char *buf, size_t size, | ||
+ size_t nmatch, xdl_regmatch_t pmatch[], int eflags) | ||
+{ | ||
+ pmatch[0].rm_so = 0; | ||
+ pmatch[0].rm_eo = size; | ||
+ | ||
+ return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND); | ||
+} | ||
+ | ||
+#endif | ||
diff --git a/xdiff.h b/xdiff.h | ||
index bb56b23..fb47f63 100644 | ||
--- a/xdiff.h | ||
+++ b/xdiff.h | ||
@@ -27,6 +27,8 @@ | ||
extern "C" { | ||
#endif /* #ifdef __cplusplus */ | ||
|
||
+#include "git-xdiff.h" | ||
+ | ||
/* xpparm_t.flags */ | ||
#define XDF_NEED_MINIMAL (1 << 0) | ||
|
||
@@ -82,7 +84,7 @@ typedef struct s_xpparam { | ||
unsigned long flags; | ||
|
||
/* -I<regex> */ | ||
- regex_t **ignore_regex; | ||
+ xdl_regex_t **ignore_regex; | ||
size_t ignore_regex_nr; | ||
|
||
/* See Documentation/diff-options.txt. */ | ||
@@ -119,11 +121,6 @@ typedef struct s_bdiffparam { | ||
} bdiffparam_t; | ||
|
||
|
||
-#define xdl_malloc(x) xmalloc(x) | ||
-#define xdl_calloc(n, sz) xcalloc(n, sz) | ||
-#define xdl_free(ptr) free(ptr) | ||
-#define xdl_realloc(ptr,x) xrealloc(ptr,x) | ||
- | ||
void *xdl_mmfile_first(mmfile_t *mmf, long *size); | ||
long xdl_mmfile_size(mmfile_t *mmf); | ||
|
||
diff --git a/xdiffi.c b/xdiffi.c | ||
index 344c2df..ea36143 100644 | ||
--- a/xdiffi.c | ||
+++ b/xdiffi.c | ||
@@ -833,7 +833,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { | ||
/* Shift the group backward as much as possible: */ | ||
while (!group_slide_up(xdf, &g)) | ||
if (group_previous(xdfo, &go)) | ||
- BUG("group sync broken sliding up"); | ||
+ XDL_BUG("group sync broken sliding up"); | ||
|
||
/* | ||
* This is this highest that this group can be shifted. | ||
@@ -849,7 +849,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { | ||
if (group_slide_down(xdf, &g)) | ||
break; | ||
if (group_next(xdfo, &go)) | ||
- BUG("group sync broken sliding down"); | ||
+ XDL_BUG("group sync broken sliding down"); | ||
|
||
if (go.end > go.start) | ||
end_matching_other = g.end; | ||
@@ -874,9 +874,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { | ||
*/ | ||
while (go.end == go.start) { | ||
if (group_slide_up(xdf, &g)) | ||
- BUG("match disappeared"); | ||
+ XDL_BUG("match disappeared"); | ||
if (group_previous(xdfo, &go)) | ||
- BUG("group sync broken sliding to match"); | ||
+ XDL_BUG("group sync broken sliding to match"); | ||
} | ||
} else if (flags & XDF_INDENT_HEURISTIC) { | ||
/* | ||
@@ -917,9 +917,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { | ||
|
||
while (g.end > best_shift) { | ||
if (group_slide_up(xdf, &g)) | ||
- BUG("best shift unreached"); | ||
+ XDL_BUG("best shift unreached"); | ||
if (group_previous(xdfo, &go)) | ||
- BUG("group sync broken sliding to blank line"); | ||
+ XDL_BUG("group sync broken sliding to blank line"); | ||
} | ||
} | ||
|
||
@@ -928,11 +928,11 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { | ||
if (group_next(xdf, &g)) | ||
break; | ||
if (group_next(xdfo, &go)) | ||
- BUG("group sync broken moving to next group"); | ||
+ XDL_BUG("group sync broken moving to next group"); | ||
} | ||
|
||
if (!group_next(xdfo, &go)) | ||
- BUG("group sync broken at end of file"); | ||
+ XDL_BUG("group sync broken at end of file"); | ||
|
||
return 0; | ||
} | ||
@@ -973,7 +973,7 @@ void xdl_free_script(xdchange_t *xscr) { | ||
} | ||
} | ||
|
||
-static int xdl_call_hunk_func(xdfenv_t *xe UNUSED, xdchange_t *xscr, xdemitcb_t *ecb, | ||
+static int xdl_call_hunk_func(xdfenv_t *xe XDL_UNUSED, xdchange_t *xscr, xdemitcb_t *ecb, | ||
xdemitconf_t const *xecfg) | ||
{ | ||
xdchange_t *xch, *xche; | ||
@@ -1012,11 +1012,11 @@ static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags) | ||
} | ||
|
||
static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) { | ||
- regmatch_t regmatch; | ||
+ xdl_regmatch_t regmatch; | ||
int i; | ||
|
||
for (i = 0; i < xpp->ignore_regex_nr; i++) | ||
- if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, | ||
+ if (!xdl_regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, | ||
®match, 0)) | ||
return 1; | ||
|
||
diff --git a/xinclude.h b/xinclude.h | ||
index a4285ac..75db1d8 100644 | ||
--- a/xinclude.h | ||
+++ b/xinclude.h | ||
@@ -23,7 +23,7 @@ | ||
#if !defined(XINCLUDE_H) | ||
#define XINCLUDE_H | ||
|
||
-#include "git-compat-util.h" | ||
+#include "git-xdiff.h" | ||
#include "xmacros.h" | ||
#include "xdiff.h" | ||
#include "xtypes.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file provides the necessary indirection between xdiff and | ||
* the calling application. Callers can use this file to avoid modifying | ||
* xdiff itself with application-specific code, while still using their | ||
* bespoke runtime. For example: callers may wish to use a specific | ||
* `malloc` function, and can do so by defining `xdl_malloc` in this | ||
* file. | ||
*/ | ||
|
||
#ifndef __GIT_XDIFF_H__ | ||
#define __GIT_XDIFF_H__ | ||
|
||
#include <ctype.h> | ||
#include <limits.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <regex.h> | ||
|
||
/* Work around C90-conformance issues */ | ||
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) | ||
# if defined(_MSC_VER) | ||
# define inline __inline | ||
# elif defined(__GNUC__) | ||
# define inline __inline__ | ||
# else | ||
# define inline | ||
# endif | ||
#endif | ||
|
||
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ | ||
((__GNUC__ << 16) + __GNUC_MINOR__ >= (4 << 16) + 5) | ||
# define XDL_UNUSED __attribute__((unused)) \ | ||
__attribute__((deprecated ("parameter declared as UNUSED"))) | ||
#elif defined(__GNUC__) | ||
# define XDL_UNUSED __attribute__((unused)) \ | ||
__attribute__((deprecated)) | ||
#else | ||
# define XDL_UNUSED | ||
#endif | ||
|
||
#define xdl_malloc(x) malloc(x) | ||
#define xdl_calloc(n, sz) calloc(n, sz) | ||
#define xdl_free(ptr) free(ptr) | ||
#define xdl_realloc(ptr, x) realloc(ptr, x) | ||
|
||
#define XDL_BUG(msg) do { fprintf(stderr, "fatal: %s\n", msg); exit(128); } while(0) | ||
|
||
#define xdl_regex_t regex_t | ||
#define xdl_regmatch_t regmatch_t | ||
|
||
inline int xdl_regexec_buf( | ||
const xdl_regex_t *preg, const char *buf, size_t size, | ||
size_t nmatch, xdl_regmatch_t pmatch[], int eflags) | ||
{ | ||
pmatch[0].rm_so = 0; | ||
pmatch[0].rm_eo = size; | ||
|
||
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND); | ||
} | ||
|
||
#endif |
Oops, something went wrong.