← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/git-cross-repository-logs into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/git-cross-repository-logs into lp:launchpad.

Commit message:
Request cross-repository logs for Git-based merge proposals.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-cross-repository-logs/+merge/295549

Request cross-repository logs for Git-based merge proposals.  The target_git_commit_sha1 may not necessarily be present in the source repository.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-cross-repository-logs into lp:launchpad.
=== modified file 'lib/lp/code/interfaces/gitref.py'
--- lib/lp/code/interfaces/gitref.py	2016-05-13 10:58:59 +0000
+++ lib/lp/code/interfaces/gitref.py	2016-05-24 07:02:50 +0000
@@ -314,13 +314,15 @@
         "Whether there are recent changes in this repository that have not "
         "yet been scanned.")
 
-    def getCommits(start, limit=None, stop=None,
+    def getCommits(start, limit=None, stop=None, union_repository=None,
                    start_date=None, end_date=None, logger=None):
         """Get commit information from this reference.
 
         :param start: The commit to start listing from.
         :param limit: If not None, return no more than this many commits.
         :param stop: If not None, ignore this commit and its ancestors.
+        :param union_repository: If not None, resolve commit identifiers in
+            this repository as well (particularly useful with `stop`).
         :param start_date: If not None, ignore commits before this date.
         :param end_date: If not None, ignore commits after this date.
         :param logger: An optional logger.

=== modified file 'lib/lp/code/model/branchmergeproposal.py'
--- lib/lp/code/model/branchmergeproposal.py	2016-05-13 17:16:40 +0000
+++ lib/lp/code/model/branchmergeproposal.py	2016-05-24 07:02:50 +0000
@@ -813,7 +813,8 @@
         else:
             return self.source_git_ref.getCommits(
                 self.source_git_commit_sha1, limit=10,
-                stop=self.target_git_commit_sha1)
+                stop=self.target_git_commit_sha1,
+                union_repository=self.target_git_repository)
 
     def createComment(self, owner, subject, content=None, vote=None,
                       review_type=None, parent=None, _date_created=DEFAULT,

=== modified file 'lib/lp/code/model/gitref.py'
--- lib/lp/code/model/gitref.py	2016-05-24 06:35:12 +0000
+++ lib/lp/code/model/gitref.py	2016-05-24 07:02:50 +0000
@@ -250,7 +250,7 @@
         """See `IGitRef`."""
         return self.repository.pending_writes
 
-    def _getLog(self, start, limit=None, stop=None,
+    def _getLog(self, start, limit=None, stop=None, union_repository=None,
                 enable_hosting=None, enable_memcache=None, logger=None):
         if enable_hosting is None:
             enable_hosting = not getFeatureFlag(
@@ -259,6 +259,19 @@
             enable_memcache = not getFeatureFlag(
                 u"code.git.log.disable_memcache")
         path = self.repository.getInternalPath()
+<<<<<<< TREE
+=======
+        if (union_repository is not None and
+                union_repository != self.repository):
+            path = "%s:%s" % (union_repository.getInternalPath(), path)
+        memcache_key = "%s:git-log:%s:%s" % (config.instance_name, path, start)
+        if limit is not None:
+            memcache_key += ":limit=%s" % limit
+        if stop is not None:
+            memcache_key += ":stop=%s" % stop
+        if isinstance(memcache_key, unicode):
+            memcache_key = memcache_key.encode("UTF-8")
+>>>>>>> MERGE-SOURCE
         log = None
         if enable_memcache:
             memcache_client = getUtility(IMemcacheClient)
@@ -307,12 +320,14 @@
                     }]
         return log
 
-    def getCommits(self, start, limit=None, stop=None,
+    def getCommits(self, start, limit=None, stop=None, union_repository=None,
                    start_date=None, end_date=None, logger=None):
         # Circular import.
         from lp.code.model.gitrepository import parse_git_commits
 
-        log = self._getLog(start, limit=limit, stop=stop, logger=logger)
+        log = self._getLog(
+            start, limit=limit, stop=stop, union_repository=union_repository,
+            logger=logger)
         parsed_commits = parse_git_commits(log)
         commits = []
         for commit in log:

=== modified file 'lib/lp/code/model/tests/test_gitref.py'
--- lib/lp/code/model/tests/test_gitref.py	2016-05-24 06:28:38 +0000
+++ lib/lp/code/model/tests/test_gitref.py	2016-05-24 07:02:50 +0000
@@ -216,6 +216,24 @@
             json.dumps(self.log),
             getUtility(IMemcacheClient).get(key.encode("UTF-8")))
 
+    def test_union_repository(self):
+        other_repository = self.factory.makeGitRepository()
+        self.ref.getCommits(
+            self.sha1_tip, stop=self.sha1_root,
+            union_repository=other_repository)
+        path = "%s:%s" % (
+            other_repository.getInternalPath(),
+            self.ref.repository.getInternalPath())
+        self.assertEqual(
+            [((path, self.sha1_tip),
+              {"limit": None, "stop": self.sha1_root, "logger": None})],
+            self.hosting_client.getLog.calls)
+        key = u"%s:git-log:%s:%s:stop=%s" % (
+            config.instance_name, path, self.sha1_tip, self.sha1_root)
+        self.assertEqual(
+            json.dumps(self.log),
+            getUtility(IMemcacheClient).get(key.encode("UTF-8")))
+
     def test_start_date(self):
         commits = self.ref.getCommits(
             self.sha1_tip, start_date=(self.dates[1] - timedelta(seconds=1)))


Follow ups