incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [1/2] git commit: [#6821] Refactored common last commit logic up and removed merge commit skipping
Date Mon, 16 Dec 2013 19:21:52 GMT
Updated Branches:
  refs/heads/cj/6821 ad87c1599 -> 77d18b129


[#6821] Refactored common last commit logic up and removed merge commit skipping

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/33796354
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/33796354
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/33796354

Branch: refs/heads/cj/6821
Commit: 33796354c9dd9514dfe012db789946fee25701a4
Parents: ad87c15
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Dec 16 18:25:14 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Dec 16 18:26:07 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py   | 46 +++++++++++++++++++++++++
 ForgeGit/forgegit/model/git_repo.py | 59 ++++++--------------------------
 2 files changed, 56 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/33796354/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index fa36e73..169b365 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -32,6 +32,8 @@ from collections import defaultdict
 from itertools import izip
 from urlparse import urljoin
 from urllib import quote
+from threading import Thread
+from Queue import Queue
 
 import tg
 from paste.deploy.converters import asbool, asint
@@ -245,6 +247,50 @@ class RepositoryImplementation(object):
     def tags(self):
         raise NotImplementedError, 'tags'
 
+    def last_commit_ids(self, commit, paths):
+        """
+        Find the ID of the last commit to touch each path.
+        """
+        if not paths:
+            return {}
+        timeout = float(tg.config.get('lcd_timeout', 60))
+        start_time = time()
+        paths = list(set(paths))  # remove dupes
+        result = {}  # will be appended to from each thread
+        chunks = Queue()
+        lcd_chunk_size = asint(tg.config.get('lcd_thread_chunk_size', 10))
+        num_threads = 0
+        for s in range(0, len(paths), lcd_chunk_size):
+            chunks.put(paths[s:s+lcd_chunk_size])
+            num_threads += 1
+        def get_ids():
+            paths = set(chunks.get())
+            try:
+                commit_id = commit._id
+                while paths and commit_id:
+                    if time() - start_time > timeout:
+                        log.error('last_commit_ids timeout for %s on %s', commit._id, ',
'.join(paths))
+                        break
+                    commit_id, changes = self._get_last_commit(commit._id, paths)
+                    if commit_id is None:
+                        break
+                    changed = prefix_paths_union(paths, changes)
+                    for path in changed:
+                        result[path] = commit_id
+                    paths -= changed
+            except Exception as e:
+                log.exception('Error in SCM thread: %s', e)
+            finally:
+                chunks.task_done()
+        if num_threads == 1:
+            get_ids()
+        else:
+            for i in range(num_threads):
+                t = Thread(target=get_ids)
+                t.start()
+            chunks.join()
+        return result
+
 class Repository(Artifact, ActivityObject):
     BATCH_SIZE=100
     class __mongometa__:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/33796354/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index f08fdd4..229f2bb 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -27,8 +27,6 @@ from datetime import datetime
 from glob import glob
 import gzip
 from time import time
-from threading import Thread
-from Queue import Queue
 
 import tg
 import git
@@ -500,54 +498,17 @@ class GitImplementation(M.RepositoryImplementation):
         self._repo.default_branch_name = name
         session(self._repo).flush(self._repo)
 
-    def last_commit_ids(self, commit, paths):
-        """
-        Find the ID of the last commit to touch each path.
-        """
-        if not paths:
-            return {}
-        timeout = float(tg.config.get('lcd_timeout', 60))
-        start_time = time()
-        paths = list(set(paths))  # remove dupes
-        result = {}  # will be appended to from each thread
-        chunks = Queue()
-        lcd_chunk_size = asint(tg.config.get('lcd_thread_chunk_size', 10))
-        num_threads = 0
-        for s in range(0, len(paths), lcd_chunk_size):
-            chunks.put(paths[s:s+lcd_chunk_size])
-            num_threads += 1
-        def get_ids():
-            paths = set(chunks.get())
-            try:
-                commit_id = commit._id
-                while paths and commit_id:
-                    if time() - start_time > timeout:
-                        log.error('last_commit_ids timeout for %s on %s', commit._id, ',
'.join(paths))
-                        break
-                    lines = self._git.git.log(
-                            commit._id, '--', *paths,
-                            pretty='format:%H',
-                            name_only=True,
-                            max_count=1,
-                            no_merges=True).split('\n')
-                    commit_id = lines[0]
-                    changes = set(lines[1:])
-                    changed = prefix_paths_union(paths, changes)
-                    for path in changed:
-                        result[path] = commit_id
-                    paths -= changed
-            except Exception as e:
-                log.exception('Error in Git thread: %s', e)
-            finally:
-                chunks.task_done()
-        if num_threads == 1:
-            get_ids()
+    def _get_last_commit(self, commit_id, paths):
+        output = self._git.git.log(
+                commit_id, '--', *paths,
+                pretty='format:%H',
+                name_only=True,
+                max_count=1)
+        if not output:
+            return None, set()
         else:
-            for i in range(num_threads):
-                t = Thread(target=get_ids)
-                t.start()
-            chunks.join()
-        return result
+            lines = output.split('\n')
+            return lines[0], set(lines[1:])
 
 class _OpenedGitBlob(object):
     CHUNK_SIZE=4096


Mime
View raw message