def writeable(f):
return os.access(f, os.W_OK)
-def sccsfile(f):
+def sccsmaster(f):
return os.path.join("SCCS", "s." + f)
+def is_sccsmaster(f):
+ return os.path.basename(f).startswith("s.")
+
+def workfile(f):
+ assert os.path.basename(f).startswith("s.")
+ return os.path.basename(f)[2:]
+
+def rcsfile(f):
+ return os.path.join("RCS", f + ",v")
+
def progress(msg):
global logtext
msg = "sccs2rcs: " + msg
def die(msg):
print >>sys.stderr, "sccs2rcs: fatal error, ", msg
progress("error recovery begins")
- for filename in os.listdir("."):
- if os.path.exists(sccsfile(filename)) and writeable(filename):
- get_output("unget " + sccsfile(filename))
+ for master in os.listdir("SCCS"):
+ if is_sccsmaster(master):
+ get_output("unget " + master)
print >>sys.stderr, """\
Danger! Danger!
Incomplete history in ./RCS -- remove it.
os.environ["PATH"] += ":/usr/lib/cssc"
# Loop over every s-file in SCCS dir
- for sfile in filter(lambda f: f.startswith("s."), os.listdir("SCCS")):
- file = sfile[2:]
+ workfiles = []
+ for master in filter(lambda f: f.startswith("s."), os.listdir("SCCS")):
+ stem = master[2:]
firsttime = True
+ # These are the files we'll need to restore later
+ if os.path.exists(stem):
+ workfiles.append(stem)
+
# Extract a list of revisions from the master
revisions = []
try:
- for line in os.popen("prs " + sccsfile(file), "r"):
+ for line in os.popen("prs " + sccsmaster(stem), "r"):
if line.startswith("D "):
revisions.append(line.split()[1])
except OSError:
- die("open of master file %s failed" % sfile)
+ die("open of master file %s failed" % master)
except IndexError:
- die("garbled revision line in master file " + sfile)
+ die("garbled revision line in master file " + master)
revisions.reverse()
# Now use prs to run through the revision list extracting data
- progress("%s revisions: %s" % (file, ", ".join(revisions)))
+ progress("%s revisions: %s" % (stem, ", ".join(revisions)))
for rev in revisions:
- cmd = 'prs -d":Dd: :Dm: :Dy: :T: :P:" -r%s SCCS/s.%s' % (rev, file)
+ cmd = 'prs -d":Dd: :Dm: :Dy: :T: :P:" -r%s SCCS/s.%s' % (rev, stem)
date = get_output_or_die(cmd).strip()
try:
(day, month, year, tod, author) = date.split()
rcsdate = day + " " + months[int(month)] + " " + year + " " + tod
progress("==> file %s, rev=%s, date=%s, author=%s" \
- % (file, rev, rcsdate, author))
- get_output_or_die("get -e -r%s SCCS/s.%s" % (rev, file))
+ % (stem, rev, rcsdate, author))
+ get_output_or_die("get -e -r%s SCCS/s.%s" % (rev, stem))
progress("checked out of SCCS")
# replace SCCS keywords with RCS keywords
try:
- rfp = open(file, "r")
- filetext = rfp.read()
+ rfp = open(stem, "r")
+ stemtext = rfp.read()
rfp.close()
for (regexp, rcskey) in conversions:
- filetext = regexp.sub(rcskey, filetext)
- wfp = open(file, "w")
- wfp.write(filetext)
+ stemtext = regexp.sub(rcskey, stemtext)
+ wfp = open(stem, "w")
+ wfp.write(stemtext)
wfp.close()
except OSError:
die("keyword substitution failed")
# check file into RCS
if firsttime:
firsttime = False
- if file in initstrings:
+ if filename in initstrings:
cmd = 'ci -f -r%s -d"%s" -w%s -t-%s %s' \
- % (rev, rcsdate, author, initstrings[file], file)
+ % (rev, rcsdate, author, initstrings[filename], stem)
else:
if initstrings:
- warn("no description for %s in comments file" % file)
+ warn("no description for %s in comments file" % stem)
cmd = 'ci -f -r%s -d"%s" -w%s -t/dev/null %s' \
- % (rev, rcsdate, author, file)
+ % (rev, rcsdate, author, stem)
cmd = "echo 'Initial revision.' | " + cmd
get_output_or_die(cmd)
progress("initial checkin successful")
lckrev = ".".join(revparts[:-1])
if re.match(r"[0-9]+\."):
# need to lock the branch -- it is OK if the lock fails
- get_output("rcs -l%s %s" % (lckrev, file))
+ get_output("rcs -l%s %s" % (lckrev, stem))
progress("got branch lock")
else:
# need to lock the trunk -- must succeed
- get_output_or_die("rcs -l %s" % (file,))
+ get_output_or_die("rcs -l %s" % (stem,))
progress("got trunk lock")
# Extract the delta message for this revision
- deltamsg = get_output_or_die("prs -r$rev SCCS/s.$file")
+ deltamsg = get_output_or_die("prs -r$rev SCCS/s.%s" % stem)
deltalines = deltamsg.split("\n")
while deltalines:
deltalines.pop(0)
if deltalines[0].startswith("COMMENTS"):
break
deltamsg = deltalines.join("\n")
- cmd = 'ci -f -r%s -d"%s" -w%s %s' % (rev, date, author, file)
+ cmd = 'ci -f -r%s -d"%s" -w%s %s' % (rev, date, author, stem)
# FIXME: output of this command isn't logged
progress("$ " + cmd)
try:
except OSError:
die("RCS checkin of delta failed")
# We're done
- logtext += get_output_or_die("unget " + sccsfile(file))
+ logtext += get_output_or_die("unget " + sccsmaster(stem))
# Replace all files for which there exist SCCS masters,
- progress("replacing workfiles")
- for filename in os.listdir("."):
- if os.path.exists(sccsfile(filename)):
- os.remove(filename)
- os.system("co " + file)
+ progress("replacing workfiles...")
+ for filename in os.listdir("SCCS"):
+ if is_sccsmaster(master):
+ get_output("co " + rcsfile(workfile(master)))
progress("done.")
# sccs2rcs ends here