{"thread":{"id":"15555","subject":"[JGIT PATCH 2/2] More aggressively clear flags during RevWalk.reset","startedAt":"2008-09-16T19:34:36Z","lastAt":"2008-09-16T19:34:37Z","messageCount":2,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"90862","messageId":"1221593677-24481-1-git-send-email-spearce@spearce.org","threadId":"15555","inReplyTo":null,"subject":"[JGIT PATCH 1/2] Paper bag fix RevWalk.reset after inMergeBase is used","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-16T19:34:36Z","receivedAt":"2008-09-16T19:34:36Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We need to remove delayedFreeFlags from carryFlags anytime we\nmark those delayedFreeFlags as actually freeFlags.  In other\nwords we do not want to continue carrying a flag which we have\nnow freed and will recycle for a different use in the future,\none which may not want to be carried automatically onto parent\ncommits during revision traversal.\n\nI had the boolean expression incorrect (call it a typo).  The\ncorrect way to remove set b from a is \"a &= ~b\" not \"a &= b\".\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/revwalk/RevWalk.java      |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java\nindex 079432c..5cd7f71 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java\n@@ -824,7 +824,7 @@ void freeFlag(final int mask) {\n \tprivate void finishDelayedFreeFlags() {\n \t\tif (delayFreeFlags != 0) {\n \t\t\tfreeFlags |= delayFreeFlags;\n-\t\t\tcarryFlags &= delayFreeFlags;\n+\t\t\tcarryFlags &= ~delayFreeFlags;\n \t\t\tdelayFreeFlags = 0;\n \t\t}\n \t}\n-- \n1.6.0.2.389.g421e0\n"},{"id":"90861","messageId":"1221593677-24481-2-git-send-email-spearce@spearce.org","threadId":"15555","inReplyTo":"1221593677-24481-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 2/2] More aggressively clear flags during RevWalk.reset","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-16T19:34:37Z","receivedAt":"2008-09-16T19:34:37Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We cannot rely upon SEEN to tell us if the commit has flags we\nmust clear, as some forms of RevWalk usage can get flags put in\nplaces that don't have a clear SEEN trail leading to them.  To\nensure we have correctly reset the graph we need to follow down\nany chain which has any flag we are not going to retain across\nthe reset, making the correct test ~retain (and not just SEEN).\n\nThis fixes an issue I identified in an application that makes\nheavy use of the same RevWalk instance, constantly resetting\nit and executing down different parts of the same DAG instance.\n\nSome executions still had UNINTERESTING colored on commits,\neven though they should have been cleared by the prior reset.\nThe clear failed as there was not a SEEN path leading into the\npreviously UNINTERESTING (but now interesting) commit.  This\nmissing SEEN path occurred because markUninteresting() runs\nRevComit.carryFlags(), pushing the UNINTERESTING flag as far\ndown the DAG as we have parsed.  Not all of those DAG nodes\nmay get visited in a traversal (so they lack SEEN), but they\nmust get reset in order to reuse the same DAG instance.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/revwalk/RevWalk.java      |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java\nindex 5cd7f71..d7e4c58 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevWalk.java\n@@ -887,10 +887,11 @@ public final void resetRetain(final RevFlag... retainFlags) {\n \tprotected void reset(int retainFlags) {\n \t\tfinishDelayedFreeFlags();\n \t\tretainFlags |= PARSED;\n+\t\tfinal int clearFlags = ~retainFlags;\n \n \t\tfinal FIFORevQueue q = new FIFORevQueue();\n \t\tfor (final RevCommit c : roots) {\n-\t\t\tif ((c.flags & SEEN) == 0)\n+\t\t\tif ((c.flags & clearFlags) == 0)\n \t\t\t\tcontinue;\n \t\t\tc.flags &= retainFlags;\n \t\t\tc.reset();\n@@ -901,10 +902,13 @@ protected void reset(int retainFlags) {\n \t\t\tfinal RevCommit c = q.next();\n \t\t\tif (c == null)\n \t\t\t\tbreak;\n+\t\t\tif (c.parents == null)\n+\t\t\t\tcontinue;\n \t\t\tfor (final RevCommit p : c.parents) {\n-\t\t\t\tif ((p.flags & SEEN) == 0)\n+\t\t\t\tif ((p.flags & clearFlags) == 0)\n \t\t\t\t\tcontinue;\n \t\t\t\tp.flags &= retainFlags;\n+\t\t\t\tp.reset();\n \t\t\t\tq.add(p);\n \t\t\t}\n \t\t}\n-- \n1.6.0.2.389.g421e0\n"}]}