Skip to content

Commit 7cab588

Browse files
dschoJunio C Hamano
authored andcommitted
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>
1 parent fa39b6b commit 7cab588

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

builtin-merge-file.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
#include "cache.h"
22
#include "xdiff/xdiff.h"
3+
#include "xdiff-interface.h"
34

45
static const char merge_file_usage[] =
56
"git merge-file [-p | --stdout] [-q | --quiet] [-L name1 [-L orig [-L name2]]] file1 orig_file file2";
67

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-
248
int cmd_merge_file(int argc, char **argv, char **envp)
259
{
2610
char *names[3];
@@ -53,7 +37,7 @@ int cmd_merge_file(int argc, char **argv, char **envp)
5337
names[i] = argv[i + 1];
5438

5539
for (i = 0; i < 3; i++)
56-
if (read_file(mmfs + i, argv[i + 1]))
40+
if (read_mmfile(mmfs + i, argv[i + 1]))
5741
return -1;
5842

5943
ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],

xdiff-interface.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,22 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
102102
}
103103
return 0;
104104
}
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf);
1717
int parse_hunk_header(char *line, int len,
1818
int *ob, int *on,
1919
int *nb, int *nn);
20+
int read_mmfile(mmfile_t *ptr, const char *filename);
2021

2122
#endif

0 commit comments

Comments
 (0)