mozreview: remove support for remotely stripping changesets (bug 1359945); r?mcote draft
authorGregory Szorc <gps@mozilla.com>
Wed, 26 Apr 2017 11:42:52 -0700
changeset 10868 08a627572c1df33ba3785e2b74f68730d9667c3e
parent 10867 c10283329959cca97f7f714d47f838d1268a7a9d
child 10869 027ee34900eb02ba7e5731ba9919ec68468db718
push id1641
push userbmo:gps@mozilla.com
push dateWed, 26 Apr 2017 18:46:15 +0000
reviewersmcote
bugs1359945
mozreview: remove support for remotely stripping changesets (bug 1359945); r?mcote This should be a rubber stamp review as far as the code goes. The "hard" part of the review is deciding we want to do this. The feature was implemented with the intent to automate stripping of changesets. 2 years later and it isn't automated. Furthermore, this feature isn't enabled in production because the remote_strip_users config option isn't set. So the feature is dead code. MozReview-Commit-ID: DD1pv0wYmxS
ansible/roles/docker-hg-reviewboard/files/set-strip-users
ansible/roles/docker-hg-reviewboard/tasks/main.yml
hgext/reviewboard/server.py
hgext/reviewboard/tests/test-remote-strip.t
deleted file mode 100755
--- a/ansible/roles/docker-hg-reviewboard/files/set-strip-users
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# This script is needed for test-remote-strip.t. In theory it should be
-# possible to do this via remote Docker exec. But shell quoting was
-# proving problematic.
-#
-# Script takes as arguments the repo relpath and a string for the
-# "remote_strip_users" value.
-
-set -e
-
-/usr/bin/ansible localhost -c local -m ini_file -a \
-  "dest=/repo/hg/mozilla/$1/.hg/hgrc section=reviewboard option=remote_strip_users value=$2"
--- a/ansible/roles/docker-hg-reviewboard/tasks/main.yml
+++ b/ansible/roles/docker-hg-reviewboard/tasks/main.yml
@@ -7,17 +7,16 @@
         mode=0644
 
 - name: install Docker support scripts
   copy: src={{ item }} dest=/{{ item }} mode=0755
   with_items:
     - create-repo
     - kill-wsgi-procs
     - refresh
-    - set-strip-users
     - set-urls
 
 - name: Install psutil
   pip: name=psutil
 
 - name: Configure MozReview user
   ini_file: dest=/etc/mercurial/hgrc section={{ item.section }} option={{ item.option }} value="{{ item.value }}"
   with_items:
--- a/hgext/reviewboard/server.py
+++ b/hgext/reviewboard/server.py
@@ -23,19 +23,16 @@ import json
 import os
 import sys
 
 from mercurial import (
     cmdutil,
     demandimport,
     extensions,
     hg,
-    phases,
-    pushkey,
-    repair,
     util,
     wireproto,
 )
 from mercurial.i18n import _
 from mercurial.node import (
     hex,
     nullid,
 )
@@ -146,55 +143,16 @@ def changegrouphook(ui, repo, source, ur
         _('REVIEWBOARD: See https://hg.mozilla.org/hgcustom/version-control-tools/file/tip/hgext/reviewboard/README.rst\n'))
 
 
 def disallowpushhook(ui, repo, **kwargs):
     repo.ui.write(nopushdiscoveryrepos)
     return 1
 
 
