diff options
-rw-r--r-- | builtin-merge-file.c | 20 | ||||
-rw-r--r-- | xdiff-interface.c | 19 | ||||
-rw-r--r-- | xdiff-interface.h | 1 |
3 files changed, 22 insertions, 18 deletions
diff --git a/builtin-merge-file.c b/builtin-merge-file.c index 6c4c3a3513..9135773908 100644 --- a/builtin-merge-file.c +++ b/builtin-merge-file.c @@ -1,26 +1,10 @@ #include "cache.h" #include "xdiff/xdiff.h" +#include "xdiff-interface.h" static const char merge_file_usage[] = "git merge-file [-p | --stdout] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2"; -static int read_file(mmfile_t *ptr, const char *filename) -{ - struct stat st; - FILE *f; - - if (stat(filename, &st)) - return error("Could not stat %s", filename); - if ((f = fopen(filename, "rb")) == NULL) - return error("Could not open %s", filename); - ptr->ptr = xmalloc(st.st_size); - if (fread(ptr->ptr, st.st_size, 1, f) != 1) - return error("Could not read %s", filename); - fclose(f); - ptr->size = st.st_size; - return 0; -} - int cmd_merge_file(int argc, char **argv, char **envp) { char *names[3]; @@ -53,7 +37,7 @@ int cmd_merge_file(int argc, char **argv, char **envp) names[i] = argv[i + 1]; for (i = 0; i < 3; i++) - if (read_file(mmfs + i, argv[i + 1])) + if (read_mmfile(mmfs + i, argv[i + 1])) return -1; ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2], diff --git a/xdiff-interface.c b/xdiff-interface.c index 08602f5221..6c1f99b149 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -102,3 +102,22 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf) } return 0; } + +int read_mmfile(mmfile_t *ptr, const char *filename) +{ + struct stat st; + FILE *f; + + if (stat(filename, &st)) + return error("Could not stat %s", filename); + if ((f = fopen(filename, "rb")) == NULL) + return error("Could not open %s", filename); + ptr->ptr = xmalloc(st.st_size); + if (fread(ptr->ptr, st.st_size, 1, f) != 1) + return error("Could not read %s", filename); + fclose(f); + ptr->size = st.st_size; + return 0; +} + + diff --git a/xdiff-interface.h b/xdiff-interface.h index 1346908bea..1918808081 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -17,5 +17,6 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf); int parse_hunk_header(char *line, int len, int *ob, int *on, int *nb, int *nn); +int read_mmfile(mmfile_t *ptr, const char *filename); #endif |