diff options
Diffstat (limited to 'xdiff-interface.c')
-rw-r--r-- | xdiff-interface.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/xdiff-interface.c b/xdiff-interface.c index 3cf39c39c4..0e2c169227 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -212,13 +212,32 @@ int read_mmfile(mmfile_t *ptr, const char *filename) return error("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) + if (sz && fread(ptr->ptr, sz, 1, f) != 1) { + fclose(f); return error("Could not read %s", filename); + } fclose(f); ptr->size = sz; return 0; } +void read_mmblob(mmfile_t *ptr, const unsigned char *sha1) +{ + unsigned long size; + enum object_type type; + + if (!hashcmp(sha1, null_sha1)) { + ptr->ptr = xstrdup(""); + ptr->size = 0; + return; + } + + ptr->ptr = read_sha1_file(sha1, &type, &size); + if (!ptr->ptr || type != OBJ_BLOB) + die("unable to read blob object %s", sha1_to_hex(sha1)); + ptr->size = size; +} + #define FIRST_FEW_BYTES 8000 int buffer_is_binary(const char *ptr, unsigned long size) { @@ -269,9 +288,8 @@ static long ff_regexp(const char *line, long len, result = pmatch[i].rm_eo - pmatch[i].rm_so; if (result > buffer_size) result = buffer_size; - else - while (result > 0 && (isspace(line[result - 1]))) - result--; + while (result > 0 && (isspace(line[result - 1]))) + result--; memcpy(buffer, line, result); fail: free(line_buffer); @@ -329,7 +347,7 @@ int git_xmerge_style = -1; int git_xmerge_config(const char *var, const char *value, void *cb) { - if (!strcasecmp(var, "merge.conflictstyle")) { + if (!strcmp(var, "merge.conflictstyle")) { if (!value) die("'%s' is not a boolean", var); if (!strcmp(value, "diff3")) |