Skip to content

Commit

Permalink
move read_mmfile() into xdiff-interface
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Dec 22, 2006
1 parent fa39b6b commit 7cab588
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
20 changes: 2 additions & 18 deletions builtin-merge-file.c
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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],
Expand Down
19 changes: 19 additions & 0 deletions xdiff-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


1 change: 1 addition & 0 deletions xdiff-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7cab588

Please sign in to comment.