pushlog: filter hidden changesets (bug 1286426); r=glandium
authorGregory Szorc <gps@mozilla.com>
Thu, 14 Jul 2016 10:47:20 -0700
changeset 8968 cc3360b720c65f901fa67070f57bdd6311415f0a
parent 8967 0bc74c039485df943b4650dc0bf2a858efcf5771
child 8969 6900f22f81a21153f82389478368b19a0d86de64
push id1034
push userbmo:gps@mozilla.com
push dateTue, 19 Jul 2016 18:10:24 +0000
reviewersglandium
bugs1286426
pushlog: filter hidden changesets (bug 1286426); r=glandium If a changeset in the pushlog results is filtered, we detect this and discard the changeset. Future commits will continue to refine this behavior. For now, we gain test coverage to make it easier to see how things change (or don't change) going forward. The docs for the ``changeset`` key have been tweaked. MozReview-Commit-ID: KtkEhIdFfQ3
docs/hgmo/pushlog.rst
hgext/pushlog-legacy/pushlog-feed.py
hgext/pushlog-legacy/tests/test-obsolescence.t
--- a/docs/hgmo/pushlog.rst
+++ b/docs/hgmo/pushlog.rst
@@ -235,19 +235,26 @@ Push Objects
 ^^^^^^^^^^^^
 
 The value of each entry in the pushes object is an object describing
 the push and the changesets therein.
 
 The following properties are always present:
 
 changesets
-   An array of 40 character changeset SHA-1s that were included in the
-   push. Changesets are included in DAG/revlog order. The tip-most
-   changeset is last.
+   An array of changeset entries.
+
+   By default, entries are 40 character changeset SHA-1s included in the
+   push. If ``full`` is specified, entries are objects containing
+   changeset metadata (see below).
+
+   Changesets are in DAG/revlog order with the tip-most changeset last.
+
+   The array may be empty. This can occur if changesets from this push
+   are now hidden/obsolete.
 
 date
    Integer seconds since UNIX epoch that the push occurred.
 
    For pushes that take a very long time (more than a single second),
    the data will be recorded towards the end of the push, just before
    the transaction is committed to Mercurial. Although, this is an
    implementation details.
--- a/hgext/pushlog-legacy/pushlog-feed.py
+++ b/hgext/pushlog-legacy/pushlog-feed.py
@@ -12,16 +12,17 @@ import mercurial.hgweb.webutil as webuti
 from mercurial.hgweb.common import (
     ErrorResponse,
     HTTP_OK,
     paritygen,
 )
 from mercurial.node import hex, nullid
 from mercurial import (
     demandimport,
+    error,
     templatefilters,
 )
 
 sys.path.append(os.path.dirname(__file__))
 
 with demandimport.deactivated():
     from parsedatetime import parsedatetime as pdt
 
@@ -339,17 +340,22 @@ def pushlogFeed(web, req, tmpl):
         'url': req.url,
         'repo': query.reponame,
         'date': dt,
         'entries': [],
     }
 
     entries = data['entries']
     for id, user, date, node in query.entries:
-        ctx = web.repo[node]
+        try:
+            ctx = web.repo[node]
+        # Changeset is hidden.
+        except error.FilteredRepoLookupError:
+            pass
+
         entries.append({
             'node': node,
             'date': isotime(date),
             'user': xmlescape(user),
             'urlbase': query.urlbase,
             'url': req.url,
             'files': [{'name': fn} for fn in ctx.files()],
         })
@@ -409,17 +415,22 @@ def pushlogHTML(web, req, tmpl):
         lastid = None
         l = []
         mergehidden = ""
         p = 0
         currentpush = None
         for id, user, date, node in query.entries:
             if isinstance(node, unicode):
                 node = node.encode('utf-8')
