3 # git-p4.py -- A tool for bidirectional operation between a Perforce depot and git.
5 # Author: Simon Hausmann <hausmann@kde.org>
6 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
9 import optparse
, sys
, os
, marshal
, popen2
12 cmd
= "p4 -G %s" % cmd
13 pipe
= os
.popen(cmd
, "rb")
18 entry
= marshal
.load(pipe
)
34 sys
.stderr
.write(msg
+ "\n")
37 def currentGitBranch():
38 return os
.popen("git-name-rev HEAD").read().split(" ")[1][:-1]
44 self
.description
= "A tool to debug the output of p4 -G."
47 for output
in p4CmdList(" ".join(args
)):
53 # optparse.make_option("--branch", dest="branch", default="refs/heads/master")
55 self
.description
= "A tool to remove stale unused tags from incremental perforce imports."
57 branch
= currentGitBranch()
58 print "Cleaning out stale p4 import tags..."
59 sout
, sin
, serr
= popen2
.popen3("git-name-rev --tags `git-rev-parse %s`" % branch
)
62 tagIdx
= output
.index(" tags/p4/")
64 print "Cannot find any p4/* tag. Nothing to do."
68 caretIdx
= output
.index("^")
70 caretIdx
= len(output
) - 1
71 rev
= int(output
[tagIdx
+ 9 : caretIdx
])
73 allTags
= os
.popen("git tag -l p4/").readlines()
74 for i
in range(len(allTags
)):
75 allTags
[i
] = int(allTags
[i
][3:-1])
82 print os
.popen("git tag -d p4/%s" % rev
).read()
84 print "%s tags removed." % len(allTags
)
86 def printUsage(commands
):
87 print "usage: %s <command> [options]" % sys
.argv
[0]
89 print "valid commands: %s" % ", ".join(commands
)
91 print "Try %s <command> --help for command specific help." % sys
.argv
[0]
96 "clean-tags" : P4CleanTags()
99 if len(sys
.argv
[1:]) == 0:
100 printUsage(commands
.keys())
104 cmdName
= sys
.argv
[1]
106 cmd
= commands
[cmdName
]
108 print "unknown command %s" % cmdName
110 printUsage(commands
.keys())
113 parser
= optparse
.OptionParser("usage: %prog " + cmdName
+ " [options]", cmd
.options
,
114 description
= cmd
.description
)
116 (cmd
, args
) = parser
.parse_args(sys
.argv
[2:], cmd
);