Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
cache-tree: convert remnants to struct object_id
author
brian m. carlson
<sandals@crustytoothpaste.net>
Mon, 12 Mar 2018 02:27:24 +0000
(
02:27
+0000)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 14 Mar 2018 16:23:47 +0000
(09:23 -0700)
Convert the remaining portions of cache-tree.c to use struct object_id.
Convert several instances of 20 to use the_hash_algo instead.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache-tree.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
fc5cb99
)
diff --git
a/cache-tree.c
b/cache-tree.c
index ba07a8067ebe583f5d9e4f47c3fb9d358ff8ff54..6a555f4d431f9f6dbf8dad06d75a4ec81a4254fd 100644
(file)
--- a/
cache-tree.c
+++ b/
cache-tree.c
@@
-320,7
+320,7
@@
static int update_one(struct cache_tree *it,
struct cache_tree_sub *sub = NULL;
const char *path, *slash;
int pathlen, entlen;
struct cache_tree_sub *sub = NULL;
const char *path, *slash;
int pathlen, entlen;
- const
unsigned char *sha1
;
+ const
struct object_id *oid
;
unsigned mode;
int expected_missing = 0;
int contains_ita = 0;
unsigned mode;
int expected_missing = 0;
int contains_ita = 0;
@@
-338,7
+338,7
@@
static int update_one(struct cache_tree *it,
die("cache-tree.c: '%.*s' in '%s' not found",
entlen, path + baselen, path);
i += sub->count;
die("cache-tree.c: '%.*s' in '%s' not found",
entlen, path + baselen, path);
i += sub->count;
-
sha1 = sub->cache_tree->oid.hash
;
+
oid = &sub->cache_tree->oid
;
mode = S_IFDIR;
contains_ita = sub->cache_tree->entry_count < 0;
if (contains_ita) {
mode = S_IFDIR;
contains_ita = sub->cache_tree->entry_count < 0;
if (contains_ita) {
@@
-347,19
+347,19
@@
static int update_one(struct cache_tree *it,
}
}
else {
}
}
else {
-
sha1 = ce->oid.hash
;
+
oid = &ce->oid
;
mode = ce->ce_mode;
entlen = pathlen - baselen;
i++;
}
mode = ce->ce_mode;
entlen = pathlen - baselen;
i++;
}
- if (is_null_
sha1(sha1
) ||
- (mode != S_IFGITLINK && !missing_ok && !has_
sha1_file(sha1
))) {
+ if (is_null_
oid(oid
) ||
+ (mode != S_IFGITLINK && !missing_ok && !has_
object_file(oid
))) {
strbuf_release(&buffer);
if (expected_missing)
return -1;
return error("invalid object %06o %s for '%.*s'",
strbuf_release(&buffer);
if (expected_missing)
return -1;
return error("invalid object %06o %s for '%.*s'",
- mode,
sha1_to_hex(sha1
), entlen+baselen, path);
+ mode,
oid_to_hex(oid
), entlen+baselen, path);
}
/*
}
/*
@@
-385,12
+385,12
@@
static int update_one(struct cache_tree *it,
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
/*
* "sub" can be an empty tree if all subentries are i-t-a.
*/
- if (contains_ita && !
hashcmp(sha1, EMPTY_TREE_SHA1_BIN
))
+ if (contains_ita && !
oidcmp(oid, &empty_tree_oid
))
continue;
strbuf_grow(&buffer, entlen + 100);
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
continue;
strbuf_grow(&buffer, entlen + 100);
strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
- strbuf_add(&buffer,
sha1, 20
);
+ strbuf_add(&buffer,
oid->hash, the_hash_algo->rawsz
);
#if DEBUG
fprintf(stderr, "cache-tree update-one %o %.*s\n",
#if DEBUG
fprintf(stderr, "cache-tree update-one %o %.*s\n",
@@
-401,7
+401,7
@@
static int update_one(struct cache_tree *it,
if (repair) {
struct object_id oid;
hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
if (repair) {
struct object_id oid;
hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
- if (has_
sha1_file(oid.hash
))
+ if (has_
object_file(&oid
))
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
oidcpy(&it->oid, &oid);
else
to_invalidate = 1;
@@
-465,7
+465,7
@@
static void write_one(struct strbuf *buffer, struct cache_tree *it,
#endif
if (0 <= it->entry_count) {
#endif
if (0 <= it->entry_count) {
- strbuf_add(buffer, it->oid.hash,
20
);
+ strbuf_add(buffer, it->oid.hash,
the_hash_algo->rawsz
);
}
for (i = 0; i < it->subtree_nr; i++) {
struct cache_tree_sub *down = it->down[i];
}
for (i = 0; i < it->subtree_nr; i++) {
struct cache_tree_sub *down = it->down[i];
@@
-492,6
+492,7
@@
static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
char *ep;
struct cache_tree *it;
int i, subtree_nr;
char *ep;
struct cache_tree *it;
int i, subtree_nr;
+ const unsigned rawsz = the_hash_algo->rawsz;
it = NULL;
/* skip name, but make sure name exists */
it = NULL;
/* skip name, but make sure name exists */
@@
-520,11
+521,11
@@
static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
goto free_return;
buf++; size--;
if (0 <= it->entry_count) {
goto free_return;
buf++; size--;
if (0 <= it->entry_count) {
- if (size <
20
)
+ if (size <
rawsz
)
goto free_return;
goto free_return;
-
hashcpy(it->oid.hash, (const unsigned char*)buf
);
- buf +=
20
;
- size -=
20
;
+
memcpy(it->oid.hash, (const unsigned char*)buf, rawsz
);
+ buf +=
rawsz
;
+ size -=
rawsz
;
}
#if DEBUG
}
#if DEBUG