-            ctx = web.repo[node]
+
+            try:
+                ctx = web.repo[node]
+            # Changeset is hidden.
+            except error.FilteredRepoLookupError:
+                continue
             n = ctx.node()
             entry = {"author": ctx.user(),
                      "desc": ctx.description(),
                      "files": listfilediffs(tmpl, ctx.files(), n),
                      "rev": ctx.rev(),
                      "node": hex(n),
                      "parents": [c.hex() for c in ctx.parents()],
                      "tags": nodetagsdict(web.repo, n),
@@ -477,18 +488,23 @@ def pushes_worker(query, repo, full):
         # pushes if nodes from the pushlog no longer exist.
         if id not in pushes:
             pushes[id] = {
                 'user': user,
                 'date': date,
                 'changesets': [],
             }
 
+        try:
+            ctx = repo[node]
+        # Changeset is hidden
+        except error.FilteredRepoLookupError:
+            continue
+
         if full:
-            ctx = repo[node]
             node = {
                 'node': ctx.hex(),
                 'author': ctx.user(),
                 'desc': ctx.description(),
                 'branch': ctx.branch(),
                 'parents': [c.hex() for c in ctx.parents()],
                 'tags': ctx.tags(),
                 'files': ctx.files()
--- a/hgext/pushlog-legacy/tests/test-obsolescence.t
+++ b/hgext/pushlog-legacy/tests/test-obsolescence.t
@@ -73,20 +73,17 @@ FIXME Hidden changesets should not be ex
       "1": {
           "changesets": [
               "96ee1d7354c4ad7372047672c36a1f561e3a6a4c"
           ],
           "date": \d+, (re)
           "user": "user@example.com"
       },
       "2": {
-          "changesets": [
-              "ae13d9da6966307c98b60987fb4fedc2e2f29736",
-              "d313a202a85e114000f669c2fcb49ad42376ac04"
-          ],
+          "changesets": [],
           "date": \d+, (re)
           "user": "user@example.com"
       },
       "3": {
           "changesets": [
               "b3641753ee63b166fad7c5f10060b0cbbc8a86b0",
               "62eebb2f0f00195f9d965f718090c678c4fa414d"
           ],
@@ -99,38 +96,126 @@ FIXME Hidden changesets should not be ex
               "d129109168f0ed985e51b0f86df256acdcfcfe45"
           ],
           "date": \d+, (re)
           "user": "user@example.com"
       }
   }
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?version=1&full=1"
-  404
-  "hidden revision 'd313a202a85e114000f669c2fcb49ad42376ac04'"
+  200
+  {
+      "1": {
+          "changesets": [
+              {
+                  "author": "test",
+                  "branch": "default",
+                  "desc": "initial",
+                  "files": [
+                      "foo"
+                  ],
+                  "node": "96ee1d7354c4ad7372047672c36a1f561e3a6a4c",
+                  "parents": [
+                      "0000000000000000000000000000000000000000"
+                  ],
+                  "tags": []
+              }
+          ],
+          "date": \d+, (re)
+          "user": "user@example.com"
+      },
+      "2": {
+          "changesets": [],
+          "date": \d+, (re)
+          "user": "user@example.com"
+      },
+      "3": {
+          "changesets": [
+              {
+                  "author": "test",
+                  "branch": "default",
+                  "desc": "file2",
+                  "files": [
+                      "file2"
+                  ],
+                  "node": "b3641753ee63b166fad7c5f10060b0cbbc8a86b0",
+                  "parents": [
+                      "96ee1d7354c4ad7372047672c36a1f561e3a6a4c"
+                  ],
+                  "tags": []
+              },
+              {
+                  "author": "test",
+                  "branch": "default",
+                  "desc": "file3",
+                  "files": [
+                      "file3"
+                  ],
+                  "node": "62eebb2f0f00195f9d965f718090c678c4fa414d",
+                  "parents": [
+                      "b3641753ee63b166fad7c5f10060b0cbbc8a86b0"
+                  ],
+                  "tags": []
+              }
+          ],
+          "date": \d+, (re)
+          "user": "user@example.com"
+      },
+      "4": {
+          "changesets": [
+              {
+                  "author": "test",
+                  "branch": "default",
+                  "desc": "file0",
+                  "files": [
+                      "file0"
+                  ],
+                  "node": "418a63f508062fb2eb9130065c5ddc7908dd5949",
+                  "parents": [
+                      "62eebb2f0f00195f9d965f718090c678c4fa414d"
+                  ],
+                  "tags": []
+              },
+              {
+                  "author": "test",
+                  "branch": "default",
+                  "desc": "file1",
+                  "files": [
+                      "file1"
+                  ],
+                  "node": "d129109168f0ed985e51b0f86df256acdcfcfe45",
+                  "parents": [
+                      "418a63f508062fb2eb9130065c5ddc7908dd5949"
+                  ],
+                  "tags": [
+                      "tip"
+                  ]
+              }
+          ],
+          "date": \d+, (re)
+          "user": "user@example.com"
+      }
+  }
 
 FIXME Hidden changesets should not be exposed to version 2
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?version=2"
   200
   {
       "lastpushid": 4,
       "pushes": {
           "1": {
               "changesets": [
                   "96ee1d7354c4ad7372047672c36a1f561e3a6a4c"
               ],
               "date": \d+, (re)
               "user": "user@example.com"
           },
           "2": {
-              "changesets": [
-                  "ae13d9da6966307c98b60987fb4fedc2e2f29736",
-                  "d313a202a85e114000f669c2fcb49ad42376ac04"
-              ],
+              "changesets": [],
               "date": \d+, (re)
               "user": "user@example.com"
           },
           "3": {
               "changesets": [
                   "b3641753ee63b166fad7c5f10060b0cbbc8a86b0",
                   "62eebb2f0f00195f9d965f718090c678c4fa414d"
               ],
@@ -144,41 +229,224 @@ FIXME Hidden changesets should not be ex
               ],
               "date": \d+, (re)
               "user": "user@example.com"
           }
       }
   }
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?version=2&full=1"
-  404
-  "hidden revision 'd313a202a85e114000f669c2fcb49ad42376ac04'"
+  200
+  {
+      "lastpushid": 4,
+      "pushes": {
+          "1": {
+              "changesets": [
+                  {
+                      "author": "test",
+                      "branch": "default",
+                      "desc": "initial",
+                      "files": [
+                          "foo"
+                      ],
+                      "node": "96ee1d7354c4ad7372047672c36a1f561e3a6a4c",
+                      "parents": [
+                          "0000000000000000000000000000000000000000"
+                      ],
+                      "tags": []
+                  }
+              ],
+              "date": \d+, (re)
+              "user": "user@example.com"
+          },
+          "2": {
+              "changesets": [],
+              "date": \d+, (re)
+              "user": "user@example.com"
+          },
+          "3": {
+              "changesets": [
+                  {
+                      "author": "test",
+                      "branch": "default",
+                      "desc": "file2",
+                      "files": [
+                          "file2"
+                      ],
+                      "node": "b3641753ee63b166fad7c5f10060b0cbbc8a86b0",
+                      "parents": [
+                          "96ee1d7354c4ad7372047672c36a1f561e3a6a4c"
+                      ],
+                      "tags": []
+                  },
+                  {
+                      "author": "test",
+                      "branch": "default",
+                      "desc": "file3",
+                      "files": [
+                          "file3"
+                      ],
+                      "node": "62eebb2f0f00195f9d965f718090c678c4fa414d",
+                      "parents": [
+                          "b3641753ee63b166fad7c5f10060b0cbbc8a86b0"
+                      ],
+                      "tags": []
+                  }
+              ],
+              "date": \d+, (re)
+              "user": "user@example.com"
+          },
+          "4": {
+              "changesets": [
+                  {
+                      "author": "test",
+                      "branch": "default",
+                      "desc": "file0",
+                      "files": [
+                          "file0"
+                      ],
+                      "node": "418a63f508062fb2eb9130065c5ddc7908dd5949",
+                      "parents": [
+                          "62eebb2f0f00195f9d965f718090c678c4fa414d"
+                      ],
+                      "tags": []
+                  },
+                  {
+                      "author": "test",
+                      "branch": "default",
+                      "desc": "file1",
+                      "files": [
+                          "file1"
+                      ],
+                      "node": "d129109168f0ed985e51b0f86df256acdcfcfe45",
+                      "parents": [
+                          "418a63f508062fb2eb9130065c5ddc7908dd5949"
+                      ],
+                      "tags": [
+                          "tip"
+                      ]
+                  }
+              ],
+              "date": \d+, (re)
+              "user": "user@example.com"
+          }
+      }
+  }
 
 FIXME Hidden changesets handled properly on feed
 
   $ http --no-headers "http://localhost:$HGPORT/atom-pushlog"
