sha1_file.c: dead code removal
write_sha1_from_fd() and write_sha1_to_fd() were dead code nobody called, neither the latter's helper repack_object() was. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 13, 2008 at 23:00 UTC
6483925999cde47e5108414ac3f57760394ee2d2
2 files changed
-145
cache.h
-3
@@ -536,9 +536,6 @@ extern int force_object_loose(const unsigned char *sha1, time_t mtime);
536
537
extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
538
539
-extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
540
- size_t bufsize, size_t *bufposn);
541
-extern int write_sha1_to_fd(int fd, const unsigned char *sha1);
539
extern int move_temp_to_file(const char *tmpfile, const char *filename);
540
541
extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
sha1_file.c
-142
@@ -2229,148 +2229,6 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
2229
return write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
2230
}
2231
2232
-/*
2233
- * We need to unpack and recompress the object for writing
2234
- * it out to a different file.
2235
- */
2236
-static void *repack_object(const unsigned char *sha1, unsigned long *objsize)
2237
-{
2238
- size_t size;
2239
- z_stream stream;
2240
- unsigned char *unpacked;
2241
- unsigned long len;
2242
- enum object_type type;
2243
- char hdr[32];
2244
- int hdrlen;
2245
- void *buf;
2246
-
2247
- /* need to unpack and recompress it by itself */
2248
- unpacked = read_packed_sha1(sha1, &type, &len);
2249
- if (!unpacked)
2250
- error("cannot read sha1_file for %s", sha1_to_hex(sha1));
2251
-
2252
- hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
2253
-
2254
- /* Set it up */
2255
- memset(&stream, 0, sizeof(stream));
2256
- deflateInit(&stream, zlib_compression_level);
2257
- size = deflateBound(&stream, len + hdrlen);
2258
- buf = xmalloc(size);
2259
-
2260
- /* Compress it */
2261
- stream.next_out = buf;
2262
- stream.avail_out = size;
2263
-
2264
- /* First header.. */
2265
- stream.next_in = (void *)hdr;
2266
- stream.avail_in = hdrlen;
2267
- while (deflate(&stream, 0) == Z_OK)
2268
- /* nothing */;
2269
-
2270
- /* Then the data itself.. */
2271
- stream.next_in = unpacked;
2272
- stream.avail_in = len;
2273
- while (deflate(&stream, Z_FINISH) == Z_OK)
2274
- /* nothing */;
2275
- deflateEnd(&stream);
2276
- free(unpacked);
2277
-
2278
- *objsize = stream.total_out;
2279
- return buf;
2280
-}
2281
-
2282
-int write_sha1_to_fd(int fd, const unsigned char *sha1)
2283
-{
2284
- int retval;
2285
- unsigned long objsize;
2286
- void *buf = map_sha1_file(sha1, &objsize);
2287
-
2288
- if (buf) {
2289
- retval = write_buffer(fd, buf, objsize);
2290
- munmap(buf, objsize);
2291
- return retval;
2292
- }
2293
-
2294
- buf = repack_object(sha1, &objsize);
2295
- retval = write_buffer(fd, buf, objsize);
2296
- free(buf);
2297
- return retval;
2298
-}
2299
-
2300
-int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
2301
- size_t bufsize, size_t *bufposn)
2302
-{
2303
- char tmpfile[PATH_MAX];
2304
- int local;
2305
- z_stream stream;
2306
- unsigned char real_sha1[20];
2307
- unsigned char discard[4096];
2308
- int ret;
2309
- SHA_CTX c;
2310
-
2311
- snprintf(tmpfile, sizeof(tmpfile), "%s/tmp_obj_XXXXXX", get_object_directory());
2312
-
2313
- local = mkstemp(tmpfile);
2314
- if (local < 0) {
2315
- if (errno == EPERM)
2316
- return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
2317
- else
2318
- return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
2319
- }
2320
-
2321
- memset(&stream, 0, sizeof(stream));
2322
-
2323
- inflateInit(&stream);
2324
-
2325
- SHA1_Init(&c);
2326
-
2327
- do {
2328
- ssize_t size;
2329
- if (*bufposn) {
2330
- stream.avail_in = *bufposn;
2331
- stream.next_in = (unsigned char *) buffer;
2332
- do {
2333
- stream.next_out = discard;
2334
- stream.avail_out = sizeof(discard);
2335
- ret = inflate(&stream, Z_SYNC_FLUSH);
2336
- SHA1_Update(&c, discard, sizeof(discard) -
2337
- stream.avail_out);
2338
- } while (stream.avail_in && ret == Z_OK);
2339
- if (write_buffer(local, buffer, *bufposn - stream.avail_in) < 0)
2340
- die("unable to write sha1 file");
2341
- memmove(buffer, buffer + *bufposn - stream.avail_in,
2342
- stream.avail_in);
2343
- *bufposn = stream.avail_in;
2344
- if (ret != Z_OK)
2345
- break;
2346
- }
2347
- size = xread(fd, buffer + *bufposn, bufsize - *bufposn);
2348
- if (size <= 0) {
2349
- close(local);
2350
- unlink(tmpfile);
2351
- if (!size)
2352
- return error("Connection closed?");
2353
- perror("Reading from connection");
2354
- return -1;
2355
- }
2356
- *bufposn += size;
2357
- } while (1);
2358
- inflateEnd(&stream);
2359
-
2360
- close_sha1_file(local);
2361
- SHA1_Final(real_sha1, &c);
2362
- if (ret != Z_STREAM_END) {
2363
- unlink(tmpfile);
2364
- return error("File %s corrupted", sha1_to_hex(sha1));
2365
- }
2366
- if (hashcmp(sha1, real_sha1)) {
2367
- unlink(tmpfile);
2368
- return error("File %s has bad hash", sha1_to_hex(sha1));
2369
- }
2370
-
2371
- return move_temp_to_file(tmpfile, sha1_file_name(sha1));
2372
-}
2373
-
2232
int has_pack_index(const unsigned char *sha1)
2233
{
2234
struct stat st;