sphinxcontrib-mercurial / sphinxcontrib / hg_changelog.py

Diff from to

sphinxcontrib/hg_changelog.py

         repo = hg.repository(ui.ui(), repo_root_path)
         l = nodes.bullet_list()
 
-        commits = range(repo.changectx("tip").rev()+1)
-        commits.reverse()
+        ctxes = self.get_ctxes(repo, self.options)
 
-        max_commits = 10
-        if 'max_commits' in self.options:
-            max_commits = self.options['max_commits']
-
-        branch = "default"
-        if 'branch' in self.options:
-            branch = self.options['branch']
-
-        path = None
-        if 'path' in self.options:
-            path = self.options['path']
-
-        for commit in commits[:max_commits]:
-            ctx = repo.changectx(commit)
-            if ctx.branch() != branch:
-                continue
-            if self.is_file_in_path(ctx.files(), path) is False:
-                continue
+        for ctx in ctxes:
             item = nodes.list_item()
             item += [ nodes.strong(text=ctx.description()),
                       nodes.inline(text=" by "),
             l.append(item)
         return [l]
 
+    def get_ctxes(self, repo, options):
+        '''get suitable ctxes from commits'''
+        max_commits = 10
+        if 'max_commits' in options:
+            max_commits = options['max_commits']
+        branch = "default"
+        if 'branch' in options:
+            branch = options['branch']
+        path = None
+        if 'path' in options:
+            path = options['path']
+            
+        commits = range(repo.changectx("tip").rev()+1)
+        commits.reverse()
+
+        ret = []
+        for commit in commits:
+            if len(ret) >= max_commits:
+                break
+            ctx = repo.changectx(commit)
+            if ctx.branch() != branch:
+                continue
+            if self.is_file_in_path(ctx.files(), path) is False:
+                continue
+            ret.append(ctx)
+            
+        return ret
+
     def is_file_in_path(self, files, path):
         '''Check files contain some file in specified path'''
         if path is None:
             return True
         for f in files:
+            print f
             if f.startswith(path):
                 return True
         return False
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.