-  404
+  200
   
   <?xml version="1.0" encoding="ascii"?>
   <feed xmlns="http://www.w3.org/2005/Atom">
-   <!-- Error -->
-   <id>http://*:$HGPORT/</id> (glob)
-   <link rel="self" href="http://*:$HGPORT/atom-log"/> (glob)
-   <link rel="alternate" href="http://*:$HGPORT/"/> (glob)
-   <title>Error</title>
-   <updated>1970-01-01T00:00:00+00:00</updated>
+   <id>http://*:$HGPORT/pushlog</id> (glob)
+   <link rel="self" href="http://*:$HGPORT/pushlog"/> (glob)
+   <link rel="alternate" href="http://*:$HGPORT/pushloghtml"/> (glob)
+   <title>server Pushlog</title>
+   <updated>*Z</updated> (glob)
+   <entry>
+    <title>Changeset d129109168f0ed985e51b0f86df256acdcfcfe45</title>
+    <id>http://www.selenic.com/mercurial/#changeset-d129109168f0ed985e51b0f86df256acdcfcfe45</id>
+    <link href="http://*:$HGPORT/rev/d129109168f0ed985e51b0f86df256acdcfcfe45"/> (glob)
+    <updated>*Z</updated> (glob)
+    <author>
+     <name>user@example.com</name>
+    </author>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">file1</li></ul>
+     </div>
+    </content>
+   </entry>
+   <entry>
+    <title>Changeset 418a63f508062fb2eb9130065c5ddc7908dd5949</title>
+    <id>http://www.selenic.com/mercurial/#changeset-418a63f508062fb2eb9130065c5ddc7908dd5949</id>
+    <link href="http://*:$HGPORT/rev/418a63f508062fb2eb9130065c5ddc7908dd5949"/> (glob)
+    <updated>*Z</updated> (glob)
+    <author>
+     <name>user@example.com</name>
+    </author>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">file0</li></ul>
+     </div>
+    </content>
+   </entry>
+   <entry>
+    <title>Changeset 62eebb2f0f00195f9d965f718090c678c4fa414d</title>
+    <id>http://www.selenic.com/mercurial/#changeset-62eebb2f0f00195f9d965f718090c678c4fa414d</id>
+    <link href="http://*:$HGPORT/rev/62eebb2f0f00195f9d965f718090c678c4fa414d"/> (glob)
+    <updated>*Z</updated> (glob)
+    <author>
+     <name>user@example.com</name>
+    </author>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">file3</li></ul>
+     </div>
+    </content>
+   </entry>
    <entry>
