]> thyrsus.com Git - rcs-fast-import.git/commitdiff
No longer scribbles on $PWD.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 13 Nov 2010 15:16:46 +0000 (10:16 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 13 Nov 2010 15:16:46 +0000 (10:16 -0500)
rcs-fast-import
rcs-fast-import.xml

index 7d390f7f21b5d92ac9c4251f9783e0af71ad00d0..0257ca508e08d87ab53659c77caea9490da95f4b 100755 (executable)
@@ -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:
index 767d03278f3006a8b04e401dacd7cb5002b6a23b..d1ff09227abe8e7637f78c2379f8f1b2fb9a77aa 100644 (file)
@@ -35,9 +35,9 @@
 stdin into individual RCS master files in RCS subdirectories of the
 corresponding directory structure.</para>
 
-<para>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.</para>
+<para>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.</para>
 
 <para>Normally, committer and author data are written into each comment as
 RFC-822 mail headers, followed by a blank line.  The -p option suppresses