Commits

Anonymous committed 6483925

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>

Comments (0)

Files changed (2)

 
 extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
 
-extern int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
-			      size_t bufsize, size_t *bufposn);
-extern int write_sha1_to_fd(int fd, const unsigned char *sha1);
 extern int move_temp_to_file(const char *tmpfile, const char *filename);
 
 extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
 	return write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
 }
 
-/*
- * We need to unpack and recompress the object for writing
- * it out to a different file.
- */
-static void *repack_object(const unsigned char *sha1, unsigned long *objsize)
-{
-	size_t size;
-	z_stream stream;
-	unsigned char *unpacked;
-	unsigned long len;
-	enum object_type type;
-	char hdr[32];
-	int hdrlen;
-	void *buf;
-
-	/* need to unpack and recompress it by itself */
-	unpacked = read_packed_sha1(sha1, &type, &len);
-	if (!unpacked)
-		error("cannot read sha1_file for %s", sha1_to_hex(sha1));
-
-	hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
-
-	/* Set it up */
-	memset(&stream, 0, sizeof(stream));
-	deflateInit(&stream, zlib_compression_level);
-	size = deflateBound(&stream, len + hdrlen);
-	buf = xmalloc(size);
-
-	/* Compress it */
-	stream.next_out = buf;
-	stream.avail_out = size;
-
-	/* First header.. */
-	stream.next_in = (void *)hdr;
-	stream.avail_in = hdrlen;
-	while (deflate(&stream, 0) == Z_OK)
-		/* nothing */;
-
-	/* Then the data itself.. */
-	stream.next_in = unpacked;
-	stream.avail_in = len;
-	while (deflate(&stream, Z_FINISH) == Z_OK)
-		/* nothing */;
-	deflateEnd(&stream);
-	free(unpacked);
-
-	*objsize = stream.total_out;
-	return buf;
-}
-
-int write_sha1_to_fd(int fd, const unsigned char *sha1)
-{
-	int retval;
-	unsigned long objsize;
-	void *buf = map_sha1_file(sha1, &objsize);
-
-	if (buf) {
-		retval = write_buffer(fd, buf, objsize);
-		munmap(buf, objsize);
-		return retval;
-	}
-
-	buf = repack_object(sha1, &objsize);
-	retval = write_buffer(fd, buf, objsize);
-	free(buf);
-	return retval;
-}
-
-int write_sha1_from_fd(const unsigned char *sha1, int fd, char *buffer,
-		       size_t bufsize, size_t *bufposn)
-{
-	char tmpfile[PATH_MAX];
-	int local;
-	z_stream stream;
-	unsigned char real_sha1[20];
-	unsigned char discard[4096];
-	int ret;
-	SHA_CTX c;
-
-	snprintf(tmpfile, sizeof(tmpfile), "%s/tmp_obj_XXXXXX", get_object_directory());
-
-	local = mkstemp(tmpfile);
-	if (local < 0) {
-		if (errno == EPERM)
-			return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());
-		else
-			return error("unable to create temporary sha1 filename %s: %s\n", tmpfile, strerror(errno));
-	}
-
-	memset(&stream, 0, sizeof(stream));
-
-	inflateInit(&stream);
-
-	SHA1_Init(&c);
-
-	do {
-		ssize_t size;
-		if (*bufposn) {
-			stream.avail_in = *bufposn;
-			stream.next_in = (unsigned char *) buffer;
-			do {
-				stream.next_out = discard;
-				stream.avail_out = sizeof(discard);
-				ret = inflate(&stream, Z_SYNC_FLUSH);
-				SHA1_Update(&c, discard, sizeof(discard) -
-					    stream.avail_out);
-			} while (stream.avail_in && ret == Z_OK);
-			if (write_buffer(local, buffer, *bufposn - stream.avail_in) < 0)
-				die("unable to write sha1 file");
-			memmove(buffer, buffer + *bufposn - stream.avail_in,
-				stream.avail_in);
-			*bufposn = stream.avail_in;
-			if (ret != Z_OK)
-				break;
-		}
-		size = xread(fd, buffer + *bufposn, bufsize - *bufposn);
-		if (size <= 0) {
-			close(local);
-			unlink(tmpfile);
-			if (!size)
-				return error("Connection closed?");
-			perror("Reading from connection");
-			return -1;
-		}
-		*bufposn += size;
-	} while (1);
-	inflateEnd(&stream);
-
-	close_sha1_file(local);
-	SHA1_Final(real_sha1, &c);
-	if (ret != Z_STREAM_END) {
-		unlink(tmpfile);
-		return error("File %s corrupted", sha1_to_hex(sha1));
-	}
-	if (hashcmp(sha1, real_sha1)) {
-		unlink(tmpfile);
-		return error("File %s has bad hash", sha1_to_hex(sha1));
-	}
-
-	return move_temp_to_file(tmpfile, sha1_file_name(sha1));
-}
-
 int has_pack_index(const unsigned char *sha1)
 {
 	struct stat st;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.