-    <title>Error</title>
-    <id>https://mercurial-scm.org/#error</id>
+    <title>Changeset b3641753ee63b166fad7c5f10060b0cbbc8a86b0</title>
+    <id>http://www.selenic.com/mercurial/#changeset-b3641753ee63b166fad7c5f10060b0cbbc8a86b0</id>
+    <link href="http://*:$HGPORT/rev/b3641753ee63b166fad7c5f10060b0cbbc8a86b0"/> (glob)
+    <updated>*Z</updated> (glob)
+    <author>
+     <name>user@example.com</name>
+    </author>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">file2</li></ul>
+     </div>
+    </content>
+   </entry>
+   <entry>
+    <title>Changeset d313a202a85e114000f669c2fcb49ad42376ac04</title>
+    <id>http://www.selenic.com/mercurial/#changeset-d313a202a85e114000f669c2fcb49ad42376ac04</id>
+    <link href="http://*:$HGPORT/rev/d313a202a85e114000f669c2fcb49ad42376ac04"/> (glob)
+    <updated>*Z</updated> (glob)
     <author>
-      <name>mercurial</name>
+     <name>user@example.com</name>
+    </author>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">file2</li></ul>
+     </div>
+    </content>
+   </entry>
+   <entry>
+    <title>Changeset ae13d9da6966307c98b60987fb4fedc2e2f29736</title>
+    <id>http://www.selenic.com/mercurial/#changeset-ae13d9da6966307c98b60987fb4fedc2e2f29736</id>
+    <link href="http://*:$HGPORT/rev/ae13d9da6966307c98b60987fb4fedc2e2f29736"/> (glob)
+    <updated>*Z</updated> (glob)
+    <author>
+     <name>user@example.com</name>
     </author>
