Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Bug 744200 - hg pull shouldn't use -r $REV. r=catlee
Browse files Browse the repository at this point in the history
  • Loading branch information
Rail Aliiev committed Apr 17, 2012
1 parent ac0b42e commit 8763a51
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/python/mozilla_buildtools/test/init_hgrepo.sh
Expand Up @@ -14,6 +14,7 @@ hg init
echo "Hello world $RANDOM" > hello.txt echo "Hello world $RANDOM" > hello.txt
hg add hello.txt hg add hello.txt
hg commit -m "Adding hello" hg commit -m "Adding hello"
hg tag TAG1


hg branch branch2 > /dev/null hg branch branch2 > /dev/null
echo "So long, farewell" >> hello.txt echo "So long, farewell" >> hello.txt
Expand Down
57 changes: 56 additions & 1 deletion lib/python/mozilla_buildtools/test/test_util_hg.py
Expand Up @@ -7,7 +7,7 @@
import util.hg as hg import util.hg as hg
from util.hg import clone, pull, update, hg_ver, mercurial, _make_absolute, \ from util.hg import clone, pull, update, hg_ver, mercurial, _make_absolute, \
share, push, apply_and_push, HgUtilError, make_hg_url, get_branch, \ share, push, apply_and_push, HgUtilError, make_hg_url, get_branch, \
get_branches, path, init, unbundle, adjust_paths get_branches, path, init, unbundle, adjust_paths, is_hg_cset
from util.commands import run_cmd, get_output from util.commands import run_cmd, get_output


def getRevisions(dest): def getRevisions(dest):
Expand Down Expand Up @@ -35,6 +35,34 @@ def testAbsoluteFilePath(self):
def testRelativeFilePath(self): def testRelativeFilePath(self):
self.assertEquals(_make_absolute("file://foo/bar"), "file://%s/foo/bar" % os.getcwd()) self.assertEquals(_make_absolute("file://foo/bar"), "file://%s/foo/bar" % os.getcwd())



class TestIsHgCset(unittest.TestCase):

def testShortCset(self):
self.assertTrue(is_hg_cset('fd06332733e5'))

def testLongCset(self):
self.assertTrue(is_hg_cset('bf37aabfd9367aec573487ebe1f784108bbef73f'))

def testMediumCset(self):
self.assertTrue(is_hg_cset('1e3391794bac9d0e707a7681de3'))

def testInt(self):
self.assertFalse(is_hg_cset(1234567890))

def testTag(self):
self.assertFalse(is_hg_cset('FIREFOX_50_0_RELEASE'))

def testDefault(self):
self.assertFalse(is_hg_cset('default'))

def testTip(self):
self.assertFalse(is_hg_cset('tip'))

def testBranch(self):
self.assertFalse(is_hg_cset('GECKO77_203512230833_RELBRANCH'))


class TestHg(unittest.TestCase): class TestHg(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmpdir = tempfile.mkdtemp() self.tmpdir = tempfile.mkdtemp()
Expand Down Expand Up @@ -147,6 +175,33 @@ def testPullBranch(self):
else: else:
self.assertEquals(getRevisions(self.wc), self.revisions) self.assertEquals(getRevisions(self.wc), self.revisions)


def testPullTag(self):
clone(self.repodir, self.wc)
run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir)
revisions = getRevisions(self.repodir)

rev = pull(self.repodir, self.wc, revision='TAG1')
self.assertEquals(rev, revisions[1])
self.assertEquals(getRevisions(self.wc), revisions)

def testPullTip(self):
clone(self.repodir, self.wc)
run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir)
revisions = getRevisions(self.repodir)

rev = pull(self.repodir, self.wc, revision='tip')
self.assertEquals(rev, revisions[0])
self.assertEquals(getRevisions(self.wc), revisions)

def testPullDefault(self):
clone(self.repodir, self.wc)
run_cmd(['hg', 'tag', '-f', 'TAG1'], cwd=self.repodir)
revisions = getRevisions(self.repodir)

rev = pull(self.repodir, self.wc, revision='default')
self.assertEquals(rev, revisions[0])
self.assertEquals(getRevisions(self.wc), revisions)

def testPullUnrelated(self): def testPullUnrelated(self):
# Create a new repo # Create a new repo
repo2 = os.path.join(self.tmpdir, 'repo2') repo2 = os.path.join(self.tmpdir, 'repo2')
Expand Down
26 changes: 20 additions & 6 deletions lib/python/util/hg.py
Expand Up @@ -62,6 +62,15 @@ def get_branches(path):
branches.append(line.split()[0]) branches.append(line.split()[0])
return branches return branches


def is_hg_cset(rev):
"""Retruns True if passed revision represents a valid HG revision
(long or short(er) 40 bit hex)"""
try:
_ = int(rev, 16)
return True
except (TypeError, ValueError):
return False

def hg_ver(): def hg_ver():
"""Returns the current version of hg, as a tuple of """Returns the current version of hg, as a tuple of
(major, minor, build)""" (major, minor, build)"""
Expand Down Expand Up @@ -203,9 +212,6 @@ def common_args(revision=None, branch=None, ssh_username=None, ssh_key=None):
def pull(repo, dest, update_dest=True, mirrors=None, **kwargs): def pull(repo, dest, update_dest=True, mirrors=None, **kwargs):
"""Pulls changes from hg repo and places it in `dest`. """Pulls changes from hg repo and places it in `dest`.
If `revision` is set, only the specified revision and its ancestors will
be pulled.
If `update_dest` is set, then `dest` will be updated to `revision` if If `update_dest` is set, then `dest` will be updated to `revision` if
set, otherwise to `branch`, otherwise to the head of default. set, otherwise to `branch`, otherwise to the head of default.
Expand All @@ -215,8 +221,7 @@ def pull(repo, dest, update_dest=True, mirrors=None, **kwargs):
if mirrors: if mirrors:
for mirror in mirrors: for mirror in mirrors:
try: try:
retval = pull(mirror, dest, update_dest=update_dest, **kwargs) return pull(mirror, dest, update_dest=update_dest, **kwargs)
return retval
except: except:
log.exception("Problem pulling from mirror %s", mirror) log.exception("Problem pulling from mirror %s", mirror)
continue continue
Expand All @@ -226,7 +231,16 @@ def pull(repo, dest, update_dest=True, mirrors=None, **kwargs):
# Convert repo to an absolute path if it's a local repository # Convert repo to an absolute path if it's a local repository
repo = _make_absolute(repo) repo = _make_absolute(repo)
cmd = ['hg', 'pull'] cmd = ['hg', 'pull']
cmd.extend(common_args(**kwargs)) # Don't pass -r to "hg pull", except when it's a valid HG revision.
# Pulling using tag names is dangerous: it uses the local .hgtags, so if
# the tag has moved on the remote side you won't pull the new revision the
# remote tag refers to.
pull_kwargs = kwargs.copy()
if 'revision' in pull_kwargs and \
not is_hg_cset(pull_kwargs['revision']):
del pull_kwargs['revision']

cmd.extend(common_args(**pull_kwargs))


cmd.append(repo) cmd.append(repo)
run_cmd(cmd, cwd=dest) run_cmd(cmd, cwd=dest)
Expand Down

0 comments on commit 8763a51

Please sign in to comment.