@matheusbsbs / matheus-bagliano / commits / 628cd5430f
Fork 0

[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>

Sergey Vlasov committed Sep 23, 2005 at 16:28 UTC 628cd5430fdf71a75c02af88ab7b557d29687db5
1 file changed +12 -5
local-fetch.c
+12 -5
@@ -52,7 +52,8 @@ static int setup_indices(void)
52 return 0;
53 }
54
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)
57 {
58 if (use_link) {
59 if (!link(source, dest)) {
@@ -61,13 +62,16 @@ static int copy_file(const char *source, const char *dest, const char *hex)
62 }
63 /* If we got ENOENT there is no point continuing. */
64 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);
67 return -1;
68 }
69 }
70 if (use_symlink) {
71 struct stat st;
72 if (stat(source, &st)) {
73 + if (!warn_if_not_exists && errno == ENOENT)
74 + return -1;
75 fprintf(stderr, "cannot stat %s: %s\n", source,
76 strerror(errno));
77 return -1;
@@ -83,8 +87,11 @@ static int copy_file(const char *source, const char *dest, const char *hex)
87 void *map;
88 ifd = open(source, O_RDONLY);
89 if (ifd < 0 || fstat(ifd, &st) < 0) {
90 + int err = errno;
91 if (ifd >= 0)
92 close(ifd);
93 + if (!warn_if_not_exists && err == ENOENT)
94 + return -1;
95 fprintf(stderr, "cannot open %s\n", source);
96 return -1;
97 }
@@ -129,11 +136,11 @@ static int fetch_pack(const unsigned char *sha1)
136 sprintf(filename, "%s/objects/pack/pack-%s.pack",
137 path, sha1_to_hex(target->sha1));
138 copy_file(filename, sha1_pack_name(target->sha1),
132 - sha1_to_hex(target->sha1));
139 + sha1_to_hex(target->sha1), 1);
140 sprintf(filename, "%s/objects/pack/pack-%s.idx",
141 path, sha1_to_hex(target->sha1));
142 copy_file(filename, sha1_pack_index_name(target->sha1),
136 - sha1_to_hex(target->sha1));
143 + sha1_to_hex(target->sha1), 1);
144 install_packed_git(target);
145 return 0;
146 }
@@ -154,7 +161,7 @@ static int fetch_file(const unsigned char *sha1)
161 filename[object_name_start+1] = hex[1];
162 filename[object_name_start+2] = '/';
163 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);
165 }
166
167 int fetch(unsigned char *sha1)