Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / find-child.py
1 #!/usr/bin/python
2 #
3 # The output of this script is a splicemap.
4 #
5 # A splicemap is used by the mercurial 'convert' extension to direct its
6 # splicing operation.
7 #
8 # The script assumes you already have a destination repository
9 # containing a conversion somewhere in its history, but that you've
10 # possibly mixed some new commits on top of that conversion. It outputs
11 # a splicemap that picks up the conversion where it left off (with the
12 # first descendant, in the source repo, of the src rev given by --start,
13 # if or rather the first descendant that would be included by the
14 # conversion's filemap) and connects them to the current tip of the
15 # destination repo.
16 #
17
18 from mercurial import ui, hg
19 from hgext.convert.filemap import filemapper
20 from optparse import OptionParser
21
22 import sys
23
24 parser = OptionParser()
25
26 parser.add_option("-s", "--src", dest="src",
27                   help="source repository", metavar="REPO")
28
29 parser.add_option("-d", "--dst", dest="dst",
30                   help="destination repository", metavar="REPO")
31
32 parser.add_option("-t", "--start", dest="start",
33                   help="starting revid in source repository", metavar="REV")
34
35 parser.add_option("-f", "--filemap", dest="filemap",
36                   help="filemap used in conversion", metavar="PATH")
37
38 (options, args) = parser.parse_args()
39
40 if not (options.src and options.dst and options.start):
41     parser.print_help()
42     exit(1)
43
44 u = ui.ui()
45
46 src_repo = hg.repository(u, options.src)
47 dst_repo = hg.repository(u, options.dst)
48
49 fm = None
50 if options.filemap:
51     fm = filemapper(u, options.filemap)
52
53 last_converted_src = src_repo[options.start]
54
55 dst_tip = dst_repo.changectx(dst_repo.changelog.tip()).hex()
56 revs = last_converted_src.children()
57
58 while len(revs) != 0:
59     tmp = revs
60     revs = []
61     for child in tmp:
62         for f in child.files():
63             if (not fm) or fm(f):
64                 u.write("%s %s\n" % (child.hex(), dst_tip))
65                 exit(0);
66         revs.extend(child.children())
67
68 sys.stderr.write("No candidate child found in source repository\n")
69 exit(1)