]> granicus.if.org Git - python/commitdiff
Support for more general diffing and retrieving any old revision.
authorGuido van Rossum <guido@python.org>
Mon, 26 May 1997 19:10:37 +0000 (19:10 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 26 May 1997 19:10:37 +0000 (19:10 +0000)
Support for index formatting with local refs.

Tools/faqwiz/faqconf.py
Tools/faqwiz/faqwiz.py

index 6013e3fd741e614f88467f1c18bc64a95ff8df6a..9c6048e7ba4b7d5b6d758dd1184f36474a722213 100644 (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
index 17a79d6ced96a8365a5ea59974ac0599a9ba4ed3..2b269c2ae1f06737ab2d28600f34a6ce7a5a0762 100644 (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,7 +515,10 @@ class FaqWizard:
                except KeyError:
                    title = "Untitled"
                emit(INDEX_SECTION, sec=sec, title=title)
-           emit(INDEX_ENTRY, entry)
+           if localrefs:
+               emit(LOCAL_ENTRY, entry)
+           else:
+               emit(INDEX_ENTRY, entry)
        if sec:
            if add:
                emit(INDEX_ADDSECTION, sec=sec)
@@ -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_revision(self):
+       entry = self.dir.open(self.ui.file)
+       rev = self.ui.rev
+       mami = revparse(rev)
+       if not mami:
+           self.error("Invalid revision number: %s." % `rev`)
+       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
-       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)
+       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))