@matheusbsbs / matheus-bagliano / commits / e7332f96b3
Fork 0

remove the artificial restriction tagsize < 8kb

Signed-off-by: Björn Engelmann <BjEngelmann@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Björn Engelmann committed May 23, 2006 at 20:19 UTC e7332f96b32bedbc39ff6ff7e845c902056099f5
3 files changed +46 -20
cache.h
+1
@@ -154,6 +154,7 @@ extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int);
154 extern int ce_modified(struct cache_entry *ce, struct stat *st, int);
155 extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
156 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type);
157 +extern int read_pipe(int fd, char** return_buf, unsigned long* return_size);
158 extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object);
159 extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
160 extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
mktag.c
+9 -10
@@ -45,7 +45,7 @@ static int verify_tag(char *buffer, unsigned long size)
45 unsigned char sha1[20];
46 const char *object, *type_line, *tag_line, *tagger_line;
47
48 - if (size < 64 || size > MAXSIZE-1)
48 + if (size < 64)
49 return -1;
50 buffer[size] = 0;
51
@@ -105,8 +105,8 @@ static int verify_tag(char *buffer, unsigned long size)
105
106 int main(int argc, char **argv)
107 {
108 - unsigned long size;
109 - char buffer[MAXSIZE];
108 + unsigned long size = 4096;
109 + char *buffer = malloc(size);
110 unsigned char result_sha1[20];
111
112 if (argc != 1)
@@ -114,13 +114,9 @@ int main(int argc, char **argv)
114
115 setup_git_directory();
116
117 - // Read the signature
118 - size = 0;
119 - for (;;) {
120 - int ret = xread(0, buffer + size, MAXSIZE - size);
121 - if (ret <= 0)
122 - break;
123 - size += ret;
117 + if (read_pipe(0, &buffer, &size)) {
118 + free(buffer);
119 + die("could not read from stdin");
120 }
121
122 // Verify it for some basic sanity: it needs to start with "object <sha1>\ntype\ntagger "
@@ -129,6 +125,9 @@ int main(int argc, char **argv)
125
126 if (write_sha1_file(buffer, size, tag_type, result_sha1) < 0)
127 die("unable to write tag file");
128 +
129 + free(buffer);
130 +
131 printf("%s\n", sha1_to_hex(result_sha1));
132 return 0;
133 }
sha1_file.c
+36 -10
@@ -1645,16 +1645,24 @@ int has_sha1_file(const unsigned char *sha1)
1645 return find_sha1_file(sha1, &st) ? 1 : 0;
1646 }
1647
1648 -int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
1648 +/*
1649 + * reads from fd as long as possible into a supplied buffer of size bytes.
1650 + * If neccessary the buffer's size is increased using realloc()
1651 + *
1652 + * returns 0 if anything went fine and -1 otherwise
1653 + *
1654 + * NOTE: both buf and size may change, but even when -1 is returned
1655 + * you still have to free() it yourself.
1656 + */
1657 +int read_pipe(int fd, char** return_buf, unsigned long* return_size)
1658 {
1650 - unsigned long size = 4096;
1651 - char *buf = malloc(size);
1652 - int iret, ret;
1659 + char* buf = *return_buf;
1660 + unsigned long size = *return_size;
1661 + int iret;
1662 unsigned long off = 0;
1654 - unsigned char hdr[50];
1655 - int hdrlen;
1663 +
1664 do {
1657 - iret = read(fd, buf + off, size - off);
1665 + iret = xread(fd, buf + off, size - off);
1666 if (iret > 0) {
1667 off += iret;
1668 if (off == size) {
@@ -1663,16 +1671,34 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
1671 }
1672 }
1673 } while (iret > 0);
1666 - if (iret < 0) {
1674 +
1675 + *return_buf = buf;
1676 + *return_size = off;
1677 +
1678 + if (iret < 0)
1679 + return -1;
1680 + return 0;
1681 +}
1682 +
1683 +int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
1684 +{
1685 + unsigned long size = 4096;
1686 + char *buf = malloc(size);
1687 + int ret;
1688 + unsigned char hdr[50];
1689 + int hdrlen;
1690 +
1691 + if (read_pipe(fd, &buf, &size)) {
1692 free(buf);
1693 return -1;
1694 }
1695 +
1696 if (!type)
1697 type = blob_type;
1698 if (write_object)
1673 - ret = write_sha1_file(buf, off, type, sha1);
1699 + ret = write_sha1_file(buf, size, type, sha1);
1700 else {
1675 - write_sha1_file_prepare(buf, off, type, sha1, hdr, &hdrlen);
1701 + write_sha1_file_prepare(buf, size, type, sha1, hdr, &hdrlen);
1702 ret = 0;
1703 }
1704 free(buf);