-def pushstrip(repo, key, old, new):
-    """pushkey for strip that allows remote stripping.
-
-    We only allow users in a controlled users list to perform remote stripping.
-    """
-    if 'USER' not in os.environ:
-        repo.ui.write(_('request not authenticated; cannot perform remote strip\n'))
-        return 0
-
-    allowed = repo.ui.configlist('reviewboard', 'remote_strip_users')
-    if os.environ['USER'] not in allowed:
-        repo.ui.write(_('user not in list of users allowed to remote strip\n'))
-        return 0
-
-    nodes = []
-    for node in new.splitlines():
-        ctx = repo[node]
-        # Stripping changesets that are public carries too much risk that too
-        # many children changesets will also get stripped. Disallow the
-        # practice.
-        if ctx.phase() == phases.public:
-            repo.ui.write(_('cannot strip public changeset: %s\n') % ctx.hex())
-            return 0
-
-        nodes.append(ctx.node())
-
-    # The strip extension does higher-level things like remove bookmarks
-    # referencing stripped changesets. We shouldn't need this functionality, so
-    # we use the core API.
-    repair.strip(repo.ui, repo, nodes, backup=True, topic='remotestrip')
-    return 1
-
-
-def liststrip(repo):
-    """listkeys for strip pushkey namespace."""
-    # Namespace is push only, so nothing to return.
-    return {}
-
-
 def listreviewrepos(repo):
     """Obtains a mapping of available repositories to root node.
 
     The data is read from a file so as to incur minimal run-time overhead.
     """
     repos = {}
     for line in repo.vfs.tryreadlines('reviewrepos'):
         line = line.rstrip()
