From 3e2c88a5ace334deda5252bd3e36aacaab079a38 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 13 Nov 2010 10:16:46 -0500 Subject: [PATCH] No longer scribbles on $PWD. --- rcs-fast-import | 70 ++++++++++++++++++++++++++------------------- rcs-fast-import.xml | 6 ++-- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/rcs-fast-import b/rcs-fast-import index 7d390f7..0257ca5 100755 --- a/rcs-fast-import +++ b/rcs-fast-import @@ -724,36 +724,48 @@ if __name__ == '__main__': vcs = RCS() try: with Repository() as repo: - repo.fast_import(sys.stdin, progress=verbose>0) - repo.roundtrip = roundtrip - for event in repo.commits(): - vcs.precommit(event) - for op in event.fileops: - if op.op == "M": - if verbose: - announce("%5s M %s" % (event.mark, op.path)) - if op.mode == "160000": - complain("cannot represent a submodule link in RCS") + here = os.getcwd() + tempdir = "rcs-fast-import-" + `os.getpid()` + try: + try: + os.mkdir(tempdir) + os.chdir(tempdir) + except OSError: + raise FatalException("Couldn't create working directory.") + repo.fast_import(sys.stdin, progress=verbose>0) + repo.roundtrip = roundtrip + for event in repo.commits(): + vcs.precommit(event) + for op in event.fileops: + if op.op == "M": + if verbose: + announce("%5s M %s" % (event.mark, op.path)) + if op.mode == "160000": + complain("cannot represent a submodule link in RCS") + else: + vcs.modify(event, op.path, op.mode, op.copyname) + elif op.op in ("D", "deleteall"): + if verbose: + announce("%5s D %s" % (event.mark, op.path)) + if not dryrun: + vcs.remove(op.path) + elif op.op == "R": + if verbose: + announce("%5s R '%s' '%s'" % (event.mark, op.source, op.target)) + if not dryrun: + vcs.rename(event, op.source, op.target) + elif op.op == "C": + if verbose: + announce("%5s C '%s' '%s'" % (event.mark, op.source, op.target)) + if not dryrun: + vcs.copy(commit, ops.source, op.target) else: - vcs.modify(event, op.path, op.mode, op.copyname) - elif op.op in ("D", "deleteall"): - if verbose: - announce("%5s D %s" % (event.mark, op.path)) - if not dryrun: - vcs.remove(op.path) - elif op.op == "R": - if verbose: - announce("%5s R '%s' '%s'" % (event.mark, op.source, op.target)) - if not dryrun: - vcs.rename(event, op.source, op.target) - elif op.op == "C": - if verbose: - announce("%5s C '%s' '%s'" % (event.mark, op.source, op.target)) - if not dryrun: - vcs.copy(commit, ops.source, op.target) - else: - raise FatalException("unknown op type %s" % op.op) - vcs.postcommit(event) + raise FatalException("unknown op type %s" % op.op) + vcs.postcommit(event) + loud_rename("RCS", os.path.join(here, "RCS")) + os.chdir(here) + finally: + nuke(tempdir, "cleaning up") vcs.checkout(checkout_mode) raise SystemExit, 0 except FatalException, e: diff --git a/rcs-fast-import.xml b/rcs-fast-import.xml index 767d032..d1ff092 100644 --- a/rcs-fast-import.xml +++ b/rcs-fast-import.xml @@ -35,9 +35,9 @@ stdin into individual RCS master files in RCS subdirectories of the corresponding directory structure. -It is recommended that you run this in an empty directory, as it -will terminate with error rather than stepping on files that already -exist in the current directory. +It is recommended that you run this in an empty directory, as the +checkout of the RCS files may step on files that exist in the current +directory. Normally, committer and author data are written into each comment as RFC-822 mail headers, followed by a blank line. The -p option suppresses -- 2.43.0