hghooks: make changelog_correctness work with 4.1 (bug 1333616); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Fri, 31 Mar 2017 15:44:41 -0700
changeset 10634 c065d52ae80aef5e7ba516bed200db8b944a8e36
parent 10633 c0863ef272fcd5491238fccd75be55616dccf71f
child 10635 629906224c04c4524c39376fd696630d13ce7383
push id1600
push userbmo:gps@mozilla.com
push dateMon, 03 Apr 2017 23:38:00 +0000
reviewersglob
bugs1333616
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
hghooks/mozhghooks/changelog_correctness.py
--- 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