@@ -367,17 +325,16 @@ def capabilitieswebcommand(web, req, tmp
     return sendjsonresponse(req, {
         'reviewcaps': sorted(reviewcapabilities(web.repo)),
         'reviewrequires': sorted(requirecaps),
     })
 
 
 def extsetup(ui):
     extensions.wrapfunction(wireproto, '_capabilities', capabilities)
-    pushkey.register('strip', pushstrip, liststrip)
 
     # To short circuit operations with discovery repos.
     extensions.wrapcommand(wireproto.commands, 'heads', wrappedwireprotoheads)
 
     setattr(webcommands, 'mozreviewcapabilities', capabilitieswebcommand)
     webcommands.__all__.append('mozreviewcapabilities')
 
     setattr(webcommands, 'mozreviewsubmitseries', submitserieswebcommand)
deleted file mode 100644
--- a/hgext/reviewboard/tests/test-remote-strip.t
+++ /dev/null
@@ -1,127 +0,0 @@
-#require mozreviewdocker
-  $ . $TESTDIR/hgext/reviewboard/tests/helpers.sh
-  $ commonenv
-
-debugpushkey doesn't inherit this setting from the host repo so define it
-globally
-
-  $ cat >> $HGRCPATH << EOF
-  > [ui]
-  > ssh = $TESTDIR/testing/mozreview-ssh
-  > EOF
-
-  $ bugzilla create-bug TestProduct TestComponent 1
-
-  $ cd client
-  $ echo initial > foo
-  $ hg -q commit -A -m initial
-  $ hg phase --public -r .
-
-  $ echo h1c1 > foo
-  $ hg commit -m h1c1
-  $ echo h1c2 > foo
-  $ hg commit -m h1c2
-  $ hg -q up -r 0
-  $ echo h2c1 > foo
-  $ hg commit -m h2c1
-  created new head
-  $ echo h2c2 > foo
-  $ hg commit -m h2c2
-
-  $ hg log -T '{node} {desc}\n'
-  85811c4bd2cd093cee28e98e7bb7a641965bf889 h2c2
-  faaa0821e83d9b1c7070b1e458a809a79173579c h2c1
-  0050780911c81eed28216c404bc64e6ecdab9a54 h1c2
-  cd04635afb3cc9f4d8b8d074465a7e3d0d70908e h1c1
-  55482a6fb4b1881fa8f746fd52cf6f096bb21c89 initial
-
-  $ hg push -r 2 --reviewid bz://1/mynick-1 --config reviewboard.autopublish=false
-  pushing to ssh://$DOCKER_HOSTNAME:$HGPORT6/test-repo
-  (adding commit id to 2 changesets)
-  saved backup bundle to $TESTTMP/client/.hg/strip-backup/0050780911c8*-addcommitid.hg (glob)
-  searching for changes
-  remote: adding changesets
-  remote: adding manifests
-  remote: adding file changes
-  remote: added 3 changesets with 3 changes to 1 files
-  remote: recorded push in pushlog
-  submitting 2 changesets for review
-  
-  changeset:  3:51c15ef8210f
-  summary:    h1c1
-  review:     http://$DOCKER_HOSTNAME:$HGPORT1/r/2 (draft)
-  
-  changeset:  4:b560312f6487
-  summary:    h1c2
-  review:     http://$DOCKER_HOSTNAME:$HGPORT1/r/3 (draft)
-  
-  review id:  bz://1/mynick-1
-  review url: http://$DOCKER_HOSTNAME:$HGPORT1/r/1 (draft)
-  
-  (review requests lack reviewers; visit review url to assign reviewers)
-  (visit review url to publish these review requests so others can see them)
-
-  $ hg push -r . --reviewid bz://1/mynick-2 --config reviewboard.autopublish=false
-  pushing to ssh://$DOCKER_HOSTNAME:$HGPORT6/test-repo
-  (adding commit id to 2 changesets)
-  saved backup bundle to $TESTTMP/client/.hg/strip-backup/85811c4bd2cd*-addcommitid.hg (glob)
-  searching for changes
-  remote: adding changesets
-  remote: adding manifests
-  remote: adding file changes
-  remote: added 2 changesets with 2 changes to 1 files (+1 heads)
-  remote: recorded push in pushlog
-  submitting 2 changesets for review
-  
-  changeset:  3:172c9543f80c
-  summary:    h2c1
-  review:     http://$DOCKER_HOSTNAME:$HGPORT1/r/5 (draft)
-  
-  changeset:  4:e8c63e38a772
-  summary:    h2c2
-  review:     http://$DOCKER_HOSTNAME:$HGPORT1/r/6 (draft)
-  
-  review id:  bz://1/mynick-2
-  review url: http://$DOCKER_HOSTNAME:$HGPORT1/r/4 (draft)
-  
-  (review requests lack reviewers; visit review url to assign reviewers)
-  (visit review url to publish these review requests so others can see them)
-
-User can't remote strip unless allowed
-
-  $ hg debugpushkey ssh://$DOCKER_HOSTNAME:$HGPORT6/test-repo strip dummy '' f5dc8e52d06801d11b624f3bf4d742240ed200e9
-  remote: user not in list of users allowed to remote strip
-  False
-  [1]
-
-User in whitelist can strip
-
-  $ mozreview create-ldap-user adminuser@example.com adminuser 2002 'Admin User' --key-file ${MOZREVIEW_HOME}/keys/adminuser@example.com --scm-level 1
-  $ export SSH_KEYNAME=adminuser@example.com
-  $ mozreview exec hgrb /set-strip-users test-repo adminuser@example.com > /dev/null
-
-  $ hg debugpushkey ssh://$DOCKER_HOSTNAME:$HGPORT6/test-repo strip dummy '' 51c15ef8210ffd51361c9197c85d5a4aa1bdd4a5
-  remote: saved backup bundle to /repo/hg/mozilla/test-repo/.hg/strip-backup/51c15ef8210f-7eb5dc8a-remotestrip.hg
-  remote: changeset will be deleted from pushlog: 51c15ef8210ffd51361c9197c85d5a4aa1bdd4a5
-  remote: changeset will be deleted from pushlog: b560312f64877bf0f5261d9cd1d71e71637be899
-  remote: changeset rev will be updated in pushlog: 172c9543f80cfa7f85ad5a0a6ad9b005cd18825c
-  remote: changeset rev will be updated in pushlog: e8c63e38a772cd7da20caff013d5ec3f85a02fd5
-  True
-
-  $ hg -q clone ssh://${HGSSH_HOST}:${HGSSH_PORT}/test-repo new-repo
-  $ hg -R new-repo log -T '{node} {desc|firstline}\n'
-  e8c63e38a772cd7da20caff013d5ec3f85a02fd5 h2c2
-  172c9543f80cfa7f85ad5a0a6ad9b005cd18825c h2c1
-  55482a6fb4b1881fa8f746fd52cf6f096bb21c89 initial
-
-Stripping of public changesets is disallowed
-
-  $ hg debugpushkey ssh://$DOCKER_HOSTNAME:$HGPORT6/test-repo strip dummy '' 55482a6fb4b1881fa8f746fd52cf6f096bb21c89
-  remote: cannot strip public changeset: 55482a6fb4b1881fa8f746fd52cf6f096bb21c89
-  False
-  [1]
-
-Cleanup
-
-  $ mozreview stop
-  stopped 9 containers