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>
This commit is contained in:
parent
1af64f73a9
commit
1a750441a7
12
convert.c
12
convert.c
@ -914,7 +914,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
|
|||||||
to_free = strbuf_detach(buf, NULL);
|
to_free = strbuf_detach(buf, NULL);
|
||||||
hash_object_file(src, len, "blob", &oid);
|
hash_object_file(src, len, "blob", &oid);
|
||||||
|
|
||||||
strbuf_grow(buf, len + cnt * 43);
|
strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* step 1: run to the next '$' */
|
/* step 1: run to the next '$' */
|
||||||
dollar = memchr(src, '$', len);
|
dollar = memchr(src, '$', len);
|
||||||
@ -1510,7 +1510,7 @@ struct ident_filter {
|
|||||||
struct stream_filter filter;
|
struct stream_filter filter;
|
||||||
struct strbuf left;
|
struct strbuf left;
|
||||||
int state;
|
int state;
|
||||||
char ident[45]; /* ": x40 $" */
|
char ident[GIT_MAX_HEXSZ + 5]; /* ": x40 $" */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int is_foreign_ident(const char *str)
|
static int is_foreign_ident(const char *str)
|
||||||
@ -1635,12 +1635,12 @@ static struct stream_filter_vtbl ident_vtbl = {
|
|||||||
ident_free_fn,
|
ident_free_fn,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct stream_filter *ident_filter(const unsigned char *sha1)
|
static struct stream_filter *ident_filter(const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct ident_filter *ident = xmalloc(sizeof(*ident));
|
struct ident_filter *ident = xmalloc(sizeof(*ident));
|
||||||
|
|
||||||
xsnprintf(ident->ident, sizeof(ident->ident),
|
xsnprintf(ident->ident, sizeof(ident->ident),
|
||||||
": %s $", sha1_to_hex(sha1));
|
": %s $", oid_to_hex(oid));
|
||||||
strbuf_init(&ident->left, 0);
|
strbuf_init(&ident->left, 0);
|
||||||
ident->filter.vtbl = &ident_vtbl;
|
ident->filter.vtbl = &ident_vtbl;
|
||||||
ident->state = 0;
|
ident->state = 0;
|
||||||
@ -1655,7 +1655,7 @@ static struct stream_filter *ident_filter(const unsigned char *sha1)
|
|||||||
* Note that you would be crazy to set CRLF, smuge/clean or ident to a
|
* Note that you would be crazy to set CRLF, smuge/clean or ident to a
|
||||||
* large binary blob you would want us not to slurp into the memory!
|
* large binary blob you would want us not to slurp into the memory!
|
||||||
*/
|
*/
|
||||||
struct stream_filter *get_stream_filter(const char *path, const unsigned char *sha1)
|
struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct conv_attrs ca;
|
struct conv_attrs ca;
|
||||||
struct stream_filter *filter = NULL;
|
struct stream_filter *filter = NULL;
|
||||||
@ -1668,7 +1668,7 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ca.ident)
|
if (ca.ident)
|
||||||
filter = ident_filter(sha1);
|
filter = ident_filter(oid);
|
||||||
|
|
||||||
if (output_eol(ca.crlf_action) == EOL_CRLF)
|
if (output_eol(ca.crlf_action) == EOL_CRLF)
|
||||||
filter = cascade_filter(filter, lf_to_crlf_filter());
|
filter = cascade_filter(filter, lf_to_crlf_filter());
|
||||||
|
@ -93,7 +93,7 @@ extern int would_convert_to_git_filter_fd(const char *path);
|
|||||||
|
|
||||||
struct stream_filter; /* opaque */
|
struct stream_filter; /* opaque */
|
||||||
|
|
||||||
extern struct stream_filter *get_stream_filter(const char *path, const unsigned char *);
|
extern struct stream_filter *get_stream_filter(const char *path, const struct object_id *);
|
||||||
extern void free_stream_filter(struct stream_filter *);
|
extern void free_stream_filter(struct stream_filter *);
|
||||||
extern int is_null_stream_filter(struct stream_filter *);
|
extern int is_null_stream_filter(struct stream_filter *);
|
||||||
|
|
||||||
|
2
entry.c
2
entry.c
@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
|
|||||||
|
|
||||||
if (ce_mode_s_ifmt == S_IFREG) {
|
if (ce_mode_s_ifmt == S_IFREG) {
|
||||||
struct stream_filter *filter = get_stream_filter(ce->name,
|
struct stream_filter *filter = get_stream_filter(ce->name,
|
||||||
ce->oid.hash);
|
&ce->oid);
|
||||||
if (filter &&
|
if (filter &&
|
||||||
!streaming_write_entry(ce, path, filter,
|
!streaming_write_entry(ce, path, filter,
|
||||||
state, to_tempfile,
|
state, to_tempfile,
|
||||||
|
Loading…
Reference in New Issue
Block a user