You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/12/20 19:50:43 UTC

[17/36] git commit: [#6821] Refactored common last commit logic up and removed merge commit skipping

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

Signed-off-by: Cory Johns <cj...@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/4070bed5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4070bed5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4070bed5

Branch: refs/heads/db/6388
Commit: 4070bed57cd5878f2d63e14009f958d724951956
Parents: 852f084
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Mon Dec 16 18:25:14 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Dec 18 22:10:33 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/4070bed5/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/4070bed5/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