*/
#include <time.h>
#include "cache.h"
-#include "diff.h"
+#include "tree-walk.h"
#include "commit.h"
#include "strbuf.h"
#include "tar.h"
}
if (size) {
memcpy(block + offset, buf, size);
- buf += size;
offset += size;
}
tail = offset % RECORDSIZE;
return chksum;
}
+static int get_path_prefix(const struct strbuf *path, int maxlen)
+{
+ int i = path->len;
+ if (i > maxlen)
+ i = maxlen;
+ while (i > 0 && path->buf[i] != '/')
+ i--;
+ return i;
+}
+
static void write_entry(const unsigned char *sha1, struct strbuf *path,
unsigned int mode, void *buffer, unsigned long size)
{
return;
}
if (path->len > sizeof(header.name)) {
- sprintf(header.name, "%s.data", sha1_to_hex(sha1));
- strbuf_append_ext_header(&ext_header, "path",
- path->buf, path->len);
+ int plen = get_path_prefix(path, sizeof(header.prefix));
+ int rest = path->len - plen - 1;
+ if (plen > 0 && rest <= sizeof(header.name)) {
+ memcpy(header.prefix, path->buf, plen);
+ memcpy(header.name, path->buf + plen + 1, rest);
+ } else {
+ sprintf(header.name, "%s.data",
+ sha1_to_hex(sha1));
+ strbuf_append_ext_header(&ext_header, "path",
+ path->buf, path->len);
+ }
} else
memcpy(header.name, path->buf, path->len);
}
current_path.len = current_path.eof = 0;
setup_git_directory();
+ git_config(git_default_config);
switch (argc) {
case 3:
} else
archive_time = time(NULL);
- tree.buf = read_object_with_reference(sha1, "tree", &tree.size,
+ tree.buf = read_object_with_reference(sha1, tree_type, &tree.size,
tree_sha1);
if (!tree.buf)
die("not a reference to a tag, commit or tree object: %s",