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
--- 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')