hghooks: make changelog_correctness work with 4.1 (
bug 1333616); r?glob
The API for manifest access completely changed in Mercurial 4.1. Make
the hook compatible with old and new APIs.
I /think/ the new API has methods that can perform a lot of what this
hook is doing manually. We should look into porting the hook to
use the built-in API. An inline TODO has been added so this fact
doesn't get lost.
MozReview-Commit-ID: B0HXuHCxnpg
--- a/hghooks/mozhghooks/changelog_correctness.py
+++ b/hghooks/mozhghooks/changelog_correctness.py
@@ -30,18 +30,26 @@ def get_changed_files(repo, cs1, cs2):
# This is the simplest way to implement this with mercurial APIs,
# but it's really too slow:
# modified, added, removed = repo.status(cs2.node(), cs1.node())[:3]
# changed_files = set(modified) | set(added) | set(removed)
# Presumably, using repo.manifest.revdiff would be much faster, but
# it raises exceptions when used on changesets part of the push.
# So a manual diff of the manifests, as below, is faster.
- manifest1 = repo.manifest.revision(cs1.manifestnode())
- manifest2 = repo.manifest.revision(cs2.manifestnode())
+ # 4.1 overhauled the manifest API.
+ # TODO much of the code below can likely be written in terms of
+ # the new API. So look into that.
+ if hasattr(repo, 'manifestlog'):
+ manifest1 = repo.manifestlog[cs1.manifestnode()].read().text()
+ manifest2 = repo.manifestlog[cs2.manifestnode()].read().text()
+ else:
+ manifest1 = repo.manifest.revision(cs1.manifestnode())
+ manifest2 = repo.manifest.revision(cs2.manifestnode())
+
lines1 = iter(StringIO(manifest1))
lines2 = iter(StringIO(manifest2))
def get_next(lines):
try:
return lines.next()
except StopIteration:
return None