Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bc49c8

Browse files
committed
Support for more general diffing and retrieving any old revision.
Support for index formatting with local refs.
1 parent 8cde0b4 commit 8bc49c8

2 files changed

Lines changed: 64 additions & 16 deletions

File tree

Tools/faqwiz/faqconf.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
SH_RLOG = RCSBINDIR + "rlog %(file)s </dev/null 2>&1"
7878
SH_RLOG_H = RCSBINDIR + "rlog -h %(file)s </dev/null 2>&1"
7979
SH_RDIFF = RCSBINDIR + "rcsdiff -r%(prev)s -r%(rev)s %(file)s </dev/null 2>&1"
80+
SH_REVISION = RCSBINDIR + "co -p%(rev)s %(file)s </dev/null 2>&1"
8081
SH_LOCK = RCSBINDIR + "rcs -l %(file)s </dev/null 2>&1"
8182
SH_CHECKIN = RCSBINDIR + "ci -u %(file)s <%(tfn)s 2>&1"
8283

@@ -91,6 +92,7 @@
9192
T_RECENT = "What's New in the " + FAQNAME
9293
T_SHOW = FAQNAME + " Entry"
9394
T_LOG = "RCS log for %s entry" % FAQNAME
95+
T_REVISION = "RCS revision for %s entry" % FAQNAME
9496
T_DIFF = "RCS diff for %s entry" % FAQNAME
9597
T_ADD = "Add an entry to the " + FAQNAME
9698
T_DELETE = "Deleting an entry from the " + FAQNAME
@@ -142,7 +144,7 @@
142144
/
143145
<INPUT TYPE=radio NAME=querytype VALUE=regex>
144146
Regular expression
145-
/
147+
/<BR>
146148
<INPUT TYPE=radio NAME=querytype VALUE=anykeywords>
147149
Keywords (any)
148150
/
@@ -197,11 +199,15 @@
197199
<LI><A HREF="%(FAQCGI)s?req=show&amp;file=%(file)s">%(title)s</A>
198200
"""
199201

202+
LOCAL_ENTRY = """\
203+
<LI><A HREF="#%(sec)s.%(num)s">%(title)s</A>
204+
"""
205+
200206
# Entry formatting
201207

202208
ENTRY_HEADER = """
203209
<HR>
204-
<H2>%(title)s</H2>
210+
<H2><A NAME="%(sec)s.%(num)s">%(title)s</A></H2>
205211
"""
206212

207213
ENTRY_FOOTER = """
@@ -240,8 +246,14 @@
240246
previous one.
241247
"""
242248

249+
REVISIONLINK = """\
250+
<A HREF="%(FAQCGI)s?req=revision&amp;file=%(file)s&amp;rev=%(rev)s"
251+
>%(line)s</A>\
252+
"""
243253
DIFFLINK = """\
244-
<A HREF="%(FAQCGI)s?req=diff&amp;file=%(file)s&amp;rev=%(rev)s">%(line)s</A>
254+
(<A HREF="%(FAQCGI)s?req=diff&amp;file=%(file)s&amp;\
255+
prev=%(prev)s&amp;rev=%(rev)s"
256+
>diff -r%(prev)s -r%(rev)s</A>)\
245257
"""
246258

247259
# Recently changed entries

Tools/faqwiz/faqwiz.py

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ def emphasize(line):
110110
emphasize_prog = regex.compile(pat)
111111
return regsub.gsub(emphasize_prog, '<I>\\1</I>', line)
112112

113+
revparse_prog = None
114+
115+
def revparse(rev):
116+
global revparse_prog
117+
if not revparse_prog:
118+
revparse_prog = regex.compile(
119+
'^\([1-9][0-9]?[0-9]?\)\.\([1-9][0-9]?[0-9]?[0-9]?\)$')
120+
if revparse_prog.match(rev) < 0:
121+
return None
122+
[major, minor] = map(string.atoi, revparse_prog.group(1, 2))
123+
return major, minor
124+
113125
def load_cookies():
114126
if not os.environ.has_key('HTTP_COOKIE'):
115127
return {}
@@ -440,12 +452,14 @@ def do_all(self):
440452
self.prologue(T_ALL)
441453
files = self.dir.list()
442454
self.last_changed(files)
455+
self.format_index(files, localrefs=1)
443456
self.format_all(files)
444457

445458
def do_compat(self):
446459
files = self.dir.list()
447460
emit(COMPAT)
448461
self.last_changed(files)
462+
self.format_index(files, localrefs=1)
449463
self.format_all(files, edit=0)
450464
sys.exit(0)
451465

@@ -483,7 +497,7 @@ def do_index(self):
483497
self.prologue(T_INDEX)
484498
self.format_index(self.dir.list(), add=1)
485499

486-
def format_index(self, files, add=0):
500+
def format_index(self, files, add=0, localrefs=0):
487501
sec = 0
488502
for file in files:
489503
try:
@@ -501,7 +515,10 @@ def format_index(self, files, add=0):
501515
except KeyError:
502516
title = "Untitled"
503517
emit(INDEX_SECTION, sec=sec, title=title)
504-
emit(INDEX_ENTRY, entry)
518+
if localrefs:
519+
emit(LOCAL_ENTRY, entry)
520+
else:
521+
emit(INDEX_ENTRY, entry)
505522
if sec:
506523
if add:
507524
emit(INDEX_ADDSECTION, sec=sec)
@@ -587,13 +604,23 @@ def rlog(self, command, entry=None):
587604
if line[:1] == '=' and len(line) >= 40 and \
588605
line == line[0]*len(line):
589606
del lines[-1]
607+
headrev = None
590608
for line in lines:
591609
if entry and athead and line[:9] == 'revision ':
592610
rev = string.strip(line[9:])
593-
if rev != '1.1':
594-
emit(DIFFLINK, entry, rev=rev, line=line)
595-
else:
611+
mami = revparse(rev)
612+
if not mami:
596613
print line
614+
else:
615+
emit(REVISIONLINK, entry, rev=rev, line=line)
616+
if mami[1] > 1:
617+
prev = "%d.%d" % (mami[0], mami[1]-1)
618+
emit(DIFFLINK, entry, prev=prev, rev=rev)
619+
if headrev:
620+
emit(DIFFLINK, entry, prev=rev, rev=headrev)
621+
else:
622+
headrev = rev
623+
print
597624
athead = 0
598625
else:
599626
athead = 0
@@ -605,18 +632,27 @@ def rlog(self, command, entry=None):
605632
print line
606633
print '</PRE>'
607634

635+
def do_revision(self):
636+
entry = self.dir.open(self.ui.file)
637+
rev = self.ui.rev
638+
mami = revparse(rev)
639+
if not mami:
640+
self.error("Invalid revision number: %s." % `rev`)
641+
self.prologue(T_REVISION, entry)
642+
self.shell(interpolate(SH_REVISION, entry, rev=rev))
643+
608644
def do_diff(self):
609645
entry = self.dir.open(self.ui.file)
646+
prev = self.ui.prev
610647
rev = self.ui.rev
611-
r = regex.compile(
612-
'^\([1-9][0-9]?[0-9]?\)\.\([1-9][0-9]?[0-9]?[0-9]?\)$')
613-
if r.match(rev) < 0:
648+
mami = revparse(rev)
649+
if not mami:
614650
self.error("Invalid revision number: %s." % `rev`)
615-
[major, minor] = map(string.atoi, r.group(1, 2))
616-
if minor == 1:
617-
self.error("No previous revision.")
618-
return
619-
prev = '%d.%d' % (major, minor-1)
651+
if prev:
652+
if not revparse(prev):
653+
self.error("Invalid previous revision number: %s." % `prev`)
654+
else:
655+
prev = '%d.%d' % (mami[0], mami[1])
620656
self.prologue(T_DIFF, entry)
621657
self.shell(interpolate(SH_RDIFF, entry, rev=rev, prev=prev))
622658

0 commit comments

Comments
 (0)