{"thread":{"id":"7094","subject":"[PATCH 1/2] fast-import: Avoid infinite loop after reset","startedAt":"2007-03-05T17:46:03Z","lastAt":"2007-03-05T17:46:03Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"36345","messageId":"20070305174603.GA22304@spearce.org","threadId":"7094","inReplyTo":null,"subject":"[PATCH 1/2] fast-import: Avoid infinite loop after reset","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-05T17:46:03Z","receivedAt":"2007-03-05T17:46:03Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johannes Sixt noticed that a 'reset' command applied to a branch that\nis already active in the branch LRU cache can cause fast-import to\nrelink the same branch into the LRU cache twice.  This will cause\nthe LRU cache to contain a cycle, making unload_one_branch run in an\ninfinite loop as it tries to select the oldest branch for eviction.\n\nI have trivially fixed the problem by adding an active bit to\neach branch object; this bit indicates if the branch is already\nin the LRU and allows us to avoid trying to add it a second time.\nConverting the pack_id field into a bitfield makes this change take\nup no additional memory.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n This two patch series was made on top of maint and is also pullable\n from my fast-import fork on repo.or.cz.  Merging it with master/next\n may require a minor evil merge as Nico's API changes there might\n be conflicting.\n\n fast-import.c |   16 +++++++++++-----\n 1 files changed, 11 insertions(+), 5 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 1ae125a..490f640 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -220,7 +220,8 @@ struct branch\n \tconst char *name;\n \tstruct tree_entry branch_tree;\n \tuintmax_t last_commit;\n-\tunsigned int pack_id;\n+\tunsigned active : 1;\n+\tunsigned pack_id : PACK_ID_BITS;\n \tunsigned char sha1[20];\n };\n \n@@ -528,6 +529,7 @@ static struct branch *new_branch(const char *name)\n \tb->table_next_branch = branch_table[hc];\n \tb->branch_tree.versions[0].mode = S_IFDIR;\n \tb->branch_tree.versions[1].mode = S_IFDIR;\n+\tb->active = 0;\n \tb->pack_id = MAX_PACK_ID;\n \tbranch_table[hc] = b;\n \tbranch_count++;\n@@ -1547,6 +1549,7 @@ static void unload_one_branch(void)\n \t\t\te = active_branches;\n \t\t\tactive_branches = e->active_next_branch;\n \t\t}\n+\t\te->active = 0;\n \t\te->active_next_branch = NULL;\n \t\tif (e->branch_tree.tree) {\n \t\t\trelease_tree_content_recursive(e->branch_tree.tree);\n@@ -1559,10 +1562,13 @@ static void unload_one_branch(void)\n static void load_branch(struct branch *b)\n {\n \tload_tree(&b->branch_tree);\n-\tb->active_next_branch = active_branches;\n-\tactive_branches = b;\n-\tcur_active_branches++;\n-\tbranch_load_count++;\n+\tif (!b->active) {\n+\t\tb->active = 1;\n+\t\tb->active_next_branch = active_branches;\n+\t\tactive_branches = b;\n+\t\tcur_active_branches++;\n+\t\tbranch_load_count++;\n+\t}\n }\n \n static void file_change_m(struct branch *b)\n-- \n1.5.0.3.862.g71037\n"}]}