[PATCH] local-fetch.c: some error printing cleanup
Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Mar 16, 2007 at 13:20 UTC
e8e91fece83cf67810e5b8b2908601c048ecd19c
1 file changed
+13
-20
local-fetch.c
+13
-20
@@ -64,9 +64,9 @@ static int copy_file(const char *source, char *dest, const char *hex,
64
}
65
/* If we got ENOENT there is no point continuing. */
66
if (errno == ENOENT) {
67
- if (warn_if_not_exists)
68
- fprintf(stderr, "does not exist %s\n", source);
69
- return -1;
67
+ if (!warn_if_not_exists)
68
+ return -1;
69
+ return error("does not exist %s", source);
70
}
71
}
72
if (use_symlink) {
@@ -74,9 +74,8 @@ static int copy_file(const char *source, char *dest, const char *hex,
74
if (stat(source, &st)) {
75
if (!warn_if_not_exists && errno == ENOENT)
76
return -1;
77
- fprintf(stderr, "cannot stat %s: %s\n", source,
78
- strerror(errno));
79
- return -1;
77
+ return error("cannot stat %s: %s", source,
78
+ strerror(errno));
79
}
80
if (!symlink(source, dest)) {
81
pull_say("symlink %s\n", hex);
@@ -90,25 +89,21 @@ static int copy_file(const char *source, char *dest, const char *hex,
89
if (ifd < 0) {
90
if (!warn_if_not_exists && errno == ENOENT)
91
return -1;
93
- fprintf(stderr, "cannot open %s\n", source);
94
- return -1;
92
+ return error("cannot open %s", source);
93
}
94
ofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);
95
if (ofd < 0) {
98
- fprintf(stderr, "cannot open %s\n", dest);
96
close(ifd);
100
- return -1;
97
+ return error("cannot open %s", dest);
98
}
99
status = copy_fd(ifd, ofd);
100
close(ofd);
101
if (status)
105
- fprintf(stderr, "cannot write %s\n", dest);
106
- else
107
- pull_say("copy %s\n", hex);
108
- return status;
102
+ return error("cannot write %s", dest);
103
+ pull_say("copy %s\n", hex);
104
+ return 0;
105
}
110
- fprintf(stderr, "failed to copy %s with given copy methods.\n", hex);
111
- return -1;
106
+ return error("failed to copy %s with given copy methods.", hex);
107
}
108
109
static int fetch_pack(const unsigned char *sha1)
@@ -181,13 +176,11 @@ int fetch_ref(char *ref, unsigned char *sha1)
176
ifd = open(filename, O_RDONLY);
177
if (ifd < 0) {
178
close(ifd);
184
- fprintf(stderr, "cannot open %s\n", filename);
185
- return -1;
179
+ return error("cannot open %s", filename);
180
}
181
if (read_in_full(ifd, hex, 40) != 40 || get_sha1_hex(hex, sha1)) {
182
close(ifd);
189
- fprintf(stderr, "cannot read from %s\n", filename);
190
- return -1;
183
+ return error("cannot read from %s", filename);
184
}
185
close(ifd);
186
pull_say("ref %s\n", sha1_to_hex(sha1));