diff --git a/swh/loader/mercurial/loader.py b/swh/loader/mercurial/loader.py --- a/swh/loader/mercurial/loader.py +++ b/swh/loader/mercurial/loader.py @@ -126,6 +126,8 @@ if isinstance(visit_date, str): # visit_date can be string or datetime visit_date = parser.parse(visit_date) self.visit_date = visit_date + self.last_visit = self.storage.origin_visit_get_latest( + self.origin['url'], require_snapshot=True) def prepare(self, *, origin_url, visit_date, directory=None): """Prepare the necessary steps to load an actual remote or local @@ -508,6 +510,16 @@ 'releases': self.num_releases, } + def load_status(self): + snapshot = self.get_snapshot() + load_status = 'eventful' + if (self.last_visit is not None and + self.last_visit['snapshot'] == snapshot['id']): + load_status = 'uneventful' + return { + 'status': load_status, + } + class HgArchiveBundle20Loader(HgBundle20Loader): """Mercurial loader for repository wrapped within archives. diff --git a/swh/loader/mercurial/tests/test_loader.py b/swh/loader/mercurial/tests/test_loader.py --- a/swh/loader/mercurial/tests/test_loader.py +++ b/swh/loader/mercurial/tests/test_loader.py @@ -144,6 +144,26 @@ self.assertEqual(self.loader.load_status(), {'status': 'eventful'}) self.assertEqual(self.loader.visit_status(), 'full') + def test_load_status(self): + # first visit of the mercurial repository + self.loader.load( + origin_url=self.repo_url, + visit_date='2016-05-03 15:16:32+00', + directory=self.destination_path) + + self.assertEqual(self.loader.load_status(), {'status': 'eventful'}) + self.assertEqual(self.loader.visit_status(), 'full') + + # second visit with no changes in the mercurial repository + # since the first one + self.loader.load( + origin_url=self.repo_url, + visit_date='2016-05-04 14:12:21+00', + directory=self.destination_path) + + self.assertEqual(self.loader.load_status(), {'status': 'uneventful'}) + self.assertEqual(self.loader.visit_status(), 'full') + class CommonHgLoaderData: def assert_data_ok(self):