Skip to content

Commit bcd2986

Browse files
bk2204gitster
authored andcommitted
sha1_file: convert index_path and index_fd to struct object_id
Convert these two functions and the functions that underlie them to take pointers to struct object_id. This is a prerequisite to convert resolve_gitlink_ref. Fix a stray tab in the middle of the index_mem call in index_pipe by converting it to a space. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0155f71 commit bcd2986

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

sha1_file.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ static void check_tag(const void *buf, size_t size)
16641664
die("corrupt tag");
16651665
}
16661666

1667-
static int index_mem(unsigned char *sha1, void *buf, size_t size,
1667+
static int index_mem(struct object_id *oid, void *buf, size_t size,
16681668
enum object_type type,
16691669
const char *path, unsigned flags)
16701670
{
@@ -1695,15 +1695,15 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
16951695
}
16961696

16971697
if (write_object)
1698-
ret = write_sha1_file(buf, size, typename(type), sha1);
1698+
ret = write_sha1_file(buf, size, typename(type), oid->hash);
16991699
else
1700-
ret = hash_sha1_file(buf, size, typename(type), sha1);
1700+
ret = hash_sha1_file(buf, size, typename(type), oid->hash);
17011701
if (re_allocated)
17021702
free(buf);
17031703
return ret;
17041704
}
17051705

1706-
static int index_stream_convert_blob(unsigned char *sha1, int fd,
1706+
static int index_stream_convert_blob(struct object_id *oid, int fd,
17071707
const char *path, unsigned flags)
17081708
{
17091709
int ret;
@@ -1718,22 +1718,22 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,
17181718

17191719
if (write_object)
17201720
ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1721-
sha1);
1721+
oid->hash);
17221722
else
17231723
ret = hash_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1724-
sha1);
1724+
oid->hash);
17251725
strbuf_release(&sbuf);
17261726
return ret;
17271727
}
17281728

1729-
static int index_pipe(unsigned char *sha1, int fd, enum object_type type,
1729+
static int index_pipe(struct object_id *oid, int fd, enum object_type type,
17301730
const char *path, unsigned flags)
17311731
{
17321732
struct strbuf sbuf = STRBUF_INIT;
17331733
int ret;
17341734

17351735
if (strbuf_read(&sbuf, fd, 4096) >= 0)
1736-
ret = index_mem(sha1, sbuf.buf, sbuf.len, type, path, flags);
1736+
ret = index_mem(oid, sbuf.buf, sbuf.len, type, path, flags);
17371737
else
17381738
ret = -1;
17391739
strbuf_release(&sbuf);
@@ -1742,14 +1742,14 @@ static int index_pipe(unsigned char *sha1, int fd, enum object_type type,
17421742

17431743
#define SMALL_FILE_SIZE (32*1024)
17441744

1745-
static int index_core(unsigned char *sha1, int fd, size_t size,
1745+
static int index_core(struct object_id *oid, int fd, size_t size,
17461746
enum object_type type, const char *path,
17471747
unsigned flags)
17481748
{
17491749
int ret;
17501750

17511751
if (!size) {
1752-
ret = index_mem(sha1, "", size, type, path, flags);
1752+
ret = index_mem(oid, "", size, type, path, flags);
17531753
} else if (size <= SMALL_FILE_SIZE) {
17541754
char *buf = xmalloc(size);
17551755
ssize_t read_result = read_in_full(fd, buf, size);
@@ -1760,11 +1760,11 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
17601760
ret = error("short read while indexing %s",
17611761
path ? path : "<unknown>");
17621762
else
1763-
ret = index_mem(sha1, buf, size, type, path, flags);
1763+
ret = index_mem(oid, buf, size, type, path, flags);
17641764
free(buf);
17651765
} else {
17661766
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
1767-
ret = index_mem(sha1, buf, size, type, path, flags);
1767+
ret = index_mem(oid, buf, size, type, path, flags);
17681768
munmap(buf, size);
17691769
}
17701770
return ret;
@@ -1802,12 +1802,12 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
18021802
* die() for large files.
18031803
*/
18041804
if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
1805-
ret = index_stream_convert_blob(oid->hash, fd, path, flags);
1805+
ret = index_stream_convert_blob(oid, fd, path, flags);
18061806
else if (!S_ISREG(st->st_mode))
1807-
ret = index_pipe(oid->hash, fd, type, path, flags);
1807+
ret = index_pipe(oid, fd, type, path, flags);
18081808
else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
18091809
(path && would_convert_to_git(&the_index, path)))
1810-
ret = index_core(oid->hash, fd, xsize_t(st->st_size), type, path,
1810+
ret = index_core(oid, fd, xsize_t(st->st_size), type, path,
18111811
flags);
18121812
else
18131813
ret = index_stream(oid, fd, xsize_t(st->st_size), type, path,

0 commit comments

Comments
 (0)