-
Notifications
You must be signed in to change notification settings - Fork 26
/
git-cms-import-tagset
executable file
·75 lines (70 loc) · 3.16 KB
/
git-cms-import-tagset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
from optparse import OptionParser
from commands import getstatusoutput
from sys import exit
def format(s, **kwds):
return s.encode(errors="ignore") % kwds
def die(*out):
for x in out:
print x
exit(1)
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-n", "--dry-run", help="Do not do it but just print out the commit", dest="dryRun", action="store_true", default=False)
parser.add_option("-d", "--dependency", help="Specify tagset dependency", dest="dependencies", default=None)
parser.add_option("-m", "--merge", help="Do merge", dest="merge", default=False, action="store_true")
parser.add_option("-s", "--strategy", help="Strategy to be used for the merge", dest="strategy", default="")
parser.add_option("-X", "--strategy-option", help="Strategy to be used for the merge", dest="strategyOption", default="")
opts, args = parser.parse_args()
if not len(args):
parser.error("Please specify at least one tagset ID")
if opts.strategy:
opts.strategy = "-s " + opts.strategy
if opts.strategyOption:
opts.strategyOption = "-X " + opts.strategyOption
if opts.merge:
opts.merge = "-m"
else:
opts.merge = ""
for tagset in args:
err, out = getstatusoutput("cmstc tagset %s" % tagset)
pairs = [[y for y in x.split(" ") if y] for x in out.strip().split("\n")]
print pairs
getstatusoutput("rm -rf $CMSSW_BASE/src")
for (pkg, tag) in pairs:
print pkg, tag
err, out = getstatusoutput(format("set -e ; git cms-addpkg %(pkg)s; cd $CMSSW_BASE/src; cvs rdiff -r CMSSW_6_2_0_pre8 -r %(tag)s %(pkg)s | patch -p1",
pkg=pkg,
tag=tag))
if err:
die("Error while executing command", out)
print out
err, out = getstatusoutput(format("set -e ; cd $CMSSW_BASE/src ; git add -A . ; git commit -m \"`cmstc tagsetinfo %(tagset)s | grep -A100 -e'Description:' | grep -v -e '^Description:'`\"",
tagset=tagset))
if err:
die("Error while creating commit", out)
if not opts.dependencies:
err, out = getstatusoutput(format("set -e ; cd $CMSSW_BASE/src ; git rebase official-cmssw/CMSSW_7_0_X",
tagset=tagset))
else:
for dep in opts.dependencies.split(","):
command = format("set -e ; cd $CMSSW_BASE/src ; git fetch my-cmssw tagset-%(tagset)s:my-cmssw/tagset-%(tagset)s; git rebase %(merge)s %(strategy)s %(strategyOption)s my-cmssw/tagset-%(tagset)s",
tagset=dep,
strategy=opts.strategy,
strategyOption=opts.strategyOption,
merge=opts.merge)
print command
err, out = getstatusoutput(command)
if err:
die("Error while rebasing", out)
print out
if opts.dryRun:
err, out = getstatusoutput("cd $CMSSW_BASE/src ; git show")
if err:
die("Error while doing git show", out)
print out
exit(0)
err, out = getstatusoutput(format("cd $CMSSW_BASE/src ; git push my-cmssw -f HEAD:tagset-%s" % tagset))
if err:
die("Error while pushing to your repository", out)
print out