summaryrefslogtreecommitdiff
path: root/xdiff-interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'xdiff-interface.c')
-rw-r--r--xdiff-interface.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/xdiff-interface.c b/xdiff-interface.c
index f34ea76..e7af95d 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,9 +1,12 @@
#include "cache.h"
+#include "config.h"
+#include "object-store.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
#include "xdiff/xdiffi.h"
#include "xdiff/xemit.h"
#include "xdiff/xmacros.h"
+#include "xdiff/xutils.h"
struct xdiff_emit_state {
xdiff_emit_consume_fn consume;
@@ -164,9 +167,9 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
size_t sz;
if (stat(filename, &st))
- return error("Could not stat %s", filename);
+ return error_errno("Could not stat %s", filename);
if ((f = fopen(filename, "rb")) == NULL)
- return error("Could not open %s", filename);
+ return error_errno("Could not open %s", filename);
sz = xsize_t(st.st_size);
ptr->ptr = xmalloc(sz ? sz : 1);
if (sz && fread(ptr->ptr, sz, 1, f) != 1) {
@@ -178,20 +181,20 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
return 0;
}
-void read_mmblob(mmfile_t *ptr, const unsigned char *sha1)
+void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- if (!hashcmp(sha1, null_sha1)) {
+ if (oideq(oid, &null_oid)) {
ptr->ptr = xstrdup("");
ptr->size = 0;
return;
}
- ptr->ptr = read_sha1_file(sha1, &type, &size);
+ ptr->ptr = read_object_file(oid, &type, &size);
if (!ptr->ptr || type != OBJ_BLOB)
- die("unable to read blob object %s", sha1_to_hex(sha1));
+ die("unable to read blob object %s", oid_to_hex(oid));
ptr->size = size;
}
@@ -214,11 +217,10 @@ struct ff_regs {
static long ff_regexp(const char *line, long len,
char *buffer, long buffer_size, void *priv)
{
- char *line_buffer;
struct ff_regs *regs = priv;
regmatch_t pmatch[2];
int i;
- int result = -1;
+ int result;
/* Exclude terminating newline (and cr) from matching */
if (len > 0 && line[len-1] == '\n') {
@@ -228,18 +230,16 @@ static long ff_regexp(const char *line, long len,
len--;
}
- line_buffer = xstrndup(line, len); /* make NUL terminated */
-
for (i = 0; i < regs->nr; i++) {
struct ff_reg *reg = regs->array + i;
- if (!regexec(&reg->re, line_buffer, 2, pmatch, 0)) {
+ if (!regexec_buf(&reg->re, line, len, 2, pmatch, 0)) {
if (reg->negate)
- goto fail;
+ return -1;
break;
}
}
if (regs->nr <= i)
- goto fail;
+ return -1;
i = pmatch[1].rm_so >= 0 ? 1 : 0;
line += pmatch[i].rm_so;
result = pmatch[i].rm_eo - pmatch[i].rm_so;
@@ -248,8 +248,6 @@ static long ff_regexp(const char *line, long len,
while (result > 0 && (isspace(line[result - 1])))
result--;
memcpy(buffer, line, result);
- fail:
- free(line_buffer);
return result;
}
@@ -300,6 +298,17 @@ void xdiff_clear_find_func(xdemitconf_t *xecfg)
}
}
+unsigned long xdiff_hash_string(const char *s, size_t len, long flags)
+{
+ return xdl_hash_record(&s, s + len, flags);
+}
+
+int xdiff_compare_lines(const char *l1, long s1,
+ const char *l2, long s2, long flags)
+{
+ return xdl_recmatch(l1, s1, l2, s2, flags);
+}
+
int git_xmerge_style = -1;
int git_xmerge_config(const char *var, const char *value, void *cb)