From 97a3b35de853a6b1254b7ed056006a8cc85d89d1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 21 Nov 2010 10:26:04 -0500 Subject: [PATCH] Fix bugs caught by pychecker. --- Makefile | 5 +++++ rcs-fast-import | 30 ++++++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 05ae43b..218b63e 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,11 @@ rcs-fast-import-$(VERS).tar.gz: $(SOURCES) rcs-fast-import.1 (cd ..; tar -czvf rcs-fast-import/rcs-fast-import-$(VERS).tar.gz `cat rcs-fast-import/MANIFEST`) @(cd ..; rm rcs-fast-import-$(VERS)) +pychecker: + ln -f rcs-fast-import rcs-fast-import.py + pychecker --only --limit 50 rcs-fast-import.py + rm -f rcs-fast-import.py + version: @echo $(VERS) diff --git a/rcs-fast-import b/rcs-fast-import index 2f0dd57..3e42b53 100755 --- a/rcs-fast-import +++ b/rcs-fast-import @@ -26,8 +26,8 @@ The -V option displays the program version number and exits. -? displays this help and exits. """ -import sys, os, getopt, re, cStringIO, subprocess, shutil -import time, calendar, copy, shlex, email.message, email.utils +import sys, os, getopt, re, cStringIO, subprocess +import time, shlex, email.message, email.utils version="0.1" @@ -195,6 +195,7 @@ class FileOp: self.op = "deleteall" else: raise FatalException("unexpected fileop %s while parsing" % opline) + self.copyname = None class Commit: "Generic commit object." @@ -256,7 +257,7 @@ class Passthrough: def __init__(self, line): self.text = line -class FatalException: +class FatalException(Exception): "Unrecoverable error." def __init__(self, msg): self.msg = msg @@ -400,7 +401,7 @@ class Repository: if len(fields) < 3: self.error("malformed property line") elif len(fields) == 3: - self.properties[fields[1]] = True + commit.properties[fields[1]] = True else: name = fields[1] length = int(fields[2]) @@ -424,7 +425,7 @@ class Repository: elif line[0] in ("C", "D", "R"): commit.fileops.append(FileOp(line, commit)) elif line == "filedeleteall\n": - commit.fileops.append(FileOp("filedeleteall"), commit) + commit.fileops.append(FileOp("filedeleteall", commit)) elif line[0] == "M": fileop = FileOp(line, commit) if commit.mark is None: @@ -455,13 +456,6 @@ class Repository: # a commit subpart. continue else: - # Dodgy bzr autodetection hook... - if not self.vcs: - if "branch-nick" in commit.properties: - for vcs in vcstypes: - if vcs.name == "bzr": - self.vcs = vcs - break pushback(line) break if not (commit.mark and commit.committer): @@ -536,12 +530,12 @@ class Repository: def __setitem__(self, i, v): self.events[i] = v -def sanecheck(event, path, mode, copyfile): +def sanecheck(event, path, mode): "Sanity-check an operation to see if we can cope." if mode == "160000": - raise FatalException("ignoring a submodule link %s", path) + raise FatalException("cannot import submodule link %s", path) elif mode == "120000": - raise FatalException("ignoring a symlink %s", path) + raise FatalException("cannot import a symlink %s", path) if not mode[-3:] in ('644', '755'): raise FatalException("unknown mode %s on %s", (mode, path)) @@ -704,7 +698,7 @@ class Generic: self.maketag(reset.ref, str(rev), path) def modify(self, event, path, mode, copyfile): "Perform file checkins and modifications," - sanecheck(event, path, mode, copyfile) + sanecheck(event, path, mode) self.instantiate(path, copyfile) self.supercheckin(event, "M", path, "modify") #self.record("M", path) @@ -722,7 +716,7 @@ class Generic: "Mark a path deleted, but don't actually remove the master." self.instantiate(path) open(path, "w").close() - self.supercheckin(commit, "D", path, "delete") + self.supercheckin(commit, "D", path, legend) #self.record("D", path) def rename(self, commit, source, target): "Perform RCS renames, carrying history with the rename." @@ -825,7 +819,7 @@ if __name__ == '__main__': elif op.op == "C": if verbose >= DEBUG_OPS: announce("%5s C '%s' '%s'" % (event.mark, op.source, op.target)) - vcs.copy(commit, ops.source, op.target) + vcs.copy(event, op.source, op.target) else: raise FatalException("unknown op type %s" % op.op) vcs.postcommit(event) -- 2.43.0