Support for more general diffing and retrieving any old revision.

Support for index formatting with local refs.
This commit is contained in:
Guido van Rossum 1997-05-26 19:10:37 +00:00
parent 8cde0b47b8
commit 8bc49c8ad1
2 changed files with 65 additions and 17 deletions

View File

@ -77,6 +77,7 @@ WIZVERSION = "0.3 (alpha)" # FAQ Wizard version
SH_RLOG = RCSBINDIR + "rlog %(file)s </dev/null 2>&1"
SH_RLOG_H = RCSBINDIR + "rlog -h %(file)s </dev/null 2>&1"
SH_RDIFF = RCSBINDIR + "rcsdiff -r%(prev)s -r%(rev)s %(file)s </dev/null 2>&1"
SH_REVISION = RCSBINDIR + "co -p%(rev)s %(file)s </dev/null 2>&1"
SH_LOCK = RCSBINDIR + "rcs -l %(file)s </dev/null 2>&1"
SH_CHECKIN = RCSBINDIR + "ci -u %(file)s <%(tfn)s 2>&1"
@ -91,6 +92,7 @@ T_SEARCH = FAQNAME + " Search Results"
T_RECENT = "What's New in the " + FAQNAME
T_SHOW = FAQNAME + " Entry"
T_LOG = "RCS log for %s entry" % FAQNAME
T_REVISION = "RCS revision for %s entry" % FAQNAME
T_DIFF = "RCS diff for %s entry" % FAQNAME
T_ADD = "Add an entry to the " + FAQNAME
T_DELETE = "Deleting an entry from the " + FAQNAME
@ -142,7 +144,7 @@ HOME = """
/
<INPUT TYPE=radio NAME=querytype VALUE=regex>
Regular expression
/
/<BR>
<INPUT TYPE=radio NAME=querytype VALUE=anykeywords>
Keywords (any)
/
@ -197,11 +199,15 @@ INDEX_ENTRY = """\
<LI><A HREF="%(FAQCGI)s?req=show&amp;file=%(file)s">%(title)s</A>
"""
LOCAL_ENTRY = """\
<LI><A HREF="#%(sec)s.%(num)s">%(title)s</A>
"""
# Entry formatting
ENTRY_HEADER = """
<HR>
<H2>%(title)s</H2>
<H2><A NAME="%(sec)s.%(num)s">%(title)s</A></H2>
"""
ENTRY_FOOTER = """
@ -240,8 +246,14 @@ Click on a revision line to see the diff between that revision and the
previous one.
"""
REVISIONLINK = """\
<A HREF="%(FAQCGI)s?req=revision&amp;file=%(file)s&amp;rev=%(rev)s"
>%(line)s</A>\
"""
DIFFLINK = """\
<A HREF="%(FAQCGI)s?req=diff&amp;file=%(file)s&amp;rev=%(rev)s">%(line)s</A>
(<A HREF="%(FAQCGI)s?req=diff&amp;file=%(file)s&amp;\
prev=%(prev)s&amp;rev=%(rev)s"
>diff -r%(prev)s -r%(rev)s</A>)\
"""
# Recently changed entries

View File

@ -110,6 +110,18 @@ def emphasize(line):
emphasize_prog = regex.compile(pat)
return regsub.gsub(emphasize_prog, '<I>\\1</I>', line)
revparse_prog = None
def revparse(rev):
global revparse_prog
if not revparse_prog:
revparse_prog = regex.compile(
'^\([1-9][0-9]?[0-9]?\)\.\([1-9][0-9]?[0-9]?[0-9]?\)$')
if revparse_prog.match(rev) < 0:
return None
[major, minor] = map(string.atoi, revparse_prog.group(1, 2))
return major, minor
def load_cookies():
if not os.environ.has_key('HTTP_COOKIE'):
return {}
@ -440,12 +452,14 @@ class FaqWizard:
self.prologue(T_ALL)
files = self.dir.list()
self.last_changed(files)
self.format_index(files, localrefs=1)
self.format_all(files)
def do_compat(self):
files = self.dir.list()
emit(COMPAT)
self.last_changed(files)
self.format_index(files, localrefs=1)
self.format_all(files, edit=0)
sys.exit(0)
@ -483,7 +497,7 @@ class FaqWizard:
self.prologue(T_INDEX)
self.format_index(self.dir.list(), add=1)
def format_index(self, files, add=0):
def format_index(self, files, add=0, localrefs=0):
sec = 0
for file in files:
try:
@ -501,6 +515,9 @@ class FaqWizard:
except KeyError:
title = "Untitled"
emit(INDEX_SECTION, sec=sec, title=title)
if localrefs:
emit(LOCAL_ENTRY, entry)
else:
emit(INDEX_ENTRY, entry)
if sec:
if add:
@ -587,13 +604,23 @@ class FaqWizard:
if line[:1] == '=' and len(line) >= 40 and \
line == line[0]*len(line):
del lines[-1]
headrev = None
for line in lines:
if entry and athead and line[:9] == 'revision ':
rev = string.strip(line[9:])
if rev != '1.1':
emit(DIFFLINK, entry, rev=rev, line=line)
else:
mami = revparse(rev)
if not mami:
print line
else:
emit(REVISIONLINK, entry, rev=rev, line=line)
if mami[1] > 1:
prev = "%d.%d" % (mami[0], mami[1]-1)
emit(DIFFLINK, entry, prev=prev, rev=rev)
if headrev:
emit(DIFFLINK, entry, prev=rev, rev=headrev)
else:
headrev = rev
print
athead = 0
else:
athead = 0
@ -605,18 +632,27 @@ class FaqWizard:
print line
print '</PRE>'
def do_diff(self):
def do_revision(self):
entry = self.dir.open(self.ui.file)
rev = self.ui.rev
r = regex.compile(
'^\([1-9][0-9]?[0-9]?\)\.\([1-9][0-9]?[0-9]?[0-9]?\)$')
if r.match(rev) < 0:
mami = revparse(rev)
if not mami:
self.error("Invalid revision number: %s." % `rev`)
[major, minor] = map(string.atoi, r.group(1, 2))
if minor == 1:
self.error("No previous revision.")
return
prev = '%d.%d' % (major, minor-1)
self.prologue(T_REVISION, entry)
self.shell(interpolate(SH_REVISION, entry, rev=rev))
def do_diff(self):
entry = self.dir.open(self.ui.file)
prev = self.ui.prev
rev = self.ui.rev
mami = revparse(rev)
if not mami:
self.error("Invalid revision number: %s." % `rev`)
if prev:
if not revparse(prev):
self.error("Invalid previous revision number: %s." % `prev`)
else:
prev = '%d.%d' % (mami[0], mami[1])
self.prologue(T_DIFF, entry)
self.shell(interpolate(SH_RDIFF, entry, rev=rev, prev=prev))