{"thread":{"id":"7469","subject":"[PATCH 1/3] Add BASE index extension.","startedAt":"2007-03-29T08:23:10Z","lastAt":"2007-03-29T08:23:10Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"38293","messageId":"7vmz1w4fwx.fsf@assigned-by-dhcp.cox.net","threadId":"7469","inReplyTo":null,"subject":"[PATCH 1/3] Add BASE index extension.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-29T08:23:10Z","receivedAt":"2007-03-29T08:23:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"With this patch, there now is a place to store one object name\nin the index as an optional \"BASE\".  The intended use is to\nstore the commit object name that the index is based on, so that\nwe can detect cases where a third-party updates the branch head of\nthe currently checked out branch, e.g. with \"git push\".\n\nThere currently is nobody that sets the value nor uses it.  That\nis the topic of the subsequent ones in the series.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n cache.h      |    2 ++\n read-cache.c |   19 ++++++++++++++++++-\n 2 files changed, 20 insertions(+), 1 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 384b260..def5d4a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -128,6 +128,8 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in\n extern struct cache_entry **active_cache;\n extern unsigned int active_nr, active_alloc, active_cache_changed;\n extern struct cache_tree *active_cache_tree;\n+extern unsigned char active_cache_base[20];\n+extern int active_cache_base_valid;\n extern int cache_errno;\n \n enum object_type {\ndiff --git a/read-cache.c b/read-cache.c\nindex 6339a27..221fc61 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -17,12 +17,15 @@\n \n #define CACHE_EXT(s) ( (s[0]<<24)|(s[1]<<16)|(s[2]<<8)|(s[3]) )\n #define CACHE_EXT_TREE 0x54524545\t/* \"TREE\" */\n+#define CACHE_EXT_BASE 0x42415345\t/* \"BASE\" */\n \n struct cache_entry **active_cache;\n static time_t index_file_timestamp;\n unsigned int active_nr, active_alloc, active_cache_changed;\n \n struct cache_tree *active_cache_tree;\n+unsigned char active_cache_base[20];\n+int active_cache_base_valid;\n \n int cache_errno;\n \n@@ -760,6 +763,11 @@ static int read_index_extension(const char *ext, void *data, unsigned long sz)\n \tcase CACHE_EXT_TREE:\n \t\tactive_cache_tree = cache_tree_read(data, sz);\n \t\tbreak;\n+\tcase CACHE_EXT_BASE:\n+\t\tif (sz != 40 || get_sha1_hex(data, active_cache_base))\n+\t\t\treturn error(\"malformed base commit recorded in index\");\n+\t\tactive_cache_base_valid = 1;\n+\t\tbreak;\n \tdefault:\n \t\tif (*ext < 'A' || 'Z' < *ext)\n \t\t\treturn error(\"index uses %.4s extension, which we do not understand\",\n@@ -814,6 +822,7 @@ int read_cache_from(const char *path)\n \tactive_nr = ntohl(hdr->hdr_entries);\n \tactive_alloc = alloc_nr(active_nr);\n \tactive_cache = xcalloc(active_alloc, sizeof(struct cache_entry *));\n+\tactive_cache_base_valid = 0;\n \n \toffset = sizeof(*hdr);\n \tfor (i = 0; i < active_nr; i++) {\n@@ -851,7 +860,7 @@ int discard_cache(void)\n {\n \tint ret;\n \n-\tactive_nr = active_cache_changed = 0;\n+\tactive_cache_base_valid = active_nr = active_cache_changed = 0;\n \tindex_file_timestamp = 0;\n \tcache_tree_free(&active_cache_tree);\n \tif (cache_mmap == NULL)\n@@ -1019,5 +1028,13 @@ int write_cache(int newfd, struct cache_entry **cache, int entries)\n \t\t\treturn -1;\n \t\t}\n \t}\n+\tif (active_cache_base_valid) {\n+\t\tchar *hex = sha1_to_hex(active_cache_base);\n+\t\tunsigned int len = 40;\n+\t\tif (write_index_ext_header(&c, newfd, CACHE_EXT_BASE, len) ||\n+\t\t    ce_write(&c, newfd, hex, len))\n+\t\t\treturn -1;\n+\t}\n+\n \treturn ce_flush(&c, newfd);\n }\n-- \n1.5.1.rc3.1.ga429d\n"}]}