PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

/js/src/find-child.py

http://github.com/zpao/v8monkey
Python | 105 lines | 37 code | 16 blank | 52 comment | 12 complexity | 10651b4c242ae835166e4ca3bd2679c0 MD5 | raw file
  1#!/usr/bin/python
  2# ***** BEGIN LICENSE BLOCK *****
  3# Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4#
  5# The contents of this file are subject to the Mozilla Public License Version
  6# 1.1 (the "License"); you may not use this file except in compliance with
  7# the License. You may obtain a copy of the License at
  8# http://www.mozilla.org/MPL/
  9#
 10# Software distributed under the License is distributed on an "AS IS" basis,
 11# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 12# for the specific language governing rights and limitations under the
 13# License.
 14#
 15# The Original Code is SpiderMonkey JavaScript engine.
 16#
 17# The Initial Developer of the Original Code is
 18# Mozilla Corporation.
 19# Portions created by the Initial Developer are Copyright (C) 2009
 20# the Initial Developer. All Rights Reserved.
 21#
 22# Contributor(s):
 23#   Graydon Hoare <graydon@mozilla.com>
 24#
 25# Alternatively, the contents of this file may be used under the terms of
 26# either the GNU General Public License Version 2 or later (the "GPL"), or
 27# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 28# in which case the provisions of the GPL or the LGPL are applicable instead
 29# of those above. If you wish to allow use of your version of this file only
 30# under the terms of either the GPL or the LGPL, and not to allow others to
 31# use your version of this file under the terms of the MPL, indicate your
 32# decision by deleting the provisions above and replace them with the notice
 33# and other provisions required by the GPL or the LGPL. If you do not delete
 34# the provisions above, a recipient may use your version of this file under
 35# the terms of any one of the MPL, the GPL or the LGPL.
 36#
 37# ***** END LICENSE BLOCK *****
 38#
 39# The output of this script is a splicemap.
 40#
 41# A splicemap is used by the mercurial 'convert' extension to direct its
 42# splicing operation.
 43#
 44# The script assumes you already have a destination repository
 45# containing a conversion somewhere in its history, but that you've
 46# possibly mixed some new commits on top of that conversion. It outputs
 47# a splicemap that picks up the conversion where it left off (with the
 48# first descendant, in the source repo, of the src rev given by --start,
 49# if or rather the first descendant that would be included by the
 50# conversion's filemap) and connects them to the current tip of the
 51# destination repo.
 52#
 53
 54from mercurial import ui, hg
 55from hgext.convert.filemap import filemapper
 56from optparse import OptionParser
 57
 58import sys
 59
 60parser = OptionParser()
 61
 62parser.add_option("-s", "--src", dest="src",
 63                  help="source repository", metavar="REPO")
 64
 65parser.add_option("-d", "--dst", dest="dst",
 66                  help="destination repository", metavar="REPO")
 67
 68parser.add_option("-t", "--start", dest="start",
 69                  help="starting revid in source repository", metavar="REV")
 70
 71parser.add_option("-f", "--filemap", dest="filemap",
 72                  help="filemap used in conversion", metavar="PATH")
 73
 74(options, args) = parser.parse_args()
 75
 76if not (options.src and options.dst and options.start):
 77    parser.print_help()
 78    exit(1)
 79
 80u = ui.ui()
 81
 82src_repo = hg.repository(u, options.src)
 83dst_repo = hg.repository(u, options.dst)
 84
 85fm = None
 86if options.filemap:
 87    fm = filemapper(u, options.filemap)
 88
 89last_converted_src = src_repo[options.start]
 90
 91dst_tip = dst_repo.changectx(dst_repo.changelog.tip()).hex()
 92revs = last_converted_src.children()
 93
 94while len(revs) != 0:
 95    tmp = revs
 96    revs = []
 97    for child in tmp:
 98        for f in child.files():
 99            if (not fm) or fm(f):
100                u.write("%s %s\n" % (child.hex(), dst_tip))
101                exit(0);
102        revs.extend(child.children())
103
104sys.stderr.write("No candidate child found in source repository\n")
105exit(1)