Skip to content

Commit

Permalink
MB-22602: Add gerrit_move_to_kv_engine.py
Browse files Browse the repository at this point in the history
Add a script to assist in migrating patches from the old memcached &
ep-engine repos to kv_engine.

The script will checkout the given change from Gerrit (memcached or
ep-engine), rebase into kv-engine, and then re-upload to Gerrit as a
new change against kv-engine.

The script automatically handles any rebases onto kv_engine which
don't otherwise conflict with upstream changes on the original repo -
i.e. if your patch would have rebased cleanly prior to the repo merge,
it should cleanly rebase onto the merged repo.

Example usage:

    scripts/gerrit_move_to_kv_engine.py drigby 78323

Example output:

    ** Migrating change 78323 - 'Move Blob to its own file (blob.{cc.h})' to kv_engine
    >> Fetching refs/changes/23/78323/3
    From http://review.couchbase.org/ep-engine
     * branch            refs/changes/23/78323/3 -> FETCH_HEAD
    -- Checking out change
    Previous HEAD position was bd68264... MB-22602: Add 'ep' as a subdir to engines/
    HEAD is now at 5b9d5a4... Move Blob to its own file (blob.{cc.h})
    -- Checking out latest kv_engine/master
    From github.com:couchbase/kv_engine
     * branch            master     -> FETCH_HEAD
    -- Rebasing change onto kv_engine/master
    << Uploading to Gerrit under kv_engine
    ** Successfully moved change to kv_engine

Change-Id: Ib84265529b2d4834d361c1b2db694fb73e9ab65a
Reviewed-on: http://review.couchbase.org/78522
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Daniel Owen <owend@couchbase.com>
  • Loading branch information
daverigby committed May 24, 2017
1 parent 0d5a64f commit 4fe820b
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions scripts/gerrit_move_to_kv_engine.py
@@ -0,0 +1,99 @@
#!/usr/bin/env python2.7

# Script to migrate a Gerrit Change from memcached or ep-engine repos
# to the new kv_enigne repo.

from __future__ import print_function
import json
import subprocess
import sys
import urllib2


class bcolors:
HEADER = '\033[35m'
OKBLUE = '\033[34m'
OKGREEN = '\033[32m'
WARNING = '\033[33m'
FAIL = '\033[31m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'


def header(*args):
print(bcolors.OKBLUE, end='')
print(*args, end='')
print(bcolors.ENDC)


def success(*args):
print(bcolors.OKGREEN, end='')
print(*args, end='')
print(bcolors.ENDC)


if len(sys.argv) != 3:
print("""Migrates existing Gerrit changes from
memcached/ep-engine repo to kv_engine repo.
Checks out the specifed change, rebases to kv_engine and re-uploads to
gerrit as a kv_engine change.
Usage: gerrit_move_to_kv_engine.py <username> <change> <patch_set>
username Username for Gerrit - see
http://review.couchbase.org/#/settings/ under 'Profile'
change Change number
Example: gerrit_move_to_kv_engine.py drigby memcached 78322 3
""", file=sys.stderr)
exit(1)

user = sys.argv[1]
change = sys.argv[2]

info = dict()
# Check this patch exists and determine which project it is from.
try:
url = "http://review.couchbase.org/changes/{}".format(change)
f = urllib2.urlopen(url + "?o=CURRENT_REVISION&o=DOWNLOAD_COMMANDS")
data = f.read()[5:] # The first 4 chars of response are ')]}'
info = json.loads(data)
except urllib2.HTTPError as e:
print ("Error: failed to lookup change {} from {}: {}".format(change,
url, e),
file=sys.stderr)
print ("Check your Change is valid", file=sys.stderr)
exit(1)

header("** Migrating change {} - '{}' to kv_engine".format(change,
info['subject']))

cur_rev_info = info['revisions'][info['current_revision']]
fetch_info = cur_rev_info['fetch']['anonymous http']

header(">> Fetching", fetch_info['ref'])
subprocess.check_output(["git", "fetch", fetch_info['url'],
fetch_info['ref']])

header("-- Checking out change", bcolors.ENDC)
subprocess.check_output(["git", "checkout", "FETCH_HEAD"])

download_URL = "git@github.com:couchbase/kv_engine.git"
header("-- Checking out latest kv_engine/master")
subprocess.check_output(["git", "fetch", download_URL, "master"])

header("-- Rebasing change onto kv_engine/master")
if info['project'] == 'ep-engine':
subprocess.check_output(["git", "rebase",
"--strategy=subtree",
"--strategy-option=subtree=engines/ep",
"FETCH_HEAD"])
else:
subprocess.check_output(["git", "rebase", "FETCH_HEAD"])

upload_URL = "ssh://{}@review.couchbase.org:29418/kv_engine".format(user)
header("<< Uploading to Gerrit under kv_engine")
subprocess.check_output(["git", "push", upload_URL,
"HEAD:refs/for/master"])
success("** Successfully moved change to kv_engine")

0 comments on commit 4fe820b

Please sign in to comment.