archive: convert write_archive_entry_fn_t to object_id
Convert the write_archive_entry_fn_t type to use a pointer to struct object_id. Convert various static functions in the tar and zip archivers also. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
eedc994f18
commit
015ff4f822
@ -111,7 +111,7 @@ static void write_trailer(void)
|
|||||||
* queues up writes, so that all our write(2) calls write exactly one
|
* queues up writes, so that all our write(2) calls write exactly one
|
||||||
* full block; pads writes to RECORDSIZE
|
* full block; pads writes to RECORDSIZE
|
||||||
*/
|
*/
|
||||||
static int stream_blocked(const unsigned char *sha1)
|
static int stream_blocked(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct git_istream *st;
|
struct git_istream *st;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
@ -119,9 +119,9 @@ static int stream_blocked(const unsigned char *sha1)
|
|||||||
char buf[BLOCKSIZE];
|
char buf[BLOCKSIZE];
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
|
|
||||||
st = open_istream(sha1, &type, &sz, NULL);
|
st = open_istream(oid->hash, &type, &sz, NULL);
|
||||||
if (!st)
|
if (!st)
|
||||||
return error("cannot stream blob %s", sha1_to_hex(sha1));
|
return error("cannot stream blob %s", oid_to_hex(oid));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
readlen = read_istream(st, buf, sizeof(buf));
|
readlen = read_istream(st, buf, sizeof(buf));
|
||||||
if (readlen <= 0)
|
if (readlen <= 0)
|
||||||
@ -218,7 +218,7 @@ static void prepare_header(struct archiver_args *args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void write_extended_header(struct archiver_args *args,
|
static void write_extended_header(struct archiver_args *args,
|
||||||
const unsigned char *sha1,
|
const struct object_id *oid,
|
||||||
const void *buffer, unsigned long size)
|
const void *buffer, unsigned long size)
|
||||||
{
|
{
|
||||||
struct ustar_header header;
|
struct ustar_header header;
|
||||||
@ -226,14 +226,14 @@ static void write_extended_header(struct archiver_args *args,
|
|||||||
memset(&header, 0, sizeof(header));
|
memset(&header, 0, sizeof(header));
|
||||||
*header.typeflag = TYPEFLAG_EXT_HEADER;
|
*header.typeflag = TYPEFLAG_EXT_HEADER;
|
||||||
mode = 0100666;
|
mode = 0100666;
|
||||||
xsnprintf(header.name, sizeof(header.name), "%s.paxheader", sha1_to_hex(sha1));
|
xsnprintf(header.name, sizeof(header.name), "%s.paxheader", oid_to_hex(oid));
|
||||||
prepare_header(args, &header, mode, size);
|
prepare_header(args, &header, mode, size);
|
||||||
write_blocked(&header, sizeof(header));
|
write_blocked(&header, sizeof(header));
|
||||||
write_blocked(buffer, size);
|
write_blocked(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_tar_entry(struct archiver_args *args,
|
static int write_tar_entry(struct archiver_args *args,
|
||||||
const unsigned char *sha1,
|
const struct object_id *oid,
|
||||||
const char *path, size_t pathlen,
|
const char *path, size_t pathlen,
|
||||||
unsigned int mode)
|
unsigned int mode)
|
||||||
{
|
{
|
||||||
@ -257,7 +257,7 @@ static int write_tar_entry(struct archiver_args *args,
|
|||||||
mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
|
mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
|
||||||
} else {
|
} else {
|
||||||
return error("unsupported file mode: 0%o (SHA1: %s)",
|
return error("unsupported file mode: 0%o (SHA1: %s)",
|
||||||
mode, sha1_to_hex(sha1));
|
mode, oid_to_hex(oid));
|
||||||
}
|
}
|
||||||
if (pathlen > sizeof(header.name)) {
|
if (pathlen > sizeof(header.name)) {
|
||||||
size_t plen = get_path_prefix(path, pathlen,
|
size_t plen = get_path_prefix(path, pathlen,
|
||||||
@ -268,7 +268,7 @@ static int write_tar_entry(struct archiver_args *args,
|
|||||||
memcpy(header.name, path + plen + 1, rest);
|
memcpy(header.name, path + plen + 1, rest);
|
||||||
} else {
|
} else {
|
||||||
xsnprintf(header.name, sizeof(header.name), "%s.data",
|
xsnprintf(header.name, sizeof(header.name), "%s.data",
|
||||||
sha1_to_hex(sha1));
|
oid_to_hex(oid));
|
||||||
strbuf_append_ext_header(&ext_header, "path",
|
strbuf_append_ext_header(&ext_header, "path",
|
||||||
path, pathlen);
|
path, pathlen);
|
||||||
}
|
}
|
||||||
@ -276,14 +276,14 @@ static int write_tar_entry(struct archiver_args *args,
|
|||||||
memcpy(header.name, path, pathlen);
|
memcpy(header.name, path, pathlen);
|
||||||
|
|
||||||
if (S_ISREG(mode) && !args->convert &&
|
if (S_ISREG(mode) && !args->convert &&
|
||||||
sha1_object_info(sha1, &size) == OBJ_BLOB &&
|
sha1_object_info(oid->hash, &size) == OBJ_BLOB &&
|
||||||
size > big_file_threshold)
|
size > big_file_threshold)
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
else if (S_ISLNK(mode) || S_ISREG(mode)) {
|
else if (S_ISLNK(mode) || S_ISREG(mode)) {
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
buffer = sha1_file_to_archive(args, path, sha1, old_mode, &type, &size);
|
buffer = sha1_file_to_archive(args, path, oid->hash, old_mode, &type, &size);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return error("cannot read %s", sha1_to_hex(sha1));
|
return error("cannot read %s", oid_to_hex(oid));
|
||||||
} else {
|
} else {
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
size = 0;
|
size = 0;
|
||||||
@ -292,7 +292,7 @@ static int write_tar_entry(struct archiver_args *args,
|
|||||||
if (S_ISLNK(mode)) {
|
if (S_ISLNK(mode)) {
|
||||||
if (size > sizeof(header.linkname)) {
|
if (size > sizeof(header.linkname)) {
|
||||||
xsnprintf(header.linkname, sizeof(header.linkname),
|
xsnprintf(header.linkname, sizeof(header.linkname),
|
||||||
"see %s.paxheader", sha1_to_hex(sha1));
|
"see %s.paxheader", oid_to_hex(oid));
|
||||||
strbuf_append_ext_header(&ext_header, "linkpath",
|
strbuf_append_ext_header(&ext_header, "linkpath",
|
||||||
buffer, size);
|
buffer, size);
|
||||||
} else
|
} else
|
||||||
@ -308,7 +308,7 @@ static int write_tar_entry(struct archiver_args *args,
|
|||||||
prepare_header(args, &header, mode, size_in_header);
|
prepare_header(args, &header, mode, size_in_header);
|
||||||
|
|
||||||
if (ext_header.len > 0) {
|
if (ext_header.len > 0) {
|
||||||
write_extended_header(args, sha1, ext_header.buf,
|
write_extended_header(args, oid, ext_header.buf,
|
||||||
ext_header.len);
|
ext_header.len);
|
||||||
}
|
}
|
||||||
strbuf_release(&ext_header);
|
strbuf_release(&ext_header);
|
||||||
@ -317,7 +317,7 @@ static int write_tar_entry(struct archiver_args *args,
|
|||||||
if (buffer)
|
if (buffer)
|
||||||
write_blocked(buffer, size);
|
write_blocked(buffer, size);
|
||||||
else
|
else
|
||||||
err = stream_blocked(sha1);
|
err = stream_blocked(oid);
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return err;
|
return err;
|
||||||
|
@ -276,7 +276,7 @@ static int entry_is_binary(const char *path, const void *buffer, size_t size)
|
|||||||
#define STREAM_BUFFER_SIZE (1024 * 16)
|
#define STREAM_BUFFER_SIZE (1024 * 16)
|
||||||
|
|
||||||
static int write_zip_entry(struct archiver_args *args,
|
static int write_zip_entry(struct archiver_args *args,
|
||||||
const unsigned char *sha1,
|
const struct object_id *oid,
|
||||||
const char *path, size_t pathlen,
|
const char *path, size_t pathlen,
|
||||||
unsigned int mode)
|
unsigned int mode)
|
||||||
{
|
{
|
||||||
@ -314,7 +314,7 @@ static int write_zip_entry(struct archiver_args *args,
|
|||||||
|
|
||||||
if (pathlen > 0xffff) {
|
if (pathlen > 0xffff) {
|
||||||
return error("path too long (%d chars, SHA1: %s): %s",
|
return error("path too long (%d chars, SHA1: %s): %s",
|
||||||
(int)pathlen, sha1_to_hex(sha1), path);
|
(int)pathlen, oid_to_hex(oid), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
|
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
|
||||||
@ -325,7 +325,7 @@ static int write_zip_entry(struct archiver_args *args,
|
|||||||
compressed_size = 0;
|
compressed_size = 0;
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
} else if (S_ISREG(mode) || S_ISLNK(mode)) {
|
} else if (S_ISREG(mode) || S_ISLNK(mode)) {
|
||||||
enum object_type type = sha1_object_info(sha1, &size);
|
enum object_type type = sha1_object_info(oid->hash, &size);
|
||||||
|
|
||||||
method = 0;
|
method = 0;
|
||||||
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
|
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
|
||||||
@ -337,18 +337,18 @@ static int write_zip_entry(struct archiver_args *args,
|
|||||||
|
|
||||||
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
|
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
|
||||||
size > big_file_threshold) {
|
size > big_file_threshold) {
|
||||||
stream = open_istream(sha1, &type, &size, NULL);
|
stream = open_istream(oid->hash, &type, &size, NULL);
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return error("cannot stream blob %s",
|
return error("cannot stream blob %s",
|
||||||
sha1_to_hex(sha1));
|
oid_to_hex(oid));
|
||||||
flags |= ZIP_STREAM;
|
flags |= ZIP_STREAM;
|
||||||
out = buffer = NULL;
|
out = buffer = NULL;
|
||||||
} else {
|
} else {
|
||||||
buffer = sha1_file_to_archive(args, path, sha1, mode,
|
buffer = sha1_file_to_archive(args, path, oid->hash, mode,
|
||||||
&type, &size);
|
&type, &size);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return error("cannot read %s",
|
return error("cannot read %s",
|
||||||
sha1_to_hex(sha1));
|
oid_to_hex(oid));
|
||||||
crc = crc32(crc, buffer, size);
|
crc = crc32(crc, buffer, size);
|
||||||
is_binary = entry_is_binary(path_without_prefix,
|
is_binary = entry_is_binary(path_without_prefix,
|
||||||
buffer, size);
|
buffer, size);
|
||||||
@ -357,7 +357,7 @@ static int write_zip_entry(struct archiver_args *args,
|
|||||||
compressed_size = (method == 0) ? size : 0;
|
compressed_size = (method == 0) ? size : 0;
|
||||||
} else {
|
} else {
|
||||||
return error("unsupported file mode: 0%o (SHA1: %s)", mode,
|
return error("unsupported file mode: 0%o (SHA1: %s)", mode,
|
||||||
sha1_to_hex(sha1));
|
oid_to_hex(oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (creator_version > max_creator_version)
|
if (creator_version > max_creator_version)
|
||||||
|
12
archive.c
12
archive.c
@ -121,7 +121,7 @@ static int check_attr_export_subst(const struct attr_check *check)
|
|||||||
return check && ATTR_TRUE(check->items[1].value);
|
return check && ATTR_TRUE(check->items[1].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_archive_entry(const unsigned char *sha1, const char *base,
|
static int write_archive_entry(const struct object_id *oid, const char *base,
|
||||||
int baselen, const char *filename, unsigned mode, int stage,
|
int baselen, const char *filename, unsigned mode, int stage,
|
||||||
void *context)
|
void *context)
|
||||||
{
|
{
|
||||||
@ -153,7 +153,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
|
|||||||
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
|
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
|
||||||
if (args->verbose)
|
if (args->verbose)
|
||||||
fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
|
fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
|
||||||
err = write_entry(args, sha1, path.buf, path.len, mode);
|
err = write_entry(args, oid, path.buf, path.len, mode);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
|
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
|
||||||
@ -161,7 +161,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
|
|||||||
|
|
||||||
if (args->verbose)
|
if (args->verbose)
|
||||||
fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
|
fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
|
||||||
return write_entry(args, sha1, path.buf, path.len, mode);
|
return write_entry(args, oid, path.buf, path.len, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queue_directory(const unsigned char *sha1,
|
static void queue_directory(const unsigned char *sha1,
|
||||||
@ -191,7 +191,7 @@ static int write_directory(struct archiver_context *c)
|
|||||||
d->path[d->len - 1] = '\0'; /* no trailing slash */
|
d->path[d->len - 1] = '\0'; /* no trailing slash */
|
||||||
ret =
|
ret =
|
||||||
write_directory(c) ||
|
write_directory(c) ||
|
||||||
write_archive_entry(d->oid.hash, d->path, d->baselen,
|
write_archive_entry(&d->oid, d->path, d->baselen,
|
||||||
d->path + d->baselen, d->mode,
|
d->path + d->baselen, d->mode,
|
||||||
d->stage, c) != READ_TREE_RECURSIVE;
|
d->stage, c) != READ_TREE_RECURSIVE;
|
||||||
free(d);
|
free(d);
|
||||||
@ -231,7 +231,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid,
|
|||||||
|
|
||||||
if (write_directory(c))
|
if (write_directory(c))
|
||||||
return -1;
|
return -1;
|
||||||
return write_archive_entry(oid->hash, base->buf, base->len, filename, mode,
|
return write_archive_entry(oid, base->buf, base->len, filename, mode,
|
||||||
stage, context);
|
stage, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ int write_archive_entries(struct archiver_args *args,
|
|||||||
len--;
|
len--;
|
||||||
if (args->verbose)
|
if (args->verbose)
|
||||||
fprintf(stderr, "%.*s\n", (int)len, args->base);
|
fprintf(stderr, "%.*s\n", (int)len, args->base);
|
||||||
err = write_entry(args, args->tree->object.oid.hash, args->base,
|
err = write_entry(args, &args->tree->object.oid, args->base,
|
||||||
len, 040777);
|
len, 040777);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -31,7 +31,7 @@ extern void init_tar_archiver(void);
|
|||||||
extern void init_zip_archiver(void);
|
extern void init_zip_archiver(void);
|
||||||
|
|
||||||
typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
|
typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
|
||||||
const unsigned char *sha1,
|
const struct object_id *oid,
|
||||||
const char *path, size_t pathlen,
|
const char *path, size_t pathlen,
|
||||||
unsigned int mode);
|
unsigned int mode);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user