convert: convert to struct object_id
Convert convert.c to struct object_id. Add a use of the_hash_algo to replace hard-coded constants and change a strbuf_add to a strbuf_addstr to avoid another hard-coded constant. Note that a strict conversion using the hexsz constant would cause problems in the future if the internal and user-visible hash algorithms differed, as anticipated by the hash function transition plan. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 12, 2018 at 02:27 UTC
1a750441a7360b29fff7a414649ece1d35acaca6
3 files changed
+8
-8
convert.c
+6
-6
@@ -914,7 +914,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
914
to_free = strbuf_detach(buf, NULL);
915
hash_object_file(src, len, "blob", &oid);
916
917
- strbuf_grow(buf, len + cnt * 43);
917
+ strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3));
918
for (;;) {
919
/* step 1: run to the next '$' */
920
dollar = memchr(src, '$', len);
@@ -1510,7 +1510,7 @@ struct ident_filter {
1510
struct stream_filter filter;
1511
struct strbuf left;
1512
int state;
1513
- char ident[45]; /* ": x40 $" */
1513
+ char ident[GIT_MAX_HEXSZ + 5]; /* ": x40 $" */
1514
};
1515
1516
static int is_foreign_ident(const char *str)
@@ -1635,12 +1635,12 @@ static struct stream_filter_vtbl ident_vtbl = {
1635
ident_free_fn,
1636
};
1637
1638
-static struct stream_filter *ident_filter(const unsigned char *sha1)
1638
+static struct stream_filter *ident_filter(const struct object_id *oid)
1639
{
1640
struct ident_filter *ident = xmalloc(sizeof(*ident));
1641
1642
xsnprintf(ident->ident, sizeof(ident->ident),
1643
- ": %s $", sha1_to_hex(sha1));
1643
+ ": %s $", oid_to_hex(oid));
1644
strbuf_init(&ident->left, 0);
1645
ident->filter.vtbl = &ident_vtbl;
1646
ident->state = 0;
@@ -1655,7 +1655,7 @@ static struct stream_filter *ident_filter(const unsigned char *sha1)
1655
* Note that you would be crazy to set CRLF, smuge/clean or ident to a
1656
* large binary blob you would want us not to slurp into the memory!
1657
*/
1658
-struct stream_filter *get_stream_filter(const char *path, const unsigned char *sha1)
1658
+struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
1659
{
1660
struct conv_attrs ca;
1661
struct stream_filter *filter = NULL;
@@ -1668,7 +1668,7 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
1668
return NULL;
1669
1670
if (ca.ident)
1671
- filter = ident_filter(sha1);
1671
+ filter = ident_filter(oid);
1672
1673
if (output_eol(ca.crlf_action) == EOL_CRLF)
1674
filter = cascade_filter(filter, lf_to_crlf_filter());
convert.h
+1
-1
@@ -93,7 +93,7 @@ extern int would_convert_to_git_filter_fd(const char *path);
93
94
struct stream_filter; /* opaque */
95
96
-extern struct stream_filter *get_stream_filter(const char *path, const unsigned char *);
96
+extern struct stream_filter *get_stream_filter(const char *path, const struct object_id *);
97
extern void free_stream_filter(struct stream_filter *);
98
extern int is_null_stream_filter(struct stream_filter *);
99
entry.c
+1
-1
@@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
266
267
if (ce_mode_s_ifmt == S_IFREG) {
268
struct stream_filter *filter = get_stream_filter(ce->name,
269
- ce->oid.hash);
269
+ &ce->oid);
270
if (filter &&
271
!streaming_write_entry(ce, path, filter,
272
state, to_tempfile,