/js/src/find-child.py

http://github.com/zpao/v8monkey · Python · 105 lines · 37 code · 16 blank · 52 comment · 9 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. from mercurial import ui, hg
  54. from hgext.convert.filemap import filemapper
  55. from optparse import OptionParser
  56. import sys
  57. parser = OptionParser()
  58. parser.add_option("-s", "--src", dest="src",
  59. help="source repository", metavar="REPO")
  60. parser.add_option("-d", "--dst", dest="dst",
  61. help="destination repository", metavar="REPO")
  62. parser.add_option("-t", "--start", dest="start",
  63. help="starting revid in source repository", metavar="REV")
  64. parser.add_option("-f", "--filemap", dest="filemap",
  65. help="filemap used in conversion", metavar="PATH")
  66. (options, args) = parser.parse_args()
  67. if not (options.src and options.dst and options.start):
  68. parser.print_help()
  69. exit(1)
  70. u = ui.ui()
  71. src_repo = hg.repository(u, options.src)
  72. dst_repo = hg.repository(u, options.dst)
  73. fm = None
  74. if options.filemap:
  75. fm = filemapper(u, options.filemap)
  76. last_converted_src = src_repo[options.start]
  77. dst_tip = dst_repo.changectx(dst_repo.changelog.tip()).hex()
  78. revs = last_converted_src.children()
  79. while len(revs) != 0:
  80. tmp = revs
  81. revs = []
  82. for child in tmp:
  83. for f in child.files():
  84. if (not fm) or fm(f):
  85. u.write("%s %s\n" % (child.hex(), dst_tip))
  86. exit(0);
  87. revs.extend(child.children())
  88. sys.stderr.write("No candidate child found in source repository\n")
  89. exit(1)