@matheusbsbs / matheus-bagliano / commits / 7cab5883ff
Fork 0

move read_mmfile() into xdiff-interface

read_file() was a useful function if you want to work with the xdiff stuff, so it was renamed and put into a more central place. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Dec 20, 2006 at 17:37 UTC 7cab5883ffd643916d0322a1d3360a79ccf6f653
3 files changed +22 -18
builtin-merge-file.c
+2 -18
@@ -1,26 +1,10 @@
1 #include "cache.h"
2 #include "xdiff/xdiff.h"
3 +#include "xdiff-interface.h"
4
5 static const char merge_file_usage[] =
6 "git merge-file [-p | --stdout] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
7
7 -static int read_file(mmfile_t *ptr, const char *filename)
8 -{
9 - struct stat st;
10 - FILE *f;
11 -
12 - if (stat(filename, &st))
13 - return error("Could not stat %s", filename);
14 - if ((f = fopen(filename, "rb")) == NULL)
15 - return error("Could not open %s", filename);
16 - ptr->ptr = xmalloc(st.st_size);
17 - if (fread(ptr->ptr, st.st_size, 1, f) != 1)
18 - return error("Could not read %s", filename);
19 - fclose(f);
20 - ptr->size = st.st_size;
21 - return 0;
22 -}
23 -
8 int cmd_merge_file(int argc, char **argv, char **envp)
9 {
10 char *names[3];
@@ -53,7 +37,7 @@ int cmd_merge_file(int argc, char **argv, char **envp)
37 names[i] = argv[i + 1];
38
39 for (i = 0; i < 3; i++)
56 - if (read_file(mmfs + i, argv[i + 1]))
40 + if (read_mmfile(mmfs + i, argv[i + 1]))
41 return -1;
42
43 ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
xdiff-interface.c
+19
@@ -102,3 +102,22 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
102 }
103 return 0;
104 }
105 +
106 +int read_mmfile(mmfile_t *ptr, const char *filename)
107 +{
108 + struct stat st;
109 + FILE *f;
110 +
111 + if (stat(filename, &st))
112 + return error("Could not stat %s", filename);
113 + if ((f = fopen(filename, "rb")) == NULL)
114 + return error("Could not open %s", filename);
115 + ptr->ptr = xmalloc(st.st_size);
116 + if (fread(ptr->ptr, st.st_size, 1, f) != 1)
117 + return error("Could not read %s", filename);
118 + fclose(f);
119 + ptr->size = st.st_size;
120 + return 0;
121 +}
122 +
123 +
xdiff-interface.h
+1
@@ -17,5 +17,6 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf);
17 int parse_hunk_header(char *line, int len,
18 int *ob, int *on,
19 int *nb, int *nn);
20 +int read_mmfile(mmfile_t *ptr, const char *filename);
21
22 #endif