Use a single implementation and API for copy_file()
Originally by Kristian Hï¿œgsberg; I fixed the conversion of rerere, which had a different API. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ed10d9aa3f
commit
1468bd4783
@ -29,27 +29,6 @@ static void safe_create_dir(const char *dir, int share)
|
|||||||
die("Could not make %s writable by group\n", dir);
|
die("Could not make %s writable by group\n", dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy_file(const char *dst, const char *src, int mode)
|
|
||||||
{
|
|
||||||
int fdi, fdo, status;
|
|
||||||
|
|
||||||
mode = (mode & 0111) ? 0777 : 0666;
|
|
||||||
if ((fdi = open(src, O_RDONLY)) < 0)
|
|
||||||
return fdi;
|
|
||||||
if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
|
|
||||||
close(fdi);
|
|
||||||
return fdo;
|
|
||||||
}
|
|
||||||
status = copy_fd(fdi, fdo);
|
|
||||||
if (close(fdo) != 0)
|
|
||||||
return error("%s: write error: %s", dst, strerror(errno));
|
|
||||||
|
|
||||||
if (!status && adjust_shared_perm(dst))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void copy_templates_1(char *path, int baselen,
|
static void copy_templates_1(char *path, int baselen,
|
||||||
char *template, int template_baselen,
|
char *template, int template_baselen,
|
||||||
DIR *dir)
|
DIR *dir)
|
||||||
|
@ -267,23 +267,6 @@ static int diff_two(const char *file1, const char *label1,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy_file(const char *src, const char *dest)
|
|
||||||
{
|
|
||||||
FILE *in, *out;
|
|
||||||
char buffer[32768];
|
|
||||||
int count;
|
|
||||||
|
|
||||||
if (!(in = fopen(src, "r")))
|
|
||||||
return error("Could not open %s", src);
|
|
||||||
if (!(out = fopen(dest, "w")))
|
|
||||||
return error("Could not open %s", dest);
|
|
||||||
while ((count = fread(buffer, 1, sizeof(buffer), in)))
|
|
||||||
fwrite(buffer, 1, count, out);
|
|
||||||
fclose(in);
|
|
||||||
fclose(out);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int do_plain_rerere(struct path_list *rr, int fd)
|
static int do_plain_rerere(struct path_list *rr, int fd)
|
||||||
{
|
{
|
||||||
struct path_list conflict = { NULL, 0, 0, 1 };
|
struct path_list conflict = { NULL, 0, 0, 1 };
|
||||||
@ -343,7 +326,7 @@ static int do_plain_rerere(struct path_list *rr, int fd)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
fprintf(stderr, "Recorded resolution for '%s'.\n", path);
|
fprintf(stderr, "Recorded resolution for '%s'.\n", path);
|
||||||
copy_file(path, rr_path(name, "postimage"));
|
copy_file(rr_path(name, "postimage"), path, 0666);
|
||||||
tail_optimization:
|
tail_optimization:
|
||||||
if (i < rr->nr - 1)
|
if (i < rr->nr - 1)
|
||||||
memmove(rr->items + i,
|
memmove(rr->items + i,
|
||||||
|
1
cache.h
1
cache.h
@ -602,6 +602,7 @@ extern const char *git_log_output_encoding;
|
|||||||
/* IO helper functions */
|
/* IO helper functions */
|
||||||
extern void maybe_flush_or_die(FILE *, const char *);
|
extern void maybe_flush_or_die(FILE *, const char *);
|
||||||
extern int copy_fd(int ifd, int ofd);
|
extern int copy_fd(int ifd, int ofd);
|
||||||
|
extern int copy_file(const char *dst, const char *src, int mode);
|
||||||
extern int read_in_full(int fd, void *buf, size_t count);
|
extern int read_in_full(int fd, void *buf, size_t count);
|
||||||
extern int write_in_full(int fd, const void *buf, size_t count);
|
extern int write_in_full(int fd, const void *buf, size_t count);
|
||||||
extern void write_or_die(int fd, const void *buf, size_t count);
|
extern void write_or_die(int fd, const void *buf, size_t count);
|
||||||
|
21
copy.c
21
copy.c
@ -34,3 +34,24 @@ int copy_fd(int ifd, int ofd)
|
|||||||
close(ifd);
|
close(ifd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int copy_file(const char *dst, const char *src, int mode)
|
||||||
|
{
|
||||||
|
int fdi, fdo, status;
|
||||||
|
|
||||||
|
mode = (mode & 0111) ? 0777 : 0666;
|
||||||
|
if ((fdi = open(src, O_RDONLY)) < 0)
|
||||||
|
return fdi;
|
||||||
|
if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
|
||||||
|
close(fdi);
|
||||||
|
return fdo;
|
||||||
|
}
|
||||||
|
status = copy_fd(fdi, fdo);
|
||||||
|
if (close(fdo) != 0)
|
||||||
|
return error("%s: write error: %s", dst, strerror(errno));
|
||||||
|
|
||||||
|
if (!status && adjust_shared_perm(dst))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
8
diff.c
8
diff.c
@ -272,8 +272,8 @@ static void print_line_count(int count)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_file(int prefix, const char *data, int size,
|
static void copy_file_with_prefix(int prefix, const char *data, int size,
|
||||||
const char *set, const char *reset)
|
const char *set, const char *reset)
|
||||||
{
|
{
|
||||||
int ch, nl_just_seen = 1;
|
int ch, nl_just_seen = 1;
|
||||||
while (0 < size--) {
|
while (0 < size--) {
|
||||||
@ -331,9 +331,9 @@ static void emit_rewrite_diff(const char *name_a,
|
|||||||
print_line_count(lc_b);
|
print_line_count(lc_b);
|
||||||
printf(" @@%s\n", reset);
|
printf(" @@%s\n", reset);
|
||||||
if (lc_a)
|
if (lc_a)
|
||||||
copy_file('-', one->data, one->size, old, reset);
|
copy_file_with_prefix('-', one->data, one->size, old, reset);
|
||||||
if (lc_b)
|
if (lc_b)
|
||||||
copy_file('+', two->data, two->size, new, reset);
|
copy_file_with_prefix('+', two->data, two->size, new, reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
|
static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
|
||||||
|
Loading…
Reference in New Issue
Block a user