git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGIT PATCH 4/4] Find uninteresting commits faster for special cases

From
Karl Hasselström <kha@treskal.com>
Date
Aug 13, 2007, 21:01 UTC
Message-ID
<20070813210142.25929.66904.stgit@yoghurt>
In-Reply-To
<20070813205801.25929.34925.stgit@yoghurt>

For the special cases of zero or one patch, the set of uninteresting commits is very cheap to find.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 stgit/stack.py |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/stgit/stack.py b/stgit/stack.py
index dbb27eb..b00a024 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -449,15 +449,27 @@ class UninterestingCache:
         self.__compute_uninteresting()
         self.__write_file()
     def __compute_uninteresting(self):
-        """Compute a reasonable set of uninteresting commits from
-        scratch. This is expensive."""
-        out.start('Finding uninteresting commits')
+        """Compute the set of uninteresting commits from scratch. This
+        is expensive in the general case; therefore, we print a
+        message to the user."""
         ref2hash = read_refs(self.__series.get_name())
         patches = Set([sha1 for ref, sha1 in ref2hash.iteritems() if ref])
-        interesting, uninteresting = Set(), Set()
+
+        # Optimize some important special cases.
+        if len(patches) == 0:
+            self.__uninteresting = Set()
+            return
+        elif len(patches) == 1:
+            patch = iter(patches).next()
+            commit, parent = git._output_one_line(
+                'git-rev-list --parents %s' % patch).split()
+            self.__uninteresting = Set([parent])
+            return
 
         # Iterate over all commits. We are guaranteed to see each
         # commit before any of its children.
+        out.start('Finding uninteresting commits')
+        interesting, uninteresting = Set(), Set()
         for line in git._output_lines(
             'git-rev-list --topo-order --reverse --parents --stdin',
             ['%s\n' % p for p in patches]):
@@ -483,7 +495,6 @@ class UninterestingCache:
             # Commits with interesting parents are interesting.
             elif interesting.intersection(parents):
                 interesting.add(commit)
-
         self.__uninteresting = uninteresting
         out.done()
     def create_patch(self, name, top, bottom, new_commit):
@@ -496,6 +507,13 @@ class UninterestingCache:
         if not self.__cache_file():
             return # not cached
 
+        # If there are no existing uninteresting commits, this is the
+        # first patch, so its bottom has to be uninteresting.
+        if not self.__uninteresting:
+            self.__uninteresting.add(bottom)
+            self.__write_file()
+            return
+
         # New patch inserted just below an existing bottommost patch:
         # need to move the uninteresting commit down one step.
         if top in self.__uninteresting:
Previous: Karl Hasselström
Message 5 of 5 in “Optimizations for the DAG appliedness stuff”
  1. 0/4 Optimizations for the DAG appliedness stuffKarl Hasselström, Aug 13, 2007
  2. 1/4 Speed up the discovery of uninteresting commitsKarl Hasselström, Aug 13, 2007
  3. 2/4 Speed up appliedness check during patch creationKarl Hasselström, Aug 13, 2007
  4. 3/4 Don't traverse the whole DAG when looking for uninteresting commitsKarl Hasselström, Aug 13, 2007
  5. 4/4 Find uninteresting commits faster for special casesKarl Hasselström, Aug 13, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.