Merge ~cjwatson/turnip:log-missing-stop into turnip:master

Proposed by Colin Watson
Status: Needs review
Proposed branch: ~cjwatson/turnip:log-missing-stop
Merge into: turnip:master
Prerequisite: ~cjwatson/turnip:log-by-date
Diff against target: 36 lines (+13/-1)
2 files modified
turnip/api/store.py (+4/-1)
turnip/api/tests/test_api.py (+9/-0)
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+295545@code.launchpad.net

Commit message

Make log API ignore a missing stop commit

Determining whether the stop commit exists in advance requires an extra
round-trip, and clients are likely to just fall back to omitting the
stop commit anyway. start_time and end_time provide an alternative way
to bound the set of commits which can be used in addition to a
possibly-missing stop commit.

Description of the change

Make log API ignore a missing stop commit.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

This makes it very easily to accidentally request a couple of hundred thousand commits, but I understand the motivation.

review: Approve (code)

Unmerged commits

56c15c5... by Colin Watson on 2016-05-24

Make log API ignore a missing stop commit

Determining whether the stop commit exists in advance requires an extra
round-trip, and clients are likely to just fall back to omitting the
stop commit anyway. start_time and end_time provide an alternative way
to bound the set of commits which can be used in addition to a
possibly-missing stop commit.

ee4cd2f... by Colin Watson on 2016-05-24

Add start_time and end_time parameters to log API

This is useful for bounding the set of commits returned in cases where
we may not have a reliable stop commit.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/api/store.py b/turnip/api/store.py
2index 0b08fa9..9759fd8 100644
3--- a/turnip/api/store.py
4+++ b/turnip/api/store.py
5@@ -414,7 +414,10 @@ def get_log(repo_store, repo_name, start=None, limit=None, stop=None,
6 start = repo.head.target # walk from HEAD
7 walker = repo.walk(start)
8 if stop:
9- walker.hide(stop) # filter stop sha1 and its ancestors
10+ try:
11+ walker.hide(stop) # filter stop sha1 and its ancestors
12+ except KeyError:
13+ pass
14 if limit > 0:
15 walker = itertools.islice(walker, limit)
16 for commit in walker:
17diff --git a/turnip/api/tests/test_api.py b/turnip/api/tests/test_api.py
18index 065b067..7b2511b 100644
19--- a/turnip/api/tests/test_api.py
20+++ b/turnip/api/tests/test_api.py
21@@ -558,6 +558,15 @@ class ApiTestCase(TestCase):
22 self.assertEqual(5, len(resp.json))
23 self.assertNotIn(excluded_commit, resp.json)
24
25+ def test_repo_get_log_with_missing_stop(self):
26+ """A missing stop commit is ignored rather than crashing."""
27+ factory = RepoFactory(self.repo_store, num_commits=10)
28+ repo = factory.build()
29+ head = repo.head.target
30+ resp = self.app.get('/repo/{}/log/{}?stop={}'.format(
31+ self.repo_path, head, factory.nonexistent_oid()))
32+ self.assertEqual(10, len(resp.json))
33+
34 def test_repo_repack_verify_pack(self):
35 """Ensure commit exists in pack."""
36 factory = RepoFactory(self.repo_store)

Subscribers

People subscribed via source and target branches