{"thread":{"id":"23347","subject":"[PATCH 7/7 (v5)] graft awareness","startedAt":"2010-04-05T19:58:51Z","lastAt":"2010-04-05T19:58:51Z","messageCount":1,"participants":["Nick Edelen"],"isPatch":true,"patchVersion":5,"patchTotal":7},"messages":[{"id":"138674","messageId":"4BBA40FB.6040204@gmail.com","threadId":"23347","inReplyTo":null,"subject":"[PATCH 7/7 (v5)] graft awareness","fromName":"Nick Edelen","fromEmail":"sirnot@gmail.com","sentAt":"2010-04-05T19:58:51Z","receivedAt":"2010-04-05T19:58:51Z","isPatch":true,"sender":{"key":"sirnot@gmail.com","avatar":null},"body":"Adds support for graft commits in rev-cache (w/ test), and slightly alters\ngraft mechanism.  Before, parse_commit() checked the graft list on every\ncommit.  Now register_commit_graft() preemptively loads graft commits into\nmemory, and sets a new 'graft' flag in the object.  This allows awareness of\nthe commits' medical history without searching a (normally private) array upon\neach commit.\n\nSigned-off-by: Nick Edelen <sirnot@gmail.com>\n\n---\n builtin/rev-cache.c       |   14 ++++++++++++--\n commit.c                  |   34 +++++++++++++++++++++++++++++++---\n object.h                  |    3 ++-\n rev-cache.c               |   32 ++++++++++++++++++++++++++++++++\n t/t6019-rev-cache-list.sh |    7 +++++++\n 5 files changed, 84 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/rev-cache.c b/builtin/rev-cache.c\nindex 59fc833..404e48c 100644\n--- a/builtin/rev-cache.c\n+++ b/builtin/rev-cache.c\n@@ -102,8 +102,18 @@ static int test_rev_list(int argc, const char *argv[])\n \t\t\tflags ^= UNINTERESTING;\n \t\telse if (!strcmp(argv[i], \"--objects\"))\n \t\t\trevs.tree_objects = revs.blob_objects = 1;\n-\t\telse\n-\t\t\thandle_revision_arg(argv[i], &revs, flags, 1);\n+\t\telse {\n+\t\t\tstruct commit_graft graft;\n+\n+\t\t\tif (argv[i][0] == ':') {\n+\t\t\t\thandle_revision_arg(argv[i] + 1, &revs, flags, 1);\n+\n+\t\t\t\thashcpy(graft.sha1, revs.pending.objects[revs.pending.nr - 1].item->sha1);\n+\t\t\t\tgraft.nr_parent = -1;\n+\t\t\t\tregister_commit_graft(&graft, 0);\n+\t\t\t} else\n+\t\t\t\thandle_revision_arg(argv[i], &revs, flags, 1);\n+\t\t}\n \t}\n \n \tsetup_revisions(0, 0, &revs, 0);\ndiff --git a/commit.c b/commit.c\nindex 263dd74..23f3bb9 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -100,6 +100,7 @@ static int commit_graft_pos(const unsigned char *sha1)\n \n int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n {\n+\tstruct commit *commit;\n \tint pos = commit_graft_pos(graft->sha1);\n \n \tif (0 <= pos) {\n@@ -124,6 +125,17 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)\n \t\t\t(commit_graft_nr - pos - 1) *\n \t\t\tsizeof(*commit_graft));\n \tcommit_graft[pos] = graft;\n+\n+\tcommit = lookup_commit(graft->sha1);\n+\tcommit->object.graft = 1;\n+\tif (commit->object.parsed) {\n+\t\t/* we don't want to call this from a parse_commit(), but\n+\t\t * we should ensure commit's parents are \"correct\"\n+\t\t */\n+\t\tcommit->object.parsed = 0;\n+\t\tparse_commit(commit);\n+\t}\n+\n \treturn 0;\n }\n \n@@ -220,6 +232,7 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol)\n \n int unregister_shallow(const unsigned char *sha1)\n {\n+\tstruct commit *commit;\n \tint pos = commit_graft_pos(sha1);\n \tif (pos < 0)\n \t\treturn -1;\n@@ -228,6 +241,12 @@ int unregister_shallow(const unsigned char *sha1)\n \t\t\t\tsizeof(struct commit_graft *)\n \t\t\t\t* (commit_graft_nr - pos - 1));\n \tcommit_graft_nr--;\n+\n+\tcommit = lookup_commit(sha1);\n+\tcommit->object.graft = 0;\n+\tcommit->object.parsed = 0;\n+\tparse_commit(commit);\n+\n \treturn 0;\n }\n \n@@ -241,7 +260,6 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)\n \n \tif (item->object.parsed)\n \t\treturn 0;\n-\titem->object.parsed = 1;\n \ttail += size;\n \tif (tail <= bufptr + 46 || memcmp(bufptr, \"tree \", 5) || bufptr[45] != '\\n')\n \t\treturn error(\"bogus commit object %s\", sha1_to_hex(item->object.sha1));\n@@ -254,7 +272,13 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)\n \twhile (pop_commit(pptr))\n \t\t; /* clear anything from cache */\n \n-\tgraft = lookup_commit_graft(item->object.sha1);\n+\t/* make sure .graft flag is initialized */\n+\tprepare_commit_graft();\n+\tif (item->object.graft)\n+\t\tgraft = lookup_commit_graft(item->object.sha1);\n+\telse\n+\t\tgraft = 0;\n+\n \twhile (bufptr + 48 < tail && !memcmp(bufptr, \"parent \", 7)) {\n \t\tstruct commit *new_parent;\n \n@@ -282,8 +306,12 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)\n \t\t\t\tcontinue;\n \t\t\tpptr = &commit_list_insert(new_parent, pptr)->next;\n \t\t}\n-\t}\n+\t\titem->object.graft = 1;\n+\t} else\n+\t\titem->object.graft = 0;\n+\n \titem->date = parse_commit_date(bufptr, tail);\n+\titem->object.parsed = 1;\n \n \treturn 0;\n }\ndiff --git a/object.h b/object.h\nindex 82877c8..8123824 100644\n--- a/object.h\n+++ b/object.h\n@@ -22,7 +22,7 @@ struct object_array {\n };\n \n #define TYPE_BITS   3\n-#define FLAG_BITS  27\n+#define FLAG_BITS  26\n \n /*\n  * The object type is stored in 3 bits.\n@@ -30,6 +30,7 @@ struct object_array {\n struct object {\n \tunsigned parsed : 1;\n \tunsigned used : 1;\n+\tunsigned graft : 1;\n \tunsigned type : TYPE_BITS;\n \tunsigned flags : FLAG_BITS;\n \tunsigned char sha1[20];\ndiff --git a/rev-cache.c b/rev-cache.c\nindex 4f1ea34..dfb3212 100644\n--- a/rev-cache.c\n+++ b/rev-cache.c\n@@ -754,9 +754,41 @@ static int traverse_cache_slice_1(struct rc_slice_header *head, unsigned char *m\n \t\t\t}\n \t\t} else if (!ipath_nr && co->date <= date)\n \t\t\tslop--;\n+\t\telse if (!ipath_nr && !upath_nr)\n+\t\t\tbreak;\n \t\telse\n \t\t\tslop = SLOP;\n \n+\t\t/* before opening further topo-relations, check if the parenting has had medical attention */\n+\t\tif (obj->graft) {\n+\t\t\tstruct commit_list *list;\n+\n+\t\t\tparse_commit(co);\n+\t\t\tobj->flags &= ~FACE_VALUE;\n+\t\t\tlast_objects[path] = 0;\n+\n+\t\t\t/* we're only interested in its indirect influence */\n+\t\t\tfor (list = co->parents; list; list = list->next) {\n+\t\t\t\tstruct rc_index_entry *iep;\n+\t\t\t\tstruct object *po = &list->item->object;\n+\n+\t\t\t\tiep = search_index(po->sha1);\n+\t\t\t\tif (!iep || hashcmp(idx_caches + 20 * iep->cache_index, head->sha1)) {\n+\t\t\t\t\tif (!(obj->flags & UNINTERESTING) && !(po->flags & UNINTERESTING))\n+\t\t\t\t\t\tioutside = 1;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\t/* an abrupt end */\n+\t\t\tmyworkp = &commit_list_insert(co, myworkp)->next;\n+\t\t\tif (uninteresting)\n+\t\t\t\tupath_nr--;\n+\t\t\telse\n+\t\t\t\tipath_nr--;\n+\t\t\tpaths[path] = 0;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\t/* open parents */\n \t\tif (entry->merge_nr) {\n \t\t\tint j, off = index + OBJECT_ENTRY_SIZE;\ndiff --git a/t/t6019-rev-cache-list.sh b/t/t6019-rev-cache-list.sh\nindex b7eff3f..5664de7 100644\n--- a/t/t6019-rev-cache-list.sh\n+++ b/t/t6019-rev-cache-list.sh\n@@ -92,6 +92,7 @@ git rev-list --topo-order HEAD --not HEAD~2 >proper_commit_list_limited2\n git rev-list --topo-order HEAD >proper_commit_list\n git rev-list --objects HEAD >proper_object_list\n git rev-list HEAD --max-age=$min_date --min-age=$max_date >proper_list_date_limited\n+git rev-cache test HEAD :HEAD~2 >proper_shallow_list 2>/dev/null\n \n cache_sha1=`git rev-cache add HEAD 2>output.err`\n \n@@ -252,5 +253,11 @@ test_expect_success 'test --ignore-size function in fuse' '\n \ttest -e .git/rev-cache/$cache_sha1\n '\n \n+#test graft handling\n+test_expect_success 'check graft handling' '\n+\tgit rev-cache test HEAD :HEAD~2 >list\n+\ttest_cmp list proper_shallow_list\n+'\n+\n test_done\n \n-- \ntg: (68204ac..) t/rc/graft (depends on: t/rc/names)\n"}]}