Commit 8227fea6 authored by Junio C Hamano's avatar Junio C Hamano

Merge branch 'bc/hash-transition-16' into next

Conversion from unsigned char[20] to struct object_id continues.

* bc/hash-transition-16: (35 commits)
  gitweb: make hash size independent
  Git.pm: make hash size independent
  read-cache: read data in a hash-independent way
  dir: make untracked cache extension hash size independent
  builtin/difftool: use parse_oid_hex
  refspec: make hash size independent
  archive: convert struct archiver_args to object_id
  builtin/get-tar-commit-id: make hash size independent
  get-tar-commit-id: parse comment record
  hash: add a function to lookup hash algorithm by length
  remote-curl: make hash size independent
  http: replace sha1_to_hex
  http: compute hash of downloaded objects using the_hash_algo
  http: replace hard-coded constant with the_hash_algo
  http-walker: replace sha1_to_hex
  http-push: remove remaining uses of sha1_to_hex
  http-backend: allow 64-character hex names
  http-push: convert to use the_hash_algo
  builtin/pull: make hash-size independent
  builtin/am: make hash size independent
  ...
parents 1cfd7698 cfb04911
......@@ -326,14 +326,15 @@ static int write_tar_entry(struct archiver_args *args,
static void write_global_extended_header(struct archiver_args *args)
{
const unsigned char *sha1 = args->commit_sha1;
const struct object_id *oid = args->commit_oid;
struct strbuf ext_header = STRBUF_INIT;
struct ustar_header header;
unsigned int mode;
if (sha1)
if (oid)
strbuf_append_ext_header(&ext_header, "comment",
sha1_to_hex(sha1), 40);
oid_to_hex(oid),
the_hash_algo->hexsz);
if (args->time > USTAR_MAX_MTIME) {
strbuf_append_ext_header_uint(&ext_header, "mtime",
args->time);
......
......@@ -577,7 +577,7 @@ static void write_zip64_trailer(void)
write_or_die(1, &locator64, ZIP64_DIR_TRAILER_LOCATOR_SIZE);
}
static void write_zip_trailer(const unsigned char *sha1)
static void write_zip_trailer(const struct object_id *oid)
{
struct zip_dir_trailer trailer;
int clamped = 0;
......@@ -590,14 +590,14 @@ static void write_zip_trailer(const unsigned char *sha1)
copy_le16_clamp(trailer.entries, zip_dir_entries, &clamped);
copy_le32(trailer.size, zip_dir.len);
copy_le32_clamp(trailer.offset, zip_offset, &clamped);
copy_le16(trailer.comment_length, sha1 ? GIT_SHA1_HEXSZ : 0);
copy_le16(trailer.comment_length, oid ? the_hash_algo->hexsz : 0);
write_or_die(1, zip_dir.buf, zip_dir.len);
if (clamped)
write_zip64_trailer();
write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);
if (sha1)
write_or_die(1, sha1_to_hex(sha1), GIT_SHA1_HEXSZ);
if (oid)
write_or_die(1, oid_to_hex(oid), the_hash_algo->hexsz);
}
static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
......@@ -635,7 +635,7 @@ static int write_zip_archive(const struct archiver *ar,
err = write_archive_entries(args, write_zip_entry);
if (!err)
write_zip_trailer(args->commit_sha1);
write_zip_trailer(args->commit_oid);
strbuf_release(&zip_dir);
......
......@@ -380,7 +380,7 @@ static void parse_treeish_arg(const char **argv,
int remote)
{
const char *name = argv[0];
const unsigned char *commit_sha1;
const struct object_id *commit_oid;
time_t archive_time;
struct tree *tree;
const struct commit *commit;
......@@ -402,10 +402,10 @@ static void parse_treeish_arg(const char **argv,
commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
if (commit) {
commit_sha1 = commit->object.oid.hash;
commit_oid = &commit->object.oid;
archive_time = commit->date;
} else {
commit_sha1 = NULL;
commit_oid = NULL;
archive_time = time(NULL);
}
......@@ -426,7 +426,7 @@ static void parse_treeish_arg(const char **argv,
tree = parse_tree_indirect(&tree_oid);
}
ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1;
ar_args->commit_oid = commit_oid;
ar_args->commit = commit;
ar_args->time = archive_time;
}
......
......@@ -11,7 +11,7 @@ struct archiver_args {
const char *base;
size_t baselen;
struct tree *tree;
const unsigned char *commit_sha1;
const struct object_id *commit_oid;
const struct commit *commit;
timestamp_t time;
struct pathspec pathspec;
......
......@@ -486,23 +486,24 @@ static int copy_notes_for_rebase(const struct am_state *state)
while (!strbuf_getline_lf(&sb, fp)) {
struct object_id from_obj, to_obj;
const char *p;
if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {
if (sb.len != the_hash_algo->hexsz * 2 + 1) {
ret = error(invalid_line, sb.buf);
goto finish;
}
if (get_oid_hex(sb.buf, &from_obj)) {
if (parse_oid_hex(sb.buf, &from_obj, &p)) {
ret = error(invalid_line, sb.buf);
goto finish;
}
if (sb.buf[GIT_SHA1_HEXSZ] != ' ') {
if (*p != ' ') {
ret = error(invalid_line, sb.buf);
goto finish;
}
if (get_oid_hex(sb.buf + GIT_SHA1_HEXSZ + 1, &to_obj)) {
if (get_oid_hex(p + 1, &to_obj)) {
ret = error(invalid_line, sb.buf);
goto finish;
}
......
......@@ -65,14 +65,12 @@ static int parse_index_info(char *p, int *mode1, int *mode2,
*mode2 = (int)strtol(p + 1, &p, 8);
if (*p != ' ')
return error("expected ' ', got '%c'", *p);
if (get_oid_hex(++p, oid1))
return error("expected object ID, got '%s'", p + 1);
p += GIT_SHA1_HEXSZ;
if (parse_oid_hex(++p, oid1, (const char **)&p))
return error("expected object ID, got '%s'", p);
if (*p != ' ')
return error("expected ' ', got '%c'", *p);
if (get_oid_hex(++p, oid2))
return error("expected object ID, got '%s'", p + 1);
p += GIT_SHA1_HEXSZ;
if (parse_oid_hex(++p, oid2, (const char **)&p))
return error("expected object ID, got '%s'", p);
if (*p != ' ')
return error("expected ' ', got '%c'", *p);
*status = *++p;
......
......@@ -21,6 +21,8 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
char *content = buffer + RECORDSIZE;
const char *comment;
ssize_t n;
long len;
char *end;
if (argc != 1)
usage(builtin_get_tar_commit_id_usage);
......@@ -32,10 +34,18 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
die_errno("git get-tar-commit-id: EOF before reading tar header");
if (header->typeflag[0] != 'g')
return 1;
if (!skip_prefix(content, "52 comment=", &comment))
len = strtol(content, &end, 10);
if (errno == ERANGE || end == content || len < 0)
return 1;
if (!skip_prefix(end, " comment=", &comment))
return 1;
len -= comment - content;
if (len < 1 || !(len % 2) ||
hash_algo_by_length((len - 1) / 2) == GIT_HASH_UNKNOWN)
return 1;
if (write_in_full(1, comment, 41) < 0)
if (write_in_full(1, comment, len) < 0)
die_errno("git get-tar-commit-id: write error");
return 0;
......
......@@ -361,23 +361,25 @@ static char const * const name_rev_usage[] = {
static void name_rev_line(char *p, struct name_ref_data *data)
{
struct strbuf buf = STRBUF_INIT;
int forty = 0;
int counter = 0;
char *p_start;
const unsigned hexsz = the_hash_algo->hexsz;
for (p_start = p; *p; p++) {
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
if (!ishex(*p))
forty = 0;
else if (++forty == GIT_SHA1_HEXSZ &&
counter = 0;
else if (++counter == hexsz &&
!ishex(*(p+1))) {
struct object_id oid;
const char *name = NULL;
char c = *(p+1);
int p_len = p - p_start + 1;
forty = 0;
counter = 0;
*(p+1) = 0;
if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
if (!get_oid(p - (hexsz - 1), &oid)) {
struct object *o =
lookup_object(the_repository,
oid.hash);
......@@ -390,7 +392,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
continue;
if (data->name_only)
printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name);
printf("%.*s%s", p_len - hexsz, p_start, name);
else
printf("%.*s (%s)", p_len, p_start, name);
p_start = p + 1;
......
......@@ -1487,6 +1487,7 @@ static int can_reuse_delta(const unsigned char *base_sha1,
struct object_entry **base_out)
{
struct object_entry *base;
struct object_id base_oid;
if (!base_sha1)
return 0;
......@@ -1508,10 +1509,9 @@ static int can_reuse_delta(const unsigned char *base_sha1,
* even if it was buried too deep in history to make it into the
* packing list.
*/
if (thin && bitmap_has_sha1_in_uninteresting(bitmap_git, base_sha1)) {
oidread(&base_oid, base_sha1);
if (thin && bitmap_has_oid_in_uninteresting(bitmap_git, &base_oid)) {
if (use_delta_islands) {
struct object_id base_oid;
hashcpy(base_oid.hash, base_sha1);
if (!in_same_island(&delta->idx.oid, &base_oid))
return 0;
}
......
......@@ -641,7 +641,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
pl = red = pack_list_difference(local_packs, min);
while (pl) {
printf("%s\n%s\n",
sha1_pack_index_name(pl->pack->sha1),
sha1_pack_index_name(pl->pack->hash),
pl->pack->pack_name);
pl = pl->next;
}
......
......@@ -369,9 +369,10 @@ static void get_merge_heads(struct oid_array *merge_heads)
fp = xfopen(filename, "r");
while (strbuf_getline_lf(&sb, fp) != EOF) {
if (get_oid_hex(sb.buf, &oid))
continue; /* invalid line: does not start with SHA1 */
if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
const char *p;
if (parse_oid_hex(sb.buf, &oid, &p))
continue; /* invalid line: does not start with object ID */
if (starts_with(p, "\tnot-for-merge\t"))
continue; /* ref is not-for-merge */
oid_array_append(merge_heads, &oid);
}
......@@ -760,7 +761,7 @@ static int get_rebase_fork_point(struct object_id *fork_point, const char *repo,
cp.no_stderr = 1;
cp.git_cmd = 1;
ret = capture_command(&cp, &sb, GIT_SHA1_HEXSZ);
ret = capture_command(&cp, &sb, GIT_MAX_HEXSZ);
if (ret)
goto cleanup;
......@@ -805,7 +806,7 @@ static int get_octopus_merge_base(struct object_id *merge_base,
}
/**
* Given the current HEAD SHA1, the merge head returned from git-fetch and the
* Given the current HEAD oid, the merge head returned from git-fetch and the
* fork point calculated by get_rebase_fork_point(), runs git-rebase with the
* appropriate arguments and returns its exit status.
*/
......
......@@ -2544,13 +2544,9 @@ struct ondisk_untracked_cache {
struct stat_data info_exclude_stat;
struct stat_data excludes_file_stat;
uint32_t dir_flags;
unsigned char info_exclude_sha1[20];
unsigned char excludes_file_sha1[20];
char exclude_per_dir[FLEX_ARRAY];
};
#define ouc_offset(x) offsetof(struct ondisk_untracked_cache, x)
#define ouc_size(len) (ouc_offset(exclude_per_dir) + len + 1)
struct write_data {
int index; /* number of written untracked_cache_dir */
......@@ -2633,20 +2629,21 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
struct write_data wd;
unsigned char varbuf[16];
int varint_len;
size_t len = strlen(untracked->exclude_per_dir);
const unsigned hashsz = the_hash_algo->rawsz;
FLEX_ALLOC_MEM(ouc, exclude_per_dir, untracked->exclude_per_dir, len);
ouc = xcalloc(1, sizeof(*ouc));
stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);
stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);
hashcpy(ouc->info_exclude_sha1, untracked->ss_info_exclude.oid.hash);
hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.oid.hash);
ouc->dir_flags = htonl(untracked->dir_flags);
varint_len = encode_varint(untracked->ident.len, varbuf);
strbuf_add(out, varbuf, varint_len);
strbuf_addbuf(out, &untracked->ident);
strbuf_add(out, ouc, ouc_size(len));
strbuf_add(out, ouc, sizeof(*ouc));
strbuf_add(out, untracked->ss_info_exclude.oid.hash, hashsz);
strbuf_add(out, untracked->ss_excludes_file.oid.hash, hashsz);
strbuf_add(out, untracked->exclude_per_dir, strlen(untracked->exclude_per_dir) + 1);
FREE_AND_NULL(ouc);
if (!untracked->root) {
......@@ -2833,6 +2830,9 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
int ident_len;
ssize_t len;
const char *exclude_per_dir;
const unsigned hashsz = the_hash_algo->rawsz;
const unsigned offset = sizeof(struct ondisk_untracked_cache);
const unsigned exclude_per_dir_offset = offset + 2 * hashsz;
if (sz <= 1 || end[-1] != '\0')
return NULL;
......@@ -2844,7 +2844,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
ident = (const char *)next;
next += ident_len;
if (next + ouc_size(0) > end)
if (next + exclude_per_dir_offset + 1 > end)
return NULL;
uc = xcalloc(1, sizeof(*uc));
......@@ -2852,15 +2852,15 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
strbuf_add(&uc->ident, ident, ident_len);
load_oid_stat(&uc->ss_info_exclude,
next + ouc_offset(info_exclude_stat),
next + ouc_offset(info_exclude_sha1));
next + offset);
load_oid_stat(&uc->ss_excludes_file,
next + ouc_offset(excludes_file_stat),
next + ouc_offset(excludes_file_sha1));
next + offset + hashsz);
uc->dir_flags = get_be32(next + ouc_offset(dir_flags));
exclude_per_dir = (const char *)next + ouc_offset(exclude_per_dir);
exclude_per_dir = (const char *)next + exclude_per_dir_offset;
uc->exclude_per_dir = xstrdup(exclude_per_dir);
/* NUL after exclude_per_dir is covered by sizeof(*ouc) */
next += ouc_size(strlen(exclude_per_dir));
next += exclude_per_dir_offset + strlen(exclude_per_dir) + 1;
if (next >= end)
goto done2;
......
......@@ -29,6 +29,13 @@
*/
#define NO_DELTA S_ISUID
/*
* The amount of additional space required in order to write an object into the
* current pack. This is the hash lengths at the end of the pack, plus the
* length of one object ID.
*/
#define PACK_SIZE_THRESHOLD (the_hash_algo->rawsz * 3)
struct object_entry {
struct pack_idx_entry idx;
struct object_entry *next;
......@@ -742,7 +749,8 @@ static const char *create_index(void)
if (c != last)
die("internal consistency error creating the index");
tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts, pack_data->sha1);
tmpfile = write_idx_file(NULL, idx, object_count, &pack_idx_opts,
pack_data->hash);
free(idx);
return tmpfile;
}
......@@ -753,7 +761,7 @@ static char *keep_pack(const char *curr_index_name)
struct strbuf name = STRBUF_INIT;
int keep_fd;
odb_pack_name(&name, pack_data->sha1, "keep");
odb_pack_name(&name, pack_data->hash, "keep");
keep_fd = odb_pack_keep(name.buf);
if (keep_fd < 0)
die_errno("cannot create keep file");
......@@ -761,11 +769,11 @@ static char *keep_pack(const char *curr_index_name)
if (close(keep_fd))
die_errno("failed to write keep file");
odb_pack_name(&name, pack_data->sha1, "pack");
odb_pack_name(&name, pack_data->hash, "pack");
if (finalize_object_file(pack_data->pack_name, name.buf))
die("cannot store pack file");
odb_pack_name(&name, pack_data->sha1, "idx");
odb_pack_name(&name, pack_data->hash, "idx");
if (finalize_object_file(curr_index_name, name.buf))
die("cannot store index file");
free((void *)curr_index_name);
......@@ -779,7 +787,7 @@ static void unkeep_all_packs(void)
for (k = 0; k < pack_id; k++) {
struct packed_git *p = all_packs[k];
odb_pack_name(&name, p->sha1, "keep");
odb_pack_name(&name, p->hash, "keep");
unlink_or_warn(name.buf);
}
strbuf_release(&name);
......@@ -821,9 +829,9 @@ static void end_packfile(void)
close_pack_windows(pack_data);
finalize_hashfile(pack_file, cur_pack_oid.hash, 0);
fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,
pack_data->pack_name, object_count,
cur_pack_oid.hash, pack_size);
fixup_pack_header_footer(pack_data->pack_fd, pack_data->hash,
pack_data->pack_name, object_count,
cur_pack_oid.hash, pack_size);
if (object_count <= unpack_limit) {
if (!loosen_small_pack(pack_data)) {
......@@ -948,8 +956,9 @@ static int store_object(
git_deflate_end(&s);
/* Determine if we should auto-checkpoint. */
if ((max_packsize && (pack_size + 60 + s.total_out) > max_packsize)
|| (pack_size + 60 + s.total_out) < pack_size) {
if ((max_packsize
&& (pack_size + PACK_SIZE_THRESHOLD + s.total_out) > max_packsize)
|| (pack_size + PACK_SIZE_THRESHOLD + s.total_out) < pack_size) {
/* This new object needs to *not* have the current pack_id. */
e->pack_id = pack_id + 1;
......@@ -1044,8 +1053,9 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
int status = Z_OK;
/* Determine if we should auto-checkpoint. */
if ((max_packsize && (pack_size + 60 + len) > max_packsize)
|| (pack_size + 60 + len) < pack_size)
if ((max_packsize
&& (pack_size + PACK_SIZE_THRESHOLD + len) > max_packsize)
|| (pack_size + PACK_SIZE_THRESHOLD + len) < pack_size)
cycle_packfile();
hashfile_checkpoint(pack_file, &checkpoint);
......@@ -1240,7 +1250,7 @@ static void load_tree(struct tree_entry *root)
c += e->name->str_len + 1;
hashcpy(e->versions[0].oid.hash, (unsigned char *)c);
hashcpy(e->versions[1].oid.hash, (unsigned char *)c);
c += GIT_SHA1_RAWSZ;
c += the_hash_algo->rawsz;
}
free(buf);
}
......@@ -1287,7 +1297,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b)
strbuf_addf(b, "%o %s%c",
(unsigned int)(e->versions[v].mode & ~NO_DELTA),
e->name->str_dat, '\0');
strbuf_add(b, e->versions[v].oid.hash, GIT_SHA1_RAWSZ);
strbuf_add(b, e->versions[v].oid.hash, the_hash_algo->rawsz);
}
}
......@@ -2036,7 +2046,9 @@ static uintmax_t do_change_note_fanout(
unsigned int i, tmp_hex_oid_len, tmp_fullpath_len;
uintmax_t num_notes = 0;
struct object_id oid;
char realpath[60];
/* hex oid + '/' between each pair of hex digits + NUL */
char realpath[GIT_MAX_HEXSZ + ((GIT_MAX_HEXSZ / 2) - 1) + 1];
const unsigned hexsz = the_hash_algo->hexsz;
if (!root->tree)
load_tree(root);
......@@ -2056,7 +2068,7 @@ static uintmax_t do_change_note_fanout(
* of 2 chars.
*/
if (!e->versions[1].mode ||
tmp_hex_oid_len > GIT_SHA1_HEXSZ ||
tmp_hex_oid_len > hexsz ||
e->name->str_len % 2)
continue;
......@@ -2070,7 +2082,7 @@ static uintmax_t do_change_note_fanout(
tmp_fullpath_len += e->name->str_len;
fullpath[tmp_fullpath_len] = '\0';
if (tmp_hex_oid_len == GIT_SHA1_HEXSZ && !get_oid_hex(hex_oid, &oid)) {
if (tmp_hex_oid_len == hexsz && !get_oid_hex(hex_oid, &oid)) {
/* This is a note entry */
if (fanout == 0xff) {
/* Counting mode, no rename */
......@@ -2348,7 +2360,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
struct object_entry *oe;
struct branch *s;
struct object_id oid, commit_oid;
char path[60];
char path[GIT_MAX_RAWSZ * 3];
uint16_t inline_data = 0;
unsigned char new_fanout;
......@@ -2401,7 +2413,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
char *buf = read_object_with_reference(&commit_oid,
commit_type, &size,
&commit_oid);
if (!buf || size < 46)
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", p);
free(buf);
} else
......@@ -2452,7 +2464,7 @@ static void file_change_deleteall(struct branch *b)
static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
{
if (!buf || size < GIT_SHA1_HEXSZ + 6)
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", oid_to_hex(&b->oid));
if (memcmp("tree ", buf, 5)
|| get_oid_hex(buf + 5, &b->branch_tree.versions[1].oid))
......@@ -2551,7 +2563,7 @@ static struct hash_list *parse_merge(unsigned int *count)
char *buf = read_object_with_reference(&n->oid,
commit_type,
&size, &n->oid);
if (!buf || size < 46)
if (!buf || size < the_hash_algo->hexsz + 6)
die("Not a valid commit: %s", from);
free(buf);
} else
......@@ -2840,7 +2852,7 @@ static void parse_get_mark(const char *p)
die("Unknown mark: %s", command_buf.buf);
xsnprintf(output, sizeof(output), "%s\n", oid_to_hex(&oe->idx.oid));
cat_blob_write(output, GIT_SHA1_HEXSZ + 1);
cat_blob_write(output, the_hash_algo->hexsz + 1);
}
static void parse_cat_blob(const char *p)
......@@ -2870,6 +2882,8 @@ static struct object_entry *dereference(struct object_entry *oe,
{
unsigned long size;
char *buf = NULL;
const unsigned hexsz = the_hash_algo->hexsz;
if (!oe) {
enum object_type type = oid_object_info(the_repository, oid,
NULL);
......@@ -2903,12 +2917,12 @@ static struct object_entry *dereference(struct object_entry *oe,
/* Peel one layer. */
switch (oe->type) {
case OBJ_TAG:
if (size < GIT_SHA1_HEXSZ + strlen("object ") ||
if (size < hexsz + strlen("object ") ||
get_oid_hex(buf + strlen("object "), oid))
die("Invalid SHA1 in tag: %s", command_buf.buf);
break;
case OBJ_COMMIT:
if (size < GIT_SHA1_HEXSZ + strlen("tree ") ||
if (size < hexsz + strlen("tree ") ||
get_oid_hex(buf + strlen("tree "), oid))
die("Invalid SHA1 in commit: %s", command_buf.buf);
}
......@@ -2940,7 +2954,7 @@ static struct object_entry *parse_treeish_dataref(const char **p)
return e;
}
static void print_ls(int mode, const unsigned char *sha1, const char *path)
static void print_ls(int mode, const unsigned char *hash, const char *path)
{
static struct strbuf line = STRBUF_INIT;
......@@ -2960,7 +2974,7 @@ static void print_ls(int mode, const unsigned char *sha1, const char *path)
/* mode SP type SP object_name TAB path LF */
strbuf_reset(&line);
strbuf_addf(&line, "%06o %s %s\t",
mode & ~NO_DELTA, type, sha1_to_hex(sha1));
mode & ~NO_DELTA, type, hash_to_hex(hash));
quote_c_style(path, &line, NULL, 0);
strbuf_addch(&line, '\n');
}
......
This diff is collapsed.
......@@ -131,6 +131,8 @@ extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
int hash_algo_by_name(const char *name);
/* Identical, except based on the format ID. */
int hash_algo_by_id(uint32_t format_id);
/* Identical, except based on the length. */
int hash_algo_by_length(int len);
/* Identical, except for a pointer to struct git_hash_algo. */
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
{
......
......@@ -711,8 +711,11 @@ static struct service_cmd {
{"GET", "/objects/info/http-alternates$", get_text_file},
{"GET", "/objects/info/packs$", get_info_packs},
{"GET", "/objects/[0-9a-f]{2}/[0-9a-f]{38}$", get_loose_object},
{"GET", "/objects/[0-9a-f]{2}/[0-9a-f]{62}$", get_loose_object},
{"GET", "/objects/pack/pack-[0-9a-f]{40}\\.pack$", get_pack_file},
{"GET", "/objects/pack/pack-[0-9a-f]{64}\\.pack$", get_pack_file},
{"GET", "/objects/pack/pack-[0-9a-f]{40}\\.idx$", get_idx_file},
{"GET", "/objects/pack/pack-[0-9a-f]{64}\\.idx$", get_idx_file},
{"POST", "/git-upload-pack$", service_rpc},
{"POST", "/git-receive-pack$", service_rpc}
......
......@@ -145,7 +145,7 @@ struct remote_lock {
char *url;
char *owner;
char *token;
char tmpfile_suffix[41];
char tmpfile_suffix[GIT_MAX_HEXSZ + 1];
time_t start_time;
long timeout;
int refreshing;
......@@ -315,7 +315,8 @@ static void start_fetch_packed(struct transfer_request *request)
return;
}
fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1));
fprintf(stderr, "Fetching pack %s\n",
hash_to_hex(target->hash));
fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid));
preq = new_http_pack_request(target, repo->url);
......@@ -398,7 +399,7 @@ static void start_put(struct transfer_request *request)
request->dest = strbuf_detach(&buf, NULL);
append_remote_object_url(&buf, repo->url, hex, 0);
strbuf_add(&buf, request->lock->tmpfile_suffix, 41);
strbuf_add(&buf, request->lock->tmpfile_suffix, the_hash_algo->hexsz + 1);
request->url = strbuf_detach(&buf, NULL);
slot = get_active_slot();
......@@ -757,8 +758,8 @@ static void handle_lockprop_ctx(struct xml_ctx *ctx, int tag_closed)
static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
{
struct remote_lock *lock = (struct remote_lock *)ctx->userData;
git_SHA_CTX sha_ctx;
unsigned char lock_token_sha1[20];
git_hash_ctx hash_ctx;
unsigned char lock_token_hash[GIT_MAX_RAWSZ];
if (tag_closed && ctx->cdata) {
if (!strcmp(ctx->name, DAV_ACTIVELOCK_OWNER)) {
......@@ -770,12 +771,12 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
} else if (!strcmp(ctx->name, DAV_ACTIVELOCK_TOKEN)) {
lock->token = xstrdup(ctx->cdata);
git_SHA1_Init(&sha_ctx);
git_SHA1_Update(&sha_ctx, lock->token, strlen(lock->token));
git_SHA1_Final(lock_token_sha1, &sha_ctx);
the_hash_algo->init_fn(&hash_ctx);
the_hash_algo->update_fn(&hash_ctx, lock->token, strlen(lock->token));
the_hash_algo->final_fn(lock_token_hash, &hash_ctx);
lock->tmpfile_suffix[0] = '_';
memcpy(lock->tmpfile_suffix + 1, sha1_to_hex(lock_token_sha1), 40);
memcpy(lock->tmpfile_suffix + 1, hash_to_hex(lock_token_hash), the_hash_algo->hexsz);
}
}
}
......@@ -1017,7 +1018,7 @@ static void remote_ls(const char *path, int flags,
/* extract hex from sharded "xx/x{38}" filename */
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{
if (strlen(path) != GIT_SHA1_HEXSZ + 1)
if (strlen(path) != the_hash_algo->hexsz + 1)
return -1;
if (hex_to_bytes(oid->hash, path, 1))
......@@ -1025,7 +1026,7 @@ static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
path += 2;
path++; /* skip '/' */
return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1);
return hex_to_bytes(oid->hash + 1, path, the_hash_algo->rawsz - 1);
}
static void process_ls_object(struct remote_ls_ctx *ls)
......@@ -1373,7 +1374,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
return count;
}
static int update_remote(unsigned char *sha1, struct remote_lock *lock)
static int update_remote(const struct object_id *oid, struct remote_lock *lock)
{
struct active_request_slot *slot;
struct slot_results results;
......@@ -1382,7 +1383,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
dav_headers = get_dav_token_headers(lock, DAV_HEADER_IF);
strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1));
strbuf_addf(&out_buffer.buf, "%s\n", oid_to_hex(oid));
slot = get_active_slot();
slot->results = &results;
......@@ -1947,7 +1948,7 @@ int cmd_main(int argc, const char **argv)
run_request_queue();
/* Update the remote branch if all went well */
if (aborted || !update_remote(ref->new_oid.hash, ref_lock))
if (aborted || !update_remote(&ref->new_oid, ref_lock))
rc = 1;
if (!rc)
......
......@@ -442,9 +442,9 @@ static int http_fetch_pack(struct walker *walker, struct alt_base *repo, unsigne
if (walker->get_verbosely) {
fprintf(stderr, "Getting pack %s\n",
sha1_to_hex(target->sha1));
hash_to_hex(target->hash));
fprintf(stderr, " which contains %s\n",
sha1_to_hex(sha1));
hash_to_hex(sha1));
}
preq = new_http_pack_request(target, repo->base);
......@@ -481,9 +481,9 @@ static void abort_object_request(struct object_request *obj_req)
release_object_request(obj_req);
}