Skip to content

Commit 628cd54

Browse files
sigprofJunio C Hamano
authored andcommitted
[PATCH] git-local-fetch: Avoid confusing error messages on packed repositories
If the source repository was packed, and git-local-fetch needed to fetch a pack file, it spewed a misleading error message about not being able to find the unpacked object. Fixed by adding the warn_if_not_exists argument to copy_file(), which controls printing of error messages in case the source file does not exist. Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent e2b77f0 commit 628cd54

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

local-fetch.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static int setup_indices(void)
5252
return 0;
5353
}
5454

55-
static int copy_file(const char *source, const char *dest, const char *hex)
55+
static int copy_file(const char *source, const char *dest, const char *hex,
56+
int warn_if_not_exists)
5657
{
5758
if (use_link) {
5859
if (!link(source, dest)) {
@@ -61,13 +62,16 @@ static int copy_file(const char *source, const char *dest, const char *hex)
6162
}
6263
/* If we got ENOENT there is no point continuing. */
6364
if (errno == ENOENT) {
64-
fprintf(stderr, "does not exist %s\n", source);
65+
if (warn_if_not_exists)
66+
fprintf(stderr, "does not exist %s\n", source);
6567
return -1;
6668
}
6769
}
6870
if (use_symlink) {
6971
struct stat st;
7072
if (stat(source, &st)) {
73+
if (!warn_if_not_exists && errno == ENOENT)
74+
return -1;
7175
fprintf(stderr, "cannot stat %s: %s\n", source,
7276
strerror(errno));
7377
return -1;
@@ -83,8 +87,11 @@ static int copy_file(const char *source, const char *dest, const char *hex)
8387
void *map;
8488
ifd = open(source, O_RDONLY);
8589
if (ifd < 0 || fstat(ifd, &st) < 0) {
90+
int err = errno;
8691
if (ifd >= 0)
8792
close(ifd);
93+
if (!warn_if_not_exists && err == ENOENT)
94+
return -1;
8895
fprintf(stderr, "cannot open %s\n", source);
8996
return -1;
9097
}
@@ -129,11 +136,11 @@ static int fetch_pack(const unsigned char *sha1)
129136
sprintf(filename, "%s/objects/pack/pack-%s.pack",
130137
path, sha1_to_hex(target->sha1));
131138
copy_file(filename, sha1_pack_name(target->sha1),
132-
sha1_to_hex(target->sha1));
139+
sha1_to_hex(target->sha1), 1);
133140
sprintf(filename, "%s/objects/pack/pack-%s.idx",
134141
path, sha1_to_hex(target->sha1));
135142
copy_file(filename, sha1_pack_index_name(target->sha1),
136-
sha1_to_hex(target->sha1));
143+
sha1_to_hex(target->sha1), 1);
137144
install_packed_git(target);
138145
return 0;
139146
}
@@ -154,7 +161,7 @@ static int fetch_file(const unsigned char *sha1)
154161
filename[object_name_start+1] = hex[1];
155162
filename[object_name_start+2] = '/';
156163
strcpy(filename + object_name_start + 3, hex + 2);
157-
return copy_file(filename, dest_filename, hex);
164+
return copy_file(filename, dest_filename, hex, 0);
158165
}
159166

160167
int fetch(unsigned char *sha1)

0 commit comments

Comments
 (0)