-    <updated>1970-01-01T00:00:00+00:00</updated>
-    <content type="text">hidden revision 'd313a202a85e114000f669c2fcb49ad42376ac04'</content>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">file2</li></ul>
+     </div>
+    </content>
    </entry>
+   <entry>
+    <title>Changeset 96ee1d7354c4ad7372047672c36a1f561e3a6a4c</title>
+    <id>http://www.selenic.com/mercurial/#changeset-96ee1d7354c4ad7372047672c36a1f561e3a6a4c</id>
+    <link href="*:$HGPORT/rev/96ee1d7354c4ad7372047672c36a1f561e3a6a4c"/> (glob)
+    <updated>*Z</updated> (glob)
+    <author>
+     <name>user@example.com</name>
+    </author>
+    <content type="xhtml">
+     <div xmlns="http://www.w3.org/1999/xhtml">
+      <ul class="filelist"><li class="file">foo</li></ul>
+     </div>
+    </content>
+   </entry>
+  
   </feed>
   
 
 Specifying a fromchange with a hidden changeset works
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?fromchange=d313a202a85e"
   200
   {
@@ -272,39 +540,45 @@ Specifying a fromchange with a hidden ch
   }
 
 Specifying a tochange with a hidden changeset works
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?startID=1&tochange=ae13d9da6966"
   200
   {
       "2": {
-          "changesets": [
-              "ae13d9da6966307c98b60987fb4fedc2e2f29736",
-              "d313a202a85e114000f669c2fcb49ad42376ac04"
-          ],
+          "changesets": [],
           "date": \d+, (re)
           "user": "user@example.com"
       }
   }
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?startID=1&tochange=ae13d9da6966&full=1"
-  404
-  "hidden revision 'd313a202a85e114000f669c2fcb49ad42376ac04'"
+  200
+  {
+      "2": {
+          "changesets": [],
+          "date": \d+, (re)
+          "user": "user@example.com"
+      }
+  }
 
 Specifying a hidden changeset works
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?changeset=ae13d9da6966"
   200
   {
       "2": {
-          "changesets": [
-              "ae13d9da6966307c98b60987fb4fedc2e2f29736",
-              "d313a202a85e114000f669c2fcb49ad42376ac04"
-          ],
+          "changesets": [],
           "date": \d+, (re)
           "user": "user@example.com"
       }
   }
 
   $ httpjson "http://localhost:$HGPORT/json-pushes?changeset=ae13d9da6966&full=1"
-  404
-  "hidden revision 'd313a202a85e114000f669c2fcb49ad42376ac04'"
+  200
+  {
+      "2": {
+          "changesets": [],
+          "date": \d+, (re)
+          "user": "user@example.com"
+      }
+  }