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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 15, 2017 at 22:07 UTC
bcd29864737099ff78de3db8b1d518f2aea51bc9
1 file changed
+15
-15
sha1_file.c
+15
-15
@@ -1664,7 +1664,7 @@ static void check_tag(const void *buf, size_t size)
1664
die("corrupt tag");
1665
}
1666
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,
1668
enum object_type type,
1669
const char *path, unsigned flags)
1670
{
@@ -1695,15 +1695,15 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
1695
}
1696
1697
if (write_object)
1698
- ret = write_sha1_file(buf, size, typename(type), sha1);
1698
+ ret = write_sha1_file(buf, size, typename(type), oid->hash);
1699
else
1700
- ret = hash_sha1_file(buf, size, typename(type), sha1);
1700
+ ret = hash_sha1_file(buf, size, typename(type), oid->hash);
1701
if (re_allocated)
1702
free(buf);
1703
return ret;
1704
}
1705
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,
1707
const char *path, unsigned flags)
1708
{
1709
int ret;
@@ -1718,22 +1718,22 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,
1718
1719
if (write_object)
1720
ret = write_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1721
- sha1);
1721
+ oid->hash);
1722
else
1723
ret = hash_sha1_file(sbuf.buf, sbuf.len, typename(OBJ_BLOB),
1724
- sha1);
1724
+ oid->hash);
1725
strbuf_release(&sbuf);
1726
return ret;
1727
}
1728
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,
1730
const char *path, unsigned flags)
1731
{
1732
struct strbuf sbuf = STRBUF_INIT;
1733
int ret;
1734
1735
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);
1737
else
1738
ret = -1;
1739
strbuf_release(&sbuf);
@@ -1742,14 +1742,14 @@ static int index_pipe(unsigned char *sha1, int fd, enum object_type type,
1742
1743
#define SMALL_FILE_SIZE (32*1024)
1744
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,
1746
enum object_type type, const char *path,
1747
unsigned flags)
1748
{
1749
int ret;
1750
1751
if (!size) {
1752
- ret = index_mem(sha1, "", size, type, path, flags);
1752
+ ret = index_mem(oid, "", size, type, path, flags);
1753
} else if (size <= SMALL_FILE_SIZE) {
1754
char *buf = xmalloc(size);
1755
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,
1760
ret = error("short read while indexing %s",
1761
path ? path : "<unknown>");
1762
else
1763
- ret = index_mem(sha1, buf, size, type, path, flags);
1763
+ ret = index_mem(oid, buf, size, type, path, flags);
1764
free(buf);
1765
} else {
1766
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);
1768
munmap(buf, size);
1769
}
1770
return ret;
@@ -1802,12 +1802,12 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
1802
* die() for large files.
1803
*/
1804
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);
1806
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);
1808
else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
1809
(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,
1811
flags);
1812
else
1813
ret = index_stream(oid, fd, xsize_t(st->st_size), type, path,