summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-10-03 20:36:04 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-10-10 20:52:36 (GMT)
commit38dbe5f07837afceaec95fae5981d36eeb4917bd (patch)
treec8b54f0504b7c23df0927b393faf0fe5dc6256e1 /cache.h
parentafbba2f09ab06424d8b38908f4d76a1503f49a25 (diff)
downloadgit-38dbe5f07837afceaec95fae5981d36eeb4917bd.zip
git-38dbe5f07837afceaec95fae5981d36eeb4917bd.tar.gz
git-38dbe5f07837afceaec95fae5981d36eeb4917bd.tar.bz2
alternates: store scratch buffer as strbuf
We pre-size the scratch buffer to hold a loose object filename of the form "xx/yyyy...", which leads to allocation code that is hard to verify. We have to use some magic numbers during the initial allocation, and then writers must blindly assume that the buffer is big enough. Using a strbuf makes it more clear that we cannot overflow. Unfortunately, we do still need some magic numbers to grow our strbuf before calling fill_sha1_path(), but the strbuf growth is much closer to the point of use. This makes it easier to see that it's correct, and opens the possibility of pushing it even further down if fill_sha1_path() learns to work on strbufs. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/cache.h b/cache.h
index 555ba71..5d36ffa 100644
--- a/cache.h
+++ b/cache.h
@@ -1384,8 +1384,9 @@ extern void remove_scheduled_dirs(void);
extern struct alternate_object_database {
struct alternate_object_database *next;
- char *name;
- char *scratch;
+ /* see alt_scratch_buf() */
+ struct strbuf scratch;
+ size_t base_len;
char path[FLEX_ARRAY];
} *alt_odb_list;
@@ -1414,6 +1415,14 @@ extern void add_to_alternates_file(const char *dir);
*/
extern void add_to_alternates_memory(const char *dir);
+/*
+ * Returns a scratch strbuf pre-filled with the alternate object directory,
+ * including a trailing slash, which can be used to access paths in the
+ * alternate. Always use this over direct access to alt->scratch, as it
+ * cleans up any previous use of the scratch buffer.
+ */
+extern struct strbuf *alt_scratch_buf(struct alternate_object_database *alt);
+
struct pack_window {
struct pack_window *next;
unsigned char *base;