Skip to content

Commit 1a75044

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1af64f7 commit 1a75044

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

convert.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
914914
to_free = strbuf_detach(buf, NULL);
915915
hash_object_file(src, len, "blob", &oid);
916916

917-
strbuf_grow(buf, len + cnt * 43);
917+
strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3));
918918
for (;;) {
919919
/* step 1: run to the next '$' */
920920
dollar = memchr(src, '$', len);
@@ -1510,7 +1510,7 @@ struct ident_filter {
15101510
struct stream_filter filter;
15111511
struct strbuf left;
15121512
int state;
1513-
char ident[45]; /* ": x40 $" */
1513+
char ident[GIT_MAX_HEXSZ + 5]; /* ": x40 $" */
15141514
};
15151515

15161516
static int is_foreign_ident(const char *str)
@@ -1635,12 +1635,12 @@ static struct stream_filter_vtbl ident_vtbl = {
16351635
ident_free_fn,
16361636
};
16371637

1638-
static struct stream_filter *ident_filter(const unsigned char *sha1)
1638+
static struct stream_filter *ident_filter(const struct object_id *oid)
16391639
{
16401640
struct ident_filter *ident = xmalloc(sizeof(*ident));
16411641

16421642
xsnprintf(ident->ident, sizeof(ident->ident),
1643-
": %s $", sha1_to_hex(sha1));
1643+
": %s $", oid_to_hex(oid));
16441644
strbuf_init(&ident->left, 0);
16451645
ident->filter.vtbl = &ident_vtbl;
16461646
ident->state = 0;
@@ -1655,7 +1655,7 @@ static struct stream_filter *ident_filter(const unsigned char *sha1)
16551655
* Note that you would be crazy to set CRLF, smuge/clean or ident to a
16561656
* large binary blob you would want us not to slurp into the memory!
16571657
*/
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)
16591659
{
16601660
struct conv_attrs ca;
16611661
struct stream_filter *filter = NULL;
@@ -1668,7 +1668,7 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
16681668
return NULL;
16691669

16701670
if (ca.ident)
1671-
filter = ident_filter(sha1);
1671+
filter = ident_filter(oid);
16721672

16731673
if (output_eol(ca.crlf_action) == EOL_CRLF)
16741674
filter = cascade_filter(filter, lf_to_crlf_filter());

convert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extern int would_convert_to_git_filter_fd(const char *path);
9393

9494
struct stream_filter; /* opaque */
9595

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 *);
9797
extern void free_stream_filter(struct stream_filter *);
9898
extern int is_null_stream_filter(struct stream_filter *);
9999

entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
266266

267267
if (ce_mode_s_ifmt == S_IFREG) {
268268
struct stream_filter *filter = get_stream_filter(ce->name,
269-
ce->oid.hash);
269+
&ce->oid);
270270
if (filter &&
271271
!streaming_write_entry(ce, path, filter,
272272
state, to_tempfile,

0 commit comments

Comments
 (0)