forked from cms-sw/cms-git-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-cms-cvs-history
executable file
·131 lines (119 loc) · 4.68 KB
/
git-cms-cvs-history
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
from commands import getstatusoutput
from optparse import OptionParser
from sys import exit
from os import environ, chdir
from os.path import exists, join
import re
def format(s, **kwds):
return s % kwds
def die(s, verbose=None):
print s
if verbose:
print verbose
exit(1)
def findSymbol(tag, package):
cmssw_base = environ["CMSSW_BASE"]
if tag == "HEAD":
tag = "master"
if tag != "master":
branchAttempt = format("refs/remotes/%(package)s/%(package)s-%(tag)s",
package=package,
tag=tag)
else:
branchAttempt = format("refs/remotes/%(package)s/master",
package=package,
tag=tag)
tagAttempt = format("refs/tags/%(package)s-%(tag)s",
package=package,
tag=tag)
if exists(join(cmssw_base, "src/.git", branchAttempt)):
tag = branchAttempt
elif exists(join(cmssw_base, "src/.git", tagAttempt)):
tag = tagAttempt
else:
print branchAttempt
die("Unable to find symbol %s for package %s." % (tag, realPackage))
return tag
if __name__ == "__main__":
parser = OptionParser(usage="git cms-cvs-history diff <cvs-tag>[..<cvs-tag>] SubSystem/Package\n"
" import <cvs-tag> SubSystem/Package\n"
" tags SubSystem/Package\n"
" log SubSystem/Package")
opts, args = parser.parse_args()
if len(args) < 1:
parser.error("`git cms-cvs-history' requires either `import`, `diff', `tags' or `log' sub-command")
if len(args) == 1:
parser.error("`git cms-cvs-history' requires %s requires a package" % args[0])
command = args[0]
if not command in ["diff", "import", "log", "tags"]:
parser.error("`git cms-cvs-history' requires either `import`, `diff' or `log' sub-command")
cmssw_base = environ.get("CMSSW_BASE", None)
if not cmssw_base:
die("Please setup your CMSSW area")
chdir(join(cmssw_base, "src"))
err, output = getstatusoutput(format("cd $CMSSW_BASE/src ; git init"))
if err:
die("Error while setting up git repository")
# The last arg should be the package
realPackage = args[-1]
package = args[-1].replace("/","-")
err, output = getstatusoutput("git remote show | grep %s" % package)
if err:
err, output = getstatusoutput(format("git remote add %(package)s [email protected]:cms-cvs-history/%(package)s.git",
package=package))
if err:
die("Error while adding repository", output)
err, output = getstatusoutput(format("git fetch %(package)s ;"
"git fetch %(package)s --tags", package=package))
if err:
err, output2 = getstatusoutput(format("git remote rm %(package)s",
package=package))
die("Could not fetch info for package package %s." % package, output)
# Poor man command dispatcher..
if command == "diff":
if len(args) != 3:
parser.error("diff requires <cvs-tag>[..<cvs-tag>] <package>")
diffArgs = args[1]
tags = diffArgs.split("..")
if len(tags) == 1:
tags.append("HEAD")
tags[0] = findSymbol(tags[0], package)
tags[1] = findSymbol(tags[1], package)
err, output = getstatusoutput("git diff %s..%s" % (tags[0], tags[1]))
if err:
die("Could not create diff", output)
print output
exit(0)
elif command == "tags":
if len(args) == 1:
parser.error("Please specify a package")
err, output = getstatusoutput(format("git tag | grep -e '^%(package)s' | sed -e's/^%(package)s-//'",
package=package))
print output
exit(0)
elif command == "import":
tag = "master"
if len(args) == 3:
tag = args[1]
elif len(args) != 2:
parser.error("`import` takes only <tag> and <package> as arguments.")
tag = findSymbol(tag, package)
command = format("mkdir -p $CMSSW_BASE/src/%(realPackage)s &&"
"cd $CMSSW_BASE/src &&"
"git archive --format=tar %(tag)s | (cd $CMSSW_BASE/src/%(realPackage)s ; tar xf -)",
package=package,
tag=tag,
realPackage=realPackage)
err, output = getstatusoutput(command)
if err:
die("Error while checking out %s" % realPackage, output)
exit(0)
elif command == "log":
tag = "master"
if len(args) == 3:
tag = args[1]
err, output = getstatusoutput("git log refs/remotes/%s/%s" % (package, tag))
if err:
die("Error while doing git log", output)
print output