#define GET_NIBBLE(n, sha1) ((((sha1)[(n) >> 1]) >> ((~(n) & 0x01) << 2)) & 0x0f)
-#define KEY_INDEX (GIT_SHA1_RAWSZ - 1)
-#define FANOUT_PATH_SEPARATORS ((GIT_SHA1_HEXSZ / 2) - 1)
+#define KEY_INDEX (the_hash_algo->rawsz - 1)
+#define FANOUT_PATH_SEPARATORS (the_hash_algo->rawsz - 1)
+#define FANOUT_PATH_SEPARATORS_MAX ((GIT_MAX_HEXSZ / 2) - 1)
#define SUBTREE_SHA1_PREFIXCMP(key_sha1, subtree_sha1) \
(memcmp(key_sha1, subtree_sha1, subtree_sha1[KEY_INDEX]))
struct leaf_node *entry)
{
struct leaf_node *l;
- struct int_node *parent_stack[GIT_SHA1_RAWSZ];
+ struct int_node *parent_stack[GIT_MAX_RAWSZ];
unsigned char i, j;
void **p = note_tree_search(t, &tree, &n, entry->key_oid.hash);
void *buf;
struct tree_desc desc;
struct name_entry entry;
+ const unsigned hashsz = the_hash_algo->rawsz;
- buf = fill_tree_descriptor(&desc, &subtree->val_oid);
+ buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
if (!buf)
die("Could not read %s for notes-index",
oid_to_hex(&subtree->val_oid));
prefix_len = subtree->key_oid.hash[KEY_INDEX];
- if (prefix_len >= GIT_SHA1_RAWSZ)
+ if (prefix_len >= hashsz)
BUG("prefix_len (%"PRIuMAX") is out of range", (uintmax_t)prefix_len);
if (prefix_len * 2 < n)
BUG("prefix_len (%"PRIuMAX") is too small", (uintmax_t)prefix_len);
struct leaf_node *l;
size_t path_len = strlen(entry.path);
- if (path_len == 2 * (GIT_SHA1_RAWSZ - prefix_len)) {
+ if (path_len == 2 * (hashsz - prefix_len)) {
/* This is potentially the remainder of the SHA-1 */
if (!S_ISREG(entry.mode))
goto handle_non_note;
if (hex_to_bytes(object_oid.hash + prefix_len, entry.path,
- GIT_SHA1_RAWSZ - prefix_len))
+ hashsz - prefix_len))
goto handle_non_note; /* entry.path is not a SHA1 */
type = PTR_TYPE_NOTE;
* except for the last byte, where we write
* the length:
*/
- memset(object_oid.hash + len, 0, GIT_SHA1_RAWSZ - len - 1);
+ memset(object_oid.hash + len, 0, hashsz - len - 1);
object_oid.hash[KEY_INDEX] = (unsigned char)len;
type = PTR_TYPE_SUBTREE;
return fanout + 1;
}
-/* hex SHA1 + 19 * '/' + NUL */
-#define FANOUT_PATH_MAX GIT_SHA1_HEXSZ + FANOUT_PATH_SEPARATORS + 1
+/* hex oid + '/' between each pair of hex digits + NUL */
+#define FANOUT_PATH_MAX GIT_MAX_HEXSZ + FANOUT_PATH_SEPARATORS_MAX + 1
-static void construct_path_with_fanout(const unsigned char *sha1,
+static void construct_path_with_fanout(const unsigned char *hash,
unsigned char fanout, char *path)
{
unsigned int i = 0, j = 0;
- const char *hex_sha1 = sha1_to_hex(sha1);
- assert(fanout < GIT_SHA1_RAWSZ);
+ const char *hex_hash = hash_to_hex(hash);
+ assert(fanout < the_hash_algo->rawsz);
while (fanout) {
- path[i++] = hex_sha1[j++];
- path[i++] = hex_sha1[j++];
+ path[i++] = hex_hash[j++];
+ path[i++] = hex_hash[j++];
path[i++] = '/';
fanout--;
}
- xsnprintf(path + i, FANOUT_PATH_MAX - i, "%s", hex_sha1 + j);
+ xsnprintf(path + i, FANOUT_PATH_MAX - i, "%s", hex_hash + j);
}
static int for_each_note_helper(struct notes_tree *t, struct int_node *tree,
static void write_tree_entry(struct strbuf *buf, unsigned int mode,
const char *path, unsigned int path_len, const
- unsigned char *sha1)
+ unsigned char *hash)
{
strbuf_addf(buf, "%o %.*s%c", mode, path_len, path, '\0');
- strbuf_add(buf, sha1, GIT_SHA1_RAWSZ);
+ strbuf_add(buf, hash, the_hash_algo->rawsz);
}
static void tree_write_stack_init_subtree(struct tree_write_stack *tws,
n = (struct tree_write_stack *)
xmalloc(sizeof(struct tree_write_stack));
n->next = NULL;
- strbuf_init(&n->buf, 256 * (32 + GIT_SHA1_HEXSZ)); /* assume 256 entries per tree */
+ strbuf_init(&n->buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries per tree */
n->path[0] = n->path[1] = '\0';
tws->next = n;
tws->path[0] = path[0];
note_path[note_path_len] = '\0';
mode = 040000;
}
- assert(note_path_len <= GIT_SHA1_HEXSZ + FANOUT_PATH_SEPARATORS);
+ assert(note_path_len <= GIT_MAX_HEXSZ + FANOUT_PATH_SEPARATORS);
/* Weave non-note entries into note entries */
return write_each_non_note_until(note_path, d) ||
combine_notes_fn combine_notes, int flags)
{
struct object_id oid, object_oid;
- unsigned mode;
+ unsigned short mode;
struct leaf_node root_tree;
if (!t)
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref);
- if (get_tree_entry(&object_oid, "", &oid, &mode))
+ if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid));
/* Prepare for traversal of current notes tree */
root.next = NULL; /* last forward entry in list is grounded */
- strbuf_init(&root.buf, 256 * (32 + GIT_SHA1_HEXSZ)); /* assume 256 entries */
+ strbuf_init(&root.buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries */
root.path[0] = root.path[1] = '\0';
cb_data.root = &root;
cb_data.next_non_note = t->first_non_note;
while (l) {
if (flags & NOTES_PRUNE_VERBOSE)
- printf("%s\n", sha1_to_hex(l->sha1));
+ printf("%s\n", hash_to_hex(l->sha1));
if (!(flags & NOTES_PRUNE_DRYRUN))
remove_note(t, l->sha1);
l = l->next;