/usr/bin/cvsconvert is in cvs-fast-export 1.35-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | #! /usr/bin/python
"""
cvsconvert - convert a CVS repo and check against the original
Convert, and check the tree content of a gitspace conversion against
the CVS. The tip state of every branch, and every tag, is checked.
Will produce spurious errors if any CVS branch name had to be sanitized.
"""
# This is the testlifter.py code from the distribution directory.
# Modify it there, not here
"""
Test framework for cvs-fast-export.
"""
import sys, os, shutil, subprocess, time, filecmp
DEBUG_STEPS = 1
DEBUG_COMMANDS = 2
DEBUG_VCS = 3
DEBUG_LIFTER = 4
verbose = 0
os.putenv("PATH", os.getenv("PATH") + os.pathsep + "..")
def noisy_run(dcmd, legend=""):
"Either execute a command or raise a fatal exception."
if legend:
legend = " " + legend
caller = os.path.basename(sys.argv[0])
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("%s: executing '%s'%s\n" % (caller, dcmd, legend))
try:
retcode = subprocess.call(dcmd, shell=True)
if retcode < 0:
sys.stderr.write("%s: %s was terminated by signal %d.\n" % (-caller, dcmd, retcode))
sys.exit(1)
elif retcode != 0:
sys.stderr.write("%s: %s returned %d.\n" % (caller, dcmd, retcode))
return False
except (OSError, IOError) as e:
sys.stderr.write("%s: execution of %s%s failed: %s\n" % (caller, dcmd, legend, e))
return False
return True
def capture_or_die(dcmd, legend=""):
"Either execute a command and capture its output or die."
if legend:
legend = " " + legend
caller = os.path.basename(sys.argv[0])
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("%s: executing '%s'%s\n" % (caller, dcmd, legend))
try:
return subprocess.Popen(dcmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
except subprocess.CalledProcessError as e:
if e.returncode < 0:
sys.stderr.write("%s: child was terminated by signal %d." % (caller, -e.returncode))
elif e.returncode != 0:
sys.stderr.write("%s: child returned %d." % (caller, e.returncode))
sys.exit(1)
class directory_context:
def __init__(self, target):
self.target = target
self.source = None
def __enter__(self):
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("In %s: " % os.path.relpath(self.target))
self.source = os.getcwd()
if os.path.isdir(self.target):
os.chdir(self.target)
def __exit__(self, extype, value_unused, traceback_unused):
os.chdir(self.source)
class RCSRepository:
"An RCS file collection."
def __init__(self, name):
self.name = name
self.retain = False
# For convenience, emulate the module structure of a CVS repository
self.directory = os.path.join(os.getcwd(), self.name, "module")
self.conversions = []
def run_with_cleanup(self, cmd):
if not noisy_run(cmd):
if not self.retain:
self.cleanup()
sys.exit(1)
def do(self, cmd, *args):
"Execute a RCS command in context of this repo."
if verbose < DEBUG_VCS:
mute = '-q'
else:
mute = ""
if not noisy_run("cd %s && %s %s %s" % (self.directory, cmd, mute, " ".join(args))) and not self.retain:
self.cleanup()
sys.exit(1)
def init(self):
"Initialize the repository."
self.run_with_cleanup("rm -fr {0} && mkdir -p {0}".format(self.directory))
def write(self, fn, content):
"Create file content in the repository."
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("%s <- %s" % (fn, content))
with directory_context(self.directory):
with open(fn, "w") as fp:
fp.write(content)
def add(self, filename):
"Add a file to the version-controlled set."
self.do("rcs", "-t-", "-i", filename)
def tag(self, filename, name):
"Create a tag on a specified file."
self.do("rcs", "-n" + name + ":", filename)
def checkout(self, filename):
"Check out a writeable copy of the specified file."
self.do("co", "-l", filename)
def checkin(self, filename, message):
"Check in changes to the specified file."
self.do("ci", "-m'%s' %s" % (message, filename))
def stream(self, module, gitdir, outfile, more_opts=''):
vopt = "-v " * (verbose - DEBUG_LIFTER + 1)
# The -L is necessary to handle proxied directories.
self.run_with_cleanup('find -L {0} -name "*,v" | cvs-fast-export {1} {2} >{3}'.format(self.directory, vopt, more_opts, outfile))
def convert(self, module, gitdir, more_opts=''):
"Convert the repo."
streamfile = "%s.git.fi" % module
self.stream(module, gitdir, streamfile, more_opts)
self.run_with_cleanup("rm -fr {0} && mkdir {0} && git init --quiet {0}".format(gitdir))
self.run_with_cleanup('cat {2} | (cd {1} >/dev/null; git fast-import --quiet --done && git checkout)'.format(self.directory, gitdir, streamfile))
self.conversions.append(gitdir)
if not self.retain:
os.remove(streamfile)
def cleanup(self):
"Clean up the repository conversions."
if not self.retain:
if self.conversions:
os.system("rm -fr %s" % " ".join(self.conversions))
class CVSRepository(RCSRepository):
def __init__(self, name):
RCSRepository.__init__(self, name)
self.directory = os.path.join(os.getcwd(), self.name)
self.checkouts = []
self.conversions = []
def do(self, *cmd):
"Execute a CVS command in context of this repo."
if verbose < DEBUG_VCS:
mute = '-Q'
else:
mute = ""
self.run_with_cleanup("cvs %s -R -d:local:%s %s" % (mute,
self.directory,
" ".join(cmd)))
def init(self):
RCSRepository.init(self)
self.do("init")
def module(self, mname):
"Create an empty module with a specified name."
module = os.path.join(self.directory, mname)
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("Creating module %s\n" % module)
os.mkdir(module)
def checkout(self, module, checkout=None):
"Create a checkout of this repo."
self.checkouts.append(CVSCheckout(self, module, checkout))
return self.checkouts[-1]
def cleanup(self):
"Clean up the repository checkout directories."
if not self.retain:
RCSRepository.cleanup(self)
for checkout in self.checkouts:
checkout.cleanup()
class CVSCheckout:
PROXYSUFFIX = "-proxy"
def __init__(self, repo, module, checkout=None):
self.repo = repo
self.module = module or "module"
self.checkout = checkout or module
# Hack to get around repositories that don't have a CVSROOT & module
self.proxy = None
if not os.path.exists(self.repo.directory + os.sep + "CVSROOT"):
self.proxy = self.repo.name + CVSCheckout.PROXYSUFFIX
try:
shutil.rmtree(self.proxy)
except OSError:
pass
os.mkdir(self.proxy)
os.symlink(self.repo.directory, self.proxy + os.sep + self.module)
os.mkdir(self.proxy + os.sep + "CVSROOT")
self.repo.name += CVSCheckout.PROXYSUFFIX
self.repo.directory += CVSCheckout.PROXYSUFFIX
self.repo.do("co", self.module)
if checkout:
if os.path.exists(checkout):
shutil.rmtree(checkout)
os.rename(self.module, checkout)
self.directory = os.path.join(os.getcwd(), self.checkout)
def do(self, cmd, *args):
"Execute a command in the checkout directory."
with directory_context(self.directory):
apply(self.repo.do, [cmd] + list(args))
def outdo(self, cmd):
"Execute a command in the checkout directory."
with directory_context(self.directory):
self.repo.run_with_cleanup(cmd)
def add(self, *filenames):
"Add a file to the version-controlled set."
apply(self.do, ["add"] + list(filenames))
def remove(self, *files):
"Remove a file from the version-controlled set."
apply(self.do, ["remove", "-f"] + list(files))
def branch(self, branchname):
"Create a new branch."
self.do("tag", branchname + "_root")
self.do("tag", "-r", branchname + "_root", "-b", branchname)
self.do("up", "-r", branchname)
def switch(self, branch="HEAD"):
"Switch to an existing branch."
self.do("up", "-A")
if branch != "HEAD":
self.do("up", "-r", branch)
def tag(self, name):
"Create a tag."
self.do("tag", name)
def merge(self, branchname):
"Merge a branch to trunk."
# See https://kb.wisc.edu/middleware/page.php?id=4087
self.do("tag", "merge_" + branchname)
self.do("up", "-A")
self.do("up", "-j", branchname)
def commit(self, message):
"Commit changes to the repository."
# The CVS tools weren't designed to be called in rapid-fire
# succession by scripts; they have race conditions. This
# presents misbehavior.
time.sleep(2)
apply(self.do, ["commit", "-m '%s'" % message])
def write(self, fn, content):
"Create file content in the repository."
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("%s <- %s" % (fn, content))
with directory_context(self.directory):
with open(fn, "w") as fp:
fp.write(content)
def append(self, fn, content):
"Append to file content in the repository."
if verbose >= DEBUG_COMMANDS:
sys.stdout.write("%s <-| %s" % (fn, content))
with directory_context(self.directory):
with open(fn, "a") as fp:
fp.write(content)
def update(self, rev):
"Update the content to the specified revision or tag."
if rev == 'master':
rev = "HEAD"
self.do("up", "-kb", "-A", "-r", rev)
def cleanup(self):
"Clean up the checkout directory."
if self.proxy and os.path.exists(self.proxy):
shutil.rmtree(self.proxy)
if os.path.exists(self.directory):
shutil.rmtree(self.directory)
def expect_same(a, b):
"Complain if two files aren't identical"
if not os.path.exists(a):
sys.stderr.write("%s does not exist in CVS.\n" % a)
return
if not os.path.exists(b):
sys.stderr.write("%s does not exist in the git conversion.\n" % b)
return
if not filecmp.cmp(a, b, shallow=False):
sys.stderr.write("%s and %s are not the same.\n" % (a, b))
def expect_different(a, b):
"Rejoice if two files are unexpectedly identical"
if not os.path.exists(a):
sys.stderr.write("%s does not exist in CVS.\n" % a)
return
if not os.path.exists(b):
sys.stderr.write("%s does not exist in the git conversion.\n" % b)
return
if filecmp.cmp(a, b, shallow=False):
sys.stderr.write("%s and %s are unexpectedly the same.\n" % (a, b))
def junkbranch(name):
"Is this a synthetic branch generated by cvs-fast-export?"
return name.startswith("import-") or name.find("UNNAMED") != -1
class ConvertComparison:
"Compare a CVS repository and its conversion for equality."
# Needs to stay synchronized with reposurgeon's generic conversion makefile
SUFFIX = "-git"
def __init__(self, stem, repo=None, checkout=None, module=None, options="", showdiffs=False):
self.stem = stem
self.repo = CVSRepository(repo if repo else stem + ".testrepo")
self.checkout = self.repo.checkout(module,
checkout if checkout else stem + ".checkout")
self.module = module or stem
self.showdiffs = showdiffs
self.repo.convert("module", stem + ConvertComparison.SUFFIX, more_opts=options)
with directory_context(stem + ConvertComparison.SUFFIX):
self.branches = [name for name in capture_or_die("git branch -l").split() if name != '*' and not junkbranch(name)]
self.tags = [name for name in capture_or_die("git tag -l").split()]
self.branches.sort()
if "master" in self.branches:
self.branches.remove("master")
self.branches = ["master"] + self.branches
def compare_tree(self, legend, ref, success_expected=True):
"Test to see if a tag or branch checkout has the expected content."
preamble = "%s %s %s: " % (self.stem, legend, ref)
if ref not in self.tags and ref not in self.branches:
if success_expected:
sys.stderr.write(preamble + "%s unexpectedly missing.\n" % ref)
return False
def ftw(mydir, ignore):
for root, dirs, files in os.walk(mydir):
for file in files:
path = os.path.join(root, file)
if ignore not in path.split(os.sep) and not path.endswith(".cvsignore") and not path.endswith(".gitignore"):
yield path
self.checkout.update(ref)
with directory_context(self.stem + ConvertComparison.SUFFIX):
if not noisy_run("git checkout --quiet %s" % ref):
self.repo.cleanup()
sys.exit(1)
if 0:
with directory_context(self.stem + ConvertComparison.SUFFIX):
if not noisy_run("git log --format=%H -1"):
self.repo.cleanup()
sys.exit(1)
cvspaths = list(ftw(self.stem + ".checkout", ignore="CVS"))
cvsfiles = [fn[len(self.stem+".checkout")+1:] for fn in cvspaths]
gitpaths = list(ftw(self.stem + ConvertComparison.SUFFIX, ignore=".git"))
gitfiles = [fn[len(self.stem+ConvertComparison.SUFFIX)+1:] for fn in gitpaths]
cvsfiles.sort()
gitfiles.sort()
success = True
if cvsfiles != gitfiles:
if success_expected:
sys.stderr.write(preamble + "file manifests don't match.\n")
if self.showdiffs:
sys.stderr.write(preamble + "common: %d\n" %
len([f for f in gitfiles if f in cvsfiles]))
gitspace_only = set([f for f in gitfiles if not f in cvsfiles])
if gitspace_only:
sys.stderr.write(preamble + "gitspace only: %s\n" %
gitspace_only)
cvs_only = set([f for f in cvsfiles if not f in gitfiles])
if cvs_only:
sys.stderr.write(preamble + "CVS only: %s\n" %
cvs_only)
success = False
common = [(path, path.replace(".checkout/", ConvertComparison.SUFFIX + "/"))
for path in cvspaths if path.replace(".checkout/", ConvertComparison.SUFFIX + "/") in gitpaths]
for (a, b) in common:
if not filecmp.cmp(a, b, shallow=False):
success = False
if success_expected:
sys.stderr.write("%s %s %s: %s and %s are different.\n" % (self.stem, legend, ref, a, b))
if self.showdiffs:
os.system("diff -u %s %s" % (a, b))
if success:
if not success_expected:
sys.stderr.write(preamble + "trees unexpectedly match\n")
elif verbose >= DEBUG_STEPS:
sys.stderr.write(preamble + "trees matched as expected\n")
elif not success:
if not success_expected and verbose >= DEBUG_STEPS:
sys.stderr.write(preamble + "trees diverged as expected\n")
return success
def checkall(self):
"Check all named references - branches and tags - expecting matches."
for branch in cc.branches:
if branch.endswith("UNNAMED-BRANCH"):
if verbose > 0:
sys.stderr.write("%s: skipping %s\n" % (os.path.basename(sys.argv[0]), branch))
else:
cc.compare_tree("branch", branch)
for tag in cc.tags:
cc.compare_tree("tag", tag)
def command_returns(self, cmd, expected):
seen = capture_or_die(cmd)
succeeded = (seen.strip() == expected.strip())
if not succeeded:
sys.stderr.write(cmd + " return was not as expected\n")
def cleanup(self):
self.checkout.cleanup()
shutil.rmtree(self.stem+ConvertComparison.SUFFIX)
# End.
# Copy of testlifter.py ends here
if __name__ == '__main__':
import getopt
(opts, arguments) = getopt.getopt(sys.argv[1:], "k:npqv")
retain = True
engine_opts = "-F"
kexpand = ""
quiet = False
for (opt, arg) in opts:
if opt == '-v':
verbose += 1
elif opt == '-n':
retain = False
elif opt == '-p':
engine_opts += " -p"
elif opt == '-q':
engine_opts += " -q"
elif opt == '-k':
engine_opts += " -k " + arg
if not arguments:
sys.stderr.write("cvsconvert: requires a repo/module argument.\n")
sys.exit(1)
elif "/" in arguments[0]:
(repo, module) = arguments[0].split('/')
elif not os.path.isdir(arguments[0] + os.sep + "CVSROOT"):
(repo, module) = (arguments[0], None)
else:
candidates = [sub for sub in os.listdir(arguments[0]) if sub != "CVSROOT" and os.path.isdir(os.path.join(arguments[0], sub))]
if len(candidates) == 0:
sys.stderr.write("cvsconvert: no modules under %s.\n" % arguments[0])
sys.exit(1)
elif len(candidates) > 1:
sys.stderr.write("cvsconvert: choose one of %s\n" % candidates)
sys.exit(1)
else:
(repo, module) = (arguments[0], candidates[0])
sys.stderr.write("cvsconvert: processing %s/%s\n" % (repo, module))
if repo == module:
sys.stderr.write("cvsconvert: repo directory and module name cannot be the same.\n")
sys.exit(1)
if not os.path.exists(repo):
sys.stderr.write("cvsconvert: repo %s does not exist.\n" % repo)
sys.exit(1)
cc = ConvertComparison(stem=repo, repo=repo, module=module,
checkout=repo+".checkout",
options=engine_opts,
showdiffs= True)
if verbose == 0 and "-p" in engine_opts:
verbose = DEBUG_STEPS
cc.repo.retain = retain
cc.checkall()
cc.checkout.cleanup()
if retain:
sys.stderr.write("cvsconvert: conversion is in %s%s\n" % (repo, ConvertComparison.SUFFIX))
else:
cc.cleanup()
# end
|