Bug 1289514 - Detect empty repos from empty lastpushid; r=catlee
authorGregory Szorc <gps@mozilla.com>
Tue, 26 Jul 2016 11:54:20 -0700
changeset 4878 d76e0a6a3900f728240c404c2d1dc3beb2359241
parent 4877 93f15cf0f724e3df24c7e411b7ed0673e682d923
child 4879 ff1a7a80c2f14aee675a16f73374015446e4b6ee
child 4883 3041d0f3079fdacb88f1115e466b57adc012de54
push id3643
push userbmo:gps@mozilla.com
push dateTue, 26 Jul 2016 22:50:34 +0000
reviewerscatlee
bugs1289514
Bug 1289514 - Detect empty repos from empty lastpushid; r=catlee Before, we relied on the state of the poller to determine whether a repo was likely empty. Now that we've switched to pushlog version 2, the response tells us the last known push id. If it is an empty string, the pushlog is empty. So we change the empty detection code to look at this value. MozReview-Commit-ID: 9eVyNXaVgtE
changes/hgpoller.py
test/test_hgpoller.py
--- a/changes/hgpoller.py
+++ b/changes/hgpoller.py
@@ -281,24 +281,23 @@ class BaseHgPoller(BasePoller):
             # if self.verbose:
                 # log.msg("%s has been reset" % self.baseURL)
             # self.lastChangeset = None
             # self.emptyRepo = True
         return self.super_class.dataFailed(self, res)
 
     def processData(self, query):
         push_data = parse_pushlog_json(query)
-        if not push_data['pushes']:
-            if self.lastChangeset is None:
-                # We don't have a lastChangeset, and there are no changes.  Assume
-                # the repository is empty.
-                self.emptyRepo = True
-                if self.verbose:
-                    log.msg("%s is empty" % self.baseURL)
-            # Nothing else to do
+
+        # The payload tells us the most recent push ID. If it is the empty
+        # string, the pushlog is empty and there is no data to consume.
+        if not push_data['lastpushid']:
+            self.emptyRepo = True
+            if self.verbose:
+                log.msg('%s is empty' % self.baseURL)
             return
 
         # We want to add at most self.maxChanges changes per push. If
         # mergePushChanges is True, then we'll get up to maxChanges pushes,
         # each with up to maxChanges changes.
         # Go through the list of pushes backwards, since we want to keep the
         # latest ones and possibly discard earlier ones.
         change_list = []
--- a/test/test_hgpoller.py
+++ b/test/test_hgpoller.py
@@ -326,16 +326,27 @@ class PollingTest(unittest.TestCase):
                 changes.append(change)
 
         p = TestPoller()
         p.parent = parent()
         p.processData(data)
         return p
 
 
+class EmptyLastPushID(PollingTest):
+    def testEmptyLastPushID(self):
+        poller = self.doTest(data="""
+        {
+            "lastpushid": "",
+            "pushes": {}
+        }
+        """)
+        self.assertTrue(poller.emptyRepo, 'repo marked as empty')
+
+
 class RepoBranchHandling(PollingTest):
     def testNoRepoBranch(self):
         self.doTest(repo_branch=None)
 
         self.assertEquals(len(self.changes), 2)
 
     def testDefaultRepoBranch(self):
         self.doTest(repo_branch='default')