mirror of
https://github.com/vitalif/viewvc-4intranet
synced 2019-04-16 04:14:59 +03:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
874d43c2e1 |
22
CHANGES
22
CHANGES
@@ -1,25 +1,3 @@
|
|||||||
Version 0.9.4 (released 17-Aug-2005)
|
|
||||||
|
|
||||||
* security fix: omit forbidden/hidden modules from query results.
|
|
||||||
|
|
||||||
Version 0.9.3 (released 17-May-2005)
|
|
||||||
|
|
||||||
* security fix: disallow bad "content-type" input [CAN-2004-1062]
|
|
||||||
* security fix: disallow bad "sortby" and "cvsroot" input [CAN-2002-0771]
|
|
||||||
* security fix: omit forbidden/hidden modules from tarballs [CAN-2004-0915]
|
|
||||||
|
|
||||||
Version 0.9.2 (released 15-Jan-2001)
|
|
||||||
|
|
||||||
* fix redirects to Attic for diffs
|
|
||||||
* fix diffs that have no changes (causing an infinite loop)
|
|
||||||
|
|
||||||
Version 0.9.1 (released 26-Dec-2001)
|
|
||||||
|
|
||||||
* fix a problem with some syntax in ndiff.py which isn't compatible
|
|
||||||
with Python 1.5.2 (causing problems at install time)
|
|
||||||
* remove a debug statement left in the code which continues to
|
|
||||||
append lines to /tmp/log
|
|
||||||
|
|
||||||
Version 0.9 (released 23-Dec-2001)
|
Version 0.9 (released 23-Dec-2001)
|
||||||
|
|
||||||
* create templates for the rest of the pages: markup pages, graphs,
|
* create templates for the rest of the pages: markup pages, graphs,
|
||||||
|
786
lib/difflib.py
786
lib/difflib.py
@@ -1,786 +0,0 @@
|
|||||||
#! /usr/bin/env python
|
|
||||||
# Backported to Python 1.5.2 for the ViewCVS project by pf@artcom-gmbh.de
|
|
||||||
# 24-Dec-2001, original version "stolen" from Python-2.1.1
|
|
||||||
"""
|
|
||||||
Module difflib -- helpers for computing deltas between objects.
|
|
||||||
|
|
||||||
Function get_close_matches(word, possibilities, n=3, cutoff=0.6):
|
|
||||||
|
|
||||||
Use SequenceMatcher to return list of the best "good enough" matches.
|
|
||||||
|
|
||||||
word is a sequence for which close matches are desired (typically a
|
|
||||||
string).
|
|
||||||
|
|
||||||
possibilities is a list of sequences against which to match word
|
|
||||||
(typically a list of strings).
|
|
||||||
|
|
||||||
Optional arg n (default 3) is the maximum number of close matches to
|
|
||||||
return. n must be > 0.
|
|
||||||
|
|
||||||
Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities
|
|
||||||
that don't score at least that similar to word are ignored.
|
|
||||||
|
|
||||||
The best (no more than n) matches among the possibilities are returned
|
|
||||||
in a list, sorted by similarity score, most similar first.
|
|
||||||
|
|
||||||
>>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
|
|
||||||
['apple', 'ape']
|
|
||||||
>>> import keyword
|
|
||||||
>>> get_close_matches("wheel", keyword.kwlist)
|
|
||||||
['while']
|
|
||||||
>>> get_close_matches("apple", keyword.kwlist)
|
|
||||||
[]
|
|
||||||
>>> get_close_matches("accept", keyword.kwlist)
|
|
||||||
['except']
|
|
||||||
|
|
||||||
Class SequenceMatcher
|
|
||||||
|
|
||||||
SequenceMatcher is a flexible class for comparing pairs of sequences of any
|
|
||||||
type, so long as the sequence elements are hashable. The basic algorithm
|
|
||||||
predates, and is a little fancier than, an algorithm published in the late
|
|
||||||
1980's by Ratcliff and Obershelp under the hyperbolic name "gestalt pattern
|
|
||||||
matching". The basic idea is to find the longest contiguous matching
|
|
||||||
subsequence that contains no "junk" elements (R-O doesn't address junk).
|
|
||||||
The same idea is then applied recursively to the pieces of the sequences to
|
|
||||||
the left and to the right of the matching subsequence. This does not yield
|
|
||||||
minimal edit sequences, but does tend to yield matches that "look right"
|
|
||||||
to people.
|
|
||||||
|
|
||||||
Example, comparing two strings, and considering blanks to be "junk":
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(lambda x: x == " ",
|
|
||||||
... "private Thread currentThread;",
|
|
||||||
... "private volatile Thread currentThread;")
|
|
||||||
>>>
|
|
||||||
|
|
||||||
.ratio() returns a float in [0, 1], measuring the "similarity" of the
|
|
||||||
sequences. As a rule of thumb, a .ratio() value over 0.6 means the
|
|
||||||
sequences are close matches:
|
|
||||||
|
|
||||||
>>> print round(s.ratio(), 3)
|
|
||||||
0.866
|
|
||||||
>>>
|
|
||||||
|
|
||||||
If you're only interested in where the sequences match,
|
|
||||||
.get_matching_blocks() is handy:
|
|
||||||
|
|
||||||
>>> for block in s.get_matching_blocks():
|
|
||||||
... print "a[%d] and b[%d] match for %d elements" % block
|
|
||||||
a[0] and b[0] match for 8 elements
|
|
||||||
a[8] and b[17] match for 6 elements
|
|
||||||
a[14] and b[23] match for 15 elements
|
|
||||||
a[29] and b[38] match for 0 elements
|
|
||||||
|
|
||||||
Note that the last tuple returned by .get_matching_blocks() is always a
|
|
||||||
dummy, (len(a), len(b), 0), and this is the only case in which the last
|
|
||||||
tuple element (number of elements matched) is 0.
|
|
||||||
|
|
||||||
If you want to know how to change the first sequence into the second, use
|
|
||||||
.get_opcodes():
|
|
||||||
|
|
||||||
>>> for opcode in s.get_opcodes():
|
|
||||||
... print "%6s a[%d:%d] b[%d:%d]" % opcode
|
|
||||||
equal a[0:8] b[0:8]
|
|
||||||
insert a[8:8] b[8:17]
|
|
||||||
equal a[8:14] b[17:23]
|
|
||||||
equal a[14:29] b[23:38]
|
|
||||||
|
|
||||||
See Tools/scripts/ndiff.py for a fancy human-friendly file differencer,
|
|
||||||
which uses SequenceMatcher both to view files as sequences of lines, and
|
|
||||||
lines as sequences of characters.
|
|
||||||
|
|
||||||
See also function get_close_matches() in this module, which shows how
|
|
||||||
simple code building on SequenceMatcher can be used to do useful work.
|
|
||||||
|
|
||||||
Timing: Basic R-O is cubic time worst case and quadratic time expected
|
|
||||||
case. SequenceMatcher is quadratic time for the worst case and has
|
|
||||||
expected-case behavior dependent in a complicated way on how many
|
|
||||||
elements the sequences have in common; best case time is linear.
|
|
||||||
|
|
||||||
SequenceMatcher methods:
|
|
||||||
|
|
||||||
__init__(isjunk=None, a='', b='')
|
|
||||||
Construct a SequenceMatcher.
|
|
||||||
|
|
||||||
Optional arg isjunk is None (the default), or a one-argument function
|
|
||||||
that takes a sequence element and returns true iff the element is junk.
|
|
||||||
None is equivalent to passing "lambda x: 0", i.e. no elements are
|
|
||||||
considered to be junk. For example, pass
|
|
||||||
lambda x: x in " \\t"
|
|
||||||
if you're comparing lines as sequences of characters, and don't want to
|
|
||||||
synch up on blanks or hard tabs.
|
|
||||||
|
|
||||||
Optional arg a is the first of two sequences to be compared. By
|
|
||||||
default, an empty string. The elements of a must be hashable.
|
|
||||||
|
|
||||||
Optional arg b is the second of two sequences to be compared. By
|
|
||||||
default, an empty string. The elements of b must be hashable.
|
|
||||||
|
|
||||||
set_seqs(a, b)
|
|
||||||
Set the two sequences to be compared.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher()
|
|
||||||
>>> s.set_seqs("abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
|
|
||||||
set_seq1(a)
|
|
||||||
Set the first sequence to be compared.
|
|
||||||
|
|
||||||
The second sequence to be compared is not changed.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.set_seq1("bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
1.0
|
|
||||||
>>>
|
|
||||||
|
|
||||||
SequenceMatcher computes and caches detailed information about the
|
|
||||||
second sequence, so if you want to compare one sequence S against many
|
|
||||||
sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for
|
|
||||||
each of the other sequences.
|
|
||||||
|
|
||||||
See also set_seqs() and set_seq2().
|
|
||||||
|
|
||||||
set_seq2(b)
|
|
||||||
Set the second sequence to be compared.
|
|
||||||
|
|
||||||
The first sequence to be compared is not changed.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.set_seq2("abcd")
|
|
||||||
>>> s.ratio()
|
|
||||||
1.0
|
|
||||||
>>>
|
|
||||||
|
|
||||||
SequenceMatcher computes and caches detailed information about the
|
|
||||||
second sequence, so if you want to compare one sequence S against many
|
|
||||||
sequences, use .set_seq2(S) once and call .set_seq1(x) repeatedly for
|
|
||||||
each of the other sequences.
|
|
||||||
|
|
||||||
See also set_seqs() and set_seq1().
|
|
||||||
|
|
||||||
find_longest_match(alo, ahi, blo, bhi)
|
|
||||||
Find longest matching block in a[alo:ahi] and b[blo:bhi].
|
|
||||||
|
|
||||||
If isjunk is not defined:
|
|
||||||
|
|
||||||
Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
|
|
||||||
alo <= i <= i+k <= ahi
|
|
||||||
blo <= j <= j+k <= bhi
|
|
||||||
and for all (i',j',k') meeting those conditions,
|
|
||||||
k >= k'
|
|
||||||
i <= i'
|
|
||||||
and if i == i', j <= j'
|
|
||||||
|
|
||||||
In other words, of all maximal matching blocks, return one that starts
|
|
||||||
earliest in a, and of all those maximal matching blocks that start
|
|
||||||
earliest in a, return the one that starts earliest in b.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, " abcd", "abcd abcd")
|
|
||||||
>>> s.find_longest_match(0, 5, 0, 9)
|
|
||||||
(0, 4, 5)
|
|
||||||
|
|
||||||
If isjunk is defined, first the longest matching block is determined as
|
|
||||||
above, but with the additional restriction that no junk element appears
|
|
||||||
in the block. Then that block is extended as far as possible by
|
|
||||||
matching (only) junk elements on both sides. So the resulting block
|
|
||||||
never matches on junk except as identical junk happens to be adjacent
|
|
||||||
to an "interesting" match.
|
|
||||||
|
|
||||||
Here's the same example as before, but considering blanks to be junk.
|
|
||||||
That prevents " abcd" from matching the " abcd" at the tail end of the
|
|
||||||
second sequence directly. Instead only the "abcd" can match, and
|
|
||||||
matches the leftmost "abcd" in the second sequence:
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
|
|
||||||
>>> s.find_longest_match(0, 5, 0, 9)
|
|
||||||
(1, 0, 4)
|
|
||||||
|
|
||||||
If no blocks match, return (alo, blo, 0).
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "ab", "c")
|
|
||||||
>>> s.find_longest_match(0, 2, 0, 1)
|
|
||||||
(0, 0, 0)
|
|
||||||
|
|
||||||
get_matching_blocks()
|
|
||||||
Return list of triples describing matching subsequences.
|
|
||||||
|
|
||||||
Each triple is of the form (i, j, n), and means that
|
|
||||||
a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in i
|
|
||||||
and in j.
|
|
||||||
|
|
||||||
The last triple is a dummy, (len(a), len(b), 0), and is the only triple
|
|
||||||
with n==0.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abxcd", "abcd")
|
|
||||||
>>> s.get_matching_blocks()
|
|
||||||
[(0, 0, 2), (3, 2, 2), (5, 4, 0)]
|
|
||||||
|
|
||||||
get_opcodes()
|
|
||||||
Return list of 5-tuples describing how to turn a into b.
|
|
||||||
|
|
||||||
Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple has
|
|
||||||
i1 == j1 == 0, and remaining tuples have i1 == the i2 from the tuple
|
|
||||||
preceding it, and likewise for j1 == the previous j2.
|
|
||||||
|
|
||||||
The tags are strings, with these meanings:
|
|
||||||
|
|
||||||
'replace': a[i1:i2] should be replaced by b[j1:j2]
|
|
||||||
'delete': a[i1:i2] should be deleted.
|
|
||||||
Note that j1==j2 in this case.
|
|
||||||
'insert': b[j1:j2] should be inserted at a[i1:i1].
|
|
||||||
Note that i1==i2 in this case.
|
|
||||||
'equal': a[i1:i2] == b[j1:j2]
|
|
||||||
|
|
||||||
>>> a = "qabxcd"
|
|
||||||
>>> b = "abycdf"
|
|
||||||
>>> s = SequenceMatcher(None, a, b)
|
|
||||||
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
|
|
||||||
... print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
|
|
||||||
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
|
|
||||||
delete a[0:1] (q) b[0:0] ()
|
|
||||||
equal a[1:3] (ab) b[0:2] (ab)
|
|
||||||
replace a[3:4] (x) b[2:3] (y)
|
|
||||||
equal a[4:6] (cd) b[3:5] (cd)
|
|
||||||
insert a[6:6] () b[5:6] (f)
|
|
||||||
|
|
||||||
ratio()
|
|
||||||
Return a measure of the sequences' similarity (float in [0,1]).
|
|
||||||
|
|
||||||
Where T is the total number of elements in both sequences, and M is the
|
|
||||||
number of matches, this is 2,0*M / T. Note that this is 1 if the
|
|
||||||
sequences are identical, and 0 if they have nothing in common.
|
|
||||||
|
|
||||||
.ratio() is expensive to compute if you haven't already computed
|
|
||||||
.get_matching_blocks() or .get_opcodes(), in which case you may want to
|
|
||||||
try .quick_ratio() or .real_quick_ratio() first to get an upper bound.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.quick_ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.real_quick_ratio()
|
|
||||||
1.0
|
|
||||||
|
|
||||||
quick_ratio()
|
|
||||||
Return an upper bound on .ratio() relatively quickly.
|
|
||||||
|
|
||||||
This isn't defined beyond that it is an upper bound on .ratio(), and
|
|
||||||
is faster to compute.
|
|
||||||
|
|
||||||
real_quick_ratio():
|
|
||||||
Return an upper bound on ratio() very quickly.
|
|
||||||
|
|
||||||
This isn't defined beyond that it is an upper bound on .ratio(), and
|
|
||||||
is faster to compute than either .ratio() or .quick_ratio().
|
|
||||||
"""
|
|
||||||
|
|
||||||
TRACE = 0
|
|
||||||
|
|
||||||
class SequenceMatcher:
|
|
||||||
def __init__(self, isjunk=None, a='', b=''):
|
|
||||||
"""Construct a SequenceMatcher.
|
|
||||||
|
|
||||||
Optional arg isjunk is None (the default), or a one-argument
|
|
||||||
function that takes a sequence element and returns true iff the
|
|
||||||
element is junk. None is equivalent to passing "lambda x: 0", i.e.
|
|
||||||
no elements are considered to be junk. For example, pass
|
|
||||||
lambda x: x in " \\t"
|
|
||||||
if you're comparing lines as sequences of characters, and don't
|
|
||||||
want to synch up on blanks or hard tabs.
|
|
||||||
|
|
||||||
Optional arg a is the first of two sequences to be compared. By
|
|
||||||
default, an empty string. The elements of a must be hashable. See
|
|
||||||
also .set_seqs() and .set_seq1().
|
|
||||||
|
|
||||||
Optional arg b is the second of two sequences to be compared. By
|
|
||||||
default, an empty string. The elements of b must be hashable. See
|
|
||||||
also .set_seqs() and .set_seq2().
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Members:
|
|
||||||
# a
|
|
||||||
# first sequence
|
|
||||||
# b
|
|
||||||
# second sequence; differences are computed as "what do
|
|
||||||
# we need to do to 'a' to change it into 'b'?"
|
|
||||||
# b2j
|
|
||||||
# for x in b, b2j[x] is a list of the indices (into b)
|
|
||||||
# at which x appears; junk elements do not appear
|
|
||||||
# b2jhas
|
|
||||||
# b2j.has_key
|
|
||||||
# fullbcount
|
|
||||||
# for x in b, fullbcount[x] == the number of times x
|
|
||||||
# appears in b; only materialized if really needed (used
|
|
||||||
# only for computing quick_ratio())
|
|
||||||
# matching_blocks
|
|
||||||
# a list of (i, j, k) triples, where a[i:i+k] == b[j:j+k];
|
|
||||||
# ascending & non-overlapping in i and in j; terminated by
|
|
||||||
# a dummy (len(a), len(b), 0) sentinel
|
|
||||||
# opcodes
|
|
||||||
# a list of (tag, i1, i2, j1, j2) tuples, where tag is
|
|
||||||
# one of
|
|
||||||
# 'replace' a[i1:i2] should be replaced by b[j1:j2]
|
|
||||||
# 'delete' a[i1:i2] should be deleted
|
|
||||||
# 'insert' b[j1:j2] should be inserted
|
|
||||||
# 'equal' a[i1:i2] == b[j1:j2]
|
|
||||||
# isjunk
|
|
||||||
# a user-supplied function taking a sequence element and
|
|
||||||
# returning true iff the element is "junk" -- this has
|
|
||||||
# subtle but helpful effects on the algorithm, which I'll
|
|
||||||
# get around to writing up someday <0.9 wink>.
|
|
||||||
# DON'T USE! Only __chain_b uses this. Use isbjunk.
|
|
||||||
# isbjunk
|
|
||||||
# for x in b, isbjunk(x) == isjunk(x) but much faster;
|
|
||||||
# it's really the has_key method of a hidden dict.
|
|
||||||
# DOES NOT WORK for x in a!
|
|
||||||
|
|
||||||
self.isjunk = isjunk
|
|
||||||
self.a = self.b = None
|
|
||||||
self.set_seqs(a, b)
|
|
||||||
|
|
||||||
def set_seqs(self, a, b):
|
|
||||||
"""Set the two sequences to be compared.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher()
|
|
||||||
>>> s.set_seqs("abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.set_seq1(a)
|
|
||||||
self.set_seq2(b)
|
|
||||||
|
|
||||||
def set_seq1(self, a):
|
|
||||||
"""Set the first sequence to be compared.
|
|
||||||
|
|
||||||
The second sequence to be compared is not changed.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.set_seq1("bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
1.0
|
|
||||||
>>>
|
|
||||||
|
|
||||||
SequenceMatcher computes and caches detailed information about the
|
|
||||||
second sequence, so if you want to compare one sequence S against
|
|
||||||
many sequences, use .set_seq2(S) once and call .set_seq1(x)
|
|
||||||
repeatedly for each of the other sequences.
|
|
||||||
|
|
||||||
See also set_seqs() and set_seq2().
|
|
||||||
"""
|
|
||||||
|
|
||||||
if a is self.a:
|
|
||||||
return
|
|
||||||
self.a = a
|
|
||||||
self.matching_blocks = self.opcodes = None
|
|
||||||
|
|
||||||
def set_seq2(self, b):
|
|
||||||
"""Set the second sequence to be compared.
|
|
||||||
|
|
||||||
The first sequence to be compared is not changed.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.set_seq2("abcd")
|
|
||||||
>>> s.ratio()
|
|
||||||
1.0
|
|
||||||
>>>
|
|
||||||
|
|
||||||
SequenceMatcher computes and caches detailed information about the
|
|
||||||
second sequence, so if you want to compare one sequence S against
|
|
||||||
many sequences, use .set_seq2(S) once and call .set_seq1(x)
|
|
||||||
repeatedly for each of the other sequences.
|
|
||||||
|
|
||||||
See also set_seqs() and set_seq1().
|
|
||||||
"""
|
|
||||||
|
|
||||||
if b is self.b:
|
|
||||||
return
|
|
||||||
self.b = b
|
|
||||||
self.matching_blocks = self.opcodes = None
|
|
||||||
self.fullbcount = None
|
|
||||||
self.__chain_b()
|
|
||||||
|
|
||||||
# For each element x in b, set b2j[x] to a list of the indices in
|
|
||||||
# b where x appears; the indices are in increasing order; note that
|
|
||||||
# the number of times x appears in b is len(b2j[x]) ...
|
|
||||||
# when self.isjunk is defined, junk elements don't show up in this
|
|
||||||
# map at all, which stops the central find_longest_match method
|
|
||||||
# from starting any matching block at a junk element ...
|
|
||||||
# also creates the fast isbjunk function ...
|
|
||||||
# note that this is only called when b changes; so for cross-product
|
|
||||||
# kinds of matches, it's best to call set_seq2 once, then set_seq1
|
|
||||||
# repeatedly
|
|
||||||
|
|
||||||
def __chain_b(self):
|
|
||||||
# Because isjunk is a user-defined (not C) function, and we test
|
|
||||||
# for junk a LOT, it's important to minimize the number of calls.
|
|
||||||
# Before the tricks described here, __chain_b was by far the most
|
|
||||||
# time-consuming routine in the whole module! If anyone sees
|
|
||||||
# Jim Roskind, thank him again for profile.py -- I never would
|
|
||||||
# have guessed that.
|
|
||||||
# The first trick is to build b2j ignoring the possibility
|
|
||||||
# of junk. I.e., we don't call isjunk at all yet. Throwing
|
|
||||||
# out the junk later is much cheaper than building b2j "right"
|
|
||||||
# from the start.
|
|
||||||
b = self.b
|
|
||||||
self.b2j = b2j = {}
|
|
||||||
self.b2jhas = b2jhas = b2j.has_key
|
|
||||||
for i in xrange(len(b)):
|
|
||||||
elt = b[i]
|
|
||||||
if b2jhas(elt):
|
|
||||||
b2j[elt].append(i)
|
|
||||||
else:
|
|
||||||
b2j[elt] = [i]
|
|
||||||
|
|
||||||
# Now b2j.keys() contains elements uniquely, and especially when
|
|
||||||
# the sequence is a string, that's usually a good deal smaller
|
|
||||||
# than len(string). The difference is the number of isjunk calls
|
|
||||||
# saved.
|
|
||||||
isjunk, junkdict = self.isjunk, {}
|
|
||||||
if isjunk:
|
|
||||||
for elt in b2j.keys():
|
|
||||||
if isjunk(elt):
|
|
||||||
junkdict[elt] = 1 # value irrelevant; it's a set
|
|
||||||
del b2j[elt]
|
|
||||||
|
|
||||||
# Now for x in b, isjunk(x) == junkdict.has_key(x), but the
|
|
||||||
# latter is much faster. Note too that while there may be a
|
|
||||||
# lot of junk in the sequence, the number of *unique* junk
|
|
||||||
# elements is probably small. So the memory burden of keeping
|
|
||||||
# this dict alive is likely trivial compared to the size of b2j.
|
|
||||||
self.isbjunk = junkdict.has_key
|
|
||||||
|
|
||||||
def find_longest_match(self, alo, ahi, blo, bhi):
|
|
||||||
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
|
|
||||||
|
|
||||||
If isjunk is not defined:
|
|
||||||
|
|
||||||
Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
|
|
||||||
alo <= i <= i+k <= ahi
|
|
||||||
blo <= j <= j+k <= bhi
|
|
||||||
and for all (i',j',k') meeting those conditions,
|
|
||||||
k >= k'
|
|
||||||
i <= i'
|
|
||||||
and if i == i', j <= j'
|
|
||||||
|
|
||||||
In other words, of all maximal matching blocks, return one that
|
|
||||||
starts earliest in a, and of all those maximal matching blocks that
|
|
||||||
start earliest in a, return the one that starts earliest in b.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, " abcd", "abcd abcd")
|
|
||||||
>>> s.find_longest_match(0, 5, 0, 9)
|
|
||||||
(0, 4, 5)
|
|
||||||
|
|
||||||
If isjunk is defined, first the longest matching block is
|
|
||||||
determined as above, but with the additional restriction that no
|
|
||||||
junk element appears in the block. Then that block is extended as
|
|
||||||
far as possible by matching (only) junk elements on both sides. So
|
|
||||||
the resulting block never matches on junk except as identical junk
|
|
||||||
happens to be adjacent to an "interesting" match.
|
|
||||||
|
|
||||||
Here's the same example as before, but considering blanks to be
|
|
||||||
junk. That prevents " abcd" from matching the " abcd" at the tail
|
|
||||||
end of the second sequence directly. Instead only the "abcd" can
|
|
||||||
match, and matches the leftmost "abcd" in the second sequence:
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
|
|
||||||
>>> s.find_longest_match(0, 5, 0, 9)
|
|
||||||
(1, 0, 4)
|
|
||||||
|
|
||||||
If no blocks match, return (alo, blo, 0).
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "ab", "c")
|
|
||||||
>>> s.find_longest_match(0, 2, 0, 1)
|
|
||||||
(0, 0, 0)
|
|
||||||
"""
|
|
||||||
|
|
||||||
# CAUTION: stripping common prefix or suffix would be incorrect.
|
|
||||||
# E.g.,
|
|
||||||
# ab
|
|
||||||
# acab
|
|
||||||
# Longest matching block is "ab", but if common prefix is
|
|
||||||
# stripped, it's "a" (tied with "b"). UNIX(tm) diff does so
|
|
||||||
# strip, so ends up claiming that ab is changed to acab by
|
|
||||||
# inserting "ca" in the middle. That's minimal but unintuitive:
|
|
||||||
# "it's obvious" that someone inserted "ac" at the front.
|
|
||||||
# Windiff ends up at the same place as diff, but by pairing up
|
|
||||||
# the unique 'b's and then matching the first two 'a's.
|
|
||||||
|
|
||||||
a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.isbjunk
|
|
||||||
besti, bestj, bestsize = alo, blo, 0
|
|
||||||
# find longest junk-free match
|
|
||||||
# during an iteration of the loop, j2len[j] = length of longest
|
|
||||||
# junk-free match ending with a[i-1] and b[j]
|
|
||||||
j2len = {}
|
|
||||||
nothing = []
|
|
||||||
for i in xrange(alo, ahi):
|
|
||||||
# look at all instances of a[i] in b; note that because
|
|
||||||
# b2j has no junk keys, the loop is skipped if a[i] is junk
|
|
||||||
j2lenget = j2len.get
|
|
||||||
newj2len = {}
|
|
||||||
for j in b2j.get(a[i], nothing):
|
|
||||||
# a[i] matches b[j]
|
|
||||||
if j < blo:
|
|
||||||
continue
|
|
||||||
if j >= bhi:
|
|
||||||
break
|
|
||||||
k = newj2len[j] = j2lenget(j-1, 0) + 1
|
|
||||||
if k > bestsize:
|
|
||||||
besti, bestj, bestsize = i-k+1, j-k+1, k
|
|
||||||
j2len = newj2len
|
|
||||||
|
|
||||||
# Now that we have a wholly interesting match (albeit possibly
|
|
||||||
# empty!), we may as well suck up the matching junk on each
|
|
||||||
# side of it too. Can't think of a good reason not to, and it
|
|
||||||
# saves post-processing the (possibly considerable) expense of
|
|
||||||
# figuring out what to do with it. In the case of an empty
|
|
||||||
# interesting match, this is clearly the right thing to do,
|
|
||||||
# because no other kind of match is possible in the regions.
|
|
||||||
while besti > alo and bestj > blo and \
|
|
||||||
isbjunk(b[bestj-1]) and \
|
|
||||||
a[besti-1] == b[bestj-1]:
|
|
||||||
besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
|
|
||||||
while besti+bestsize < ahi and bestj+bestsize < bhi and \
|
|
||||||
isbjunk(b[bestj+bestsize]) and \
|
|
||||||
a[besti+bestsize] == b[bestj+bestsize]:
|
|
||||||
bestsize = bestsize + 1
|
|
||||||
|
|
||||||
if TRACE:
|
|
||||||
print "get_matching_blocks", alo, ahi, blo, bhi
|
|
||||||
print " returns", besti, bestj, bestsize
|
|
||||||
return besti, bestj, bestsize
|
|
||||||
|
|
||||||
def get_matching_blocks(self):
|
|
||||||
"""Return list of triples describing matching subsequences.
|
|
||||||
|
|
||||||
Each triple is of the form (i, j, n), and means that
|
|
||||||
a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in
|
|
||||||
i and in j.
|
|
||||||
|
|
||||||
The last triple is a dummy, (len(a), len(b), 0), and is the only
|
|
||||||
triple with n==0.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abxcd", "abcd")
|
|
||||||
>>> s.get_matching_blocks()
|
|
||||||
[(0, 0, 2), (3, 2, 2), (5, 4, 0)]
|
|
||||||
"""
|
|
||||||
|
|
||||||
if self.matching_blocks is not None:
|
|
||||||
return self.matching_blocks
|
|
||||||
self.matching_blocks = []
|
|
||||||
la, lb = len(self.a), len(self.b)
|
|
||||||
self.__helper(0, la, 0, lb, self.matching_blocks)
|
|
||||||
self.matching_blocks.append( (la, lb, 0) )
|
|
||||||
if TRACE:
|
|
||||||
print '*** matching blocks', self.matching_blocks
|
|
||||||
return self.matching_blocks
|
|
||||||
|
|
||||||
# builds list of matching blocks covering a[alo:ahi] and
|
|
||||||
# b[blo:bhi], appending them in increasing order to answer
|
|
||||||
|
|
||||||
def __helper(self, alo, ahi, blo, bhi, answer):
|
|
||||||
i, j, k = x = self.find_longest_match(alo, ahi, blo, bhi)
|
|
||||||
# a[alo:i] vs b[blo:j] unknown
|
|
||||||
# a[i:i+k] same as b[j:j+k]
|
|
||||||
# a[i+k:ahi] vs b[j+k:bhi] unknown
|
|
||||||
if k:
|
|
||||||
if alo < i and blo < j:
|
|
||||||
self.__helper(alo, i, blo, j, answer)
|
|
||||||
answer.append(x)
|
|
||||||
if i+k < ahi and j+k < bhi:
|
|
||||||
self.__helper(i+k, ahi, j+k, bhi, answer)
|
|
||||||
|
|
||||||
def get_opcodes(self):
|
|
||||||
"""Return list of 5-tuples describing how to turn a into b.
|
|
||||||
|
|
||||||
Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
|
|
||||||
has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
|
|
||||||
tuple preceding it, and likewise for j1 == the previous j2.
|
|
||||||
|
|
||||||
The tags are strings, with these meanings:
|
|
||||||
|
|
||||||
'replace': a[i1:i2] should be replaced by b[j1:j2]
|
|
||||||
'delete': a[i1:i2] should be deleted.
|
|
||||||
Note that j1==j2 in this case.
|
|
||||||
'insert': b[j1:j2] should be inserted at a[i1:i1].
|
|
||||||
Note that i1==i2 in this case.
|
|
||||||
'equal': a[i1:i2] == b[j1:j2]
|
|
||||||
|
|
||||||
>>> a = "qabxcd"
|
|
||||||
>>> b = "abycdf"
|
|
||||||
>>> s = SequenceMatcher(None, a, b)
|
|
||||||
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
|
|
||||||
... print ("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
|
|
||||||
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2]))
|
|
||||||
delete a[0:1] (q) b[0:0] ()
|
|
||||||
equal a[1:3] (ab) b[0:2] (ab)
|
|
||||||
replace a[3:4] (x) b[2:3] (y)
|
|
||||||
equal a[4:6] (cd) b[3:5] (cd)
|
|
||||||
insert a[6:6] () b[5:6] (f)
|
|
||||||
"""
|
|
||||||
|
|
||||||
if self.opcodes is not None:
|
|
||||||
return self.opcodes
|
|
||||||
i = j = 0
|
|
||||||
self.opcodes = answer = []
|
|
||||||
for ai, bj, size in self.get_matching_blocks():
|
|
||||||
# invariant: we've pumped out correct diffs to change
|
|
||||||
# a[:i] into b[:j], and the next matching block is
|
|
||||||
# a[ai:ai+size] == b[bj:bj+size]. So we need to pump
|
|
||||||
# out a diff to change a[i:ai] into b[j:bj], pump out
|
|
||||||
# the matching block, and move (i,j) beyond the match
|
|
||||||
tag = ''
|
|
||||||
if i < ai and j < bj:
|
|
||||||
tag = 'replace'
|
|
||||||
elif i < ai:
|
|
||||||
tag = 'delete'
|
|
||||||
elif j < bj:
|
|
||||||
tag = 'insert'
|
|
||||||
if tag:
|
|
||||||
answer.append( (tag, i, ai, j, bj) )
|
|
||||||
i, j = ai+size, bj+size
|
|
||||||
# the list of matching blocks is terminated by a
|
|
||||||
# sentinel with size 0
|
|
||||||
if size:
|
|
||||||
answer.append( ('equal', ai, i, bj, j) )
|
|
||||||
return answer
|
|
||||||
|
|
||||||
def ratio(self):
|
|
||||||
"""Return a measure of the sequences' similarity (float in [0,1]).
|
|
||||||
|
|
||||||
Where T is the total number of elements in both sequences, and
|
|
||||||
M is the number of matches, this is 2,0*M / T.
|
|
||||||
Note that this is 1 if the sequences are identical, and 0 if
|
|
||||||
they have nothing in common.
|
|
||||||
|
|
||||||
.ratio() is expensive to compute if you haven't already computed
|
|
||||||
.get_matching_blocks() or .get_opcodes(), in which case you may
|
|
||||||
want to try .quick_ratio() or .real_quick_ratio() first to get an
|
|
||||||
upper bound.
|
|
||||||
|
|
||||||
>>> s = SequenceMatcher(None, "abcd", "bcde")
|
|
||||||
>>> s.ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.quick_ratio()
|
|
||||||
0.75
|
|
||||||
>>> s.real_quick_ratio()
|
|
||||||
1.0
|
|
||||||
"""
|
|
||||||
|
|
||||||
matches = reduce(lambda sum, triple: sum + triple[-1],
|
|
||||||
self.get_matching_blocks(), 0)
|
|
||||||
return 2.0 * matches / (len(self.a) + len(self.b))
|
|
||||||
|
|
||||||
def quick_ratio(self):
|
|
||||||
"""Return an upper bound on ratio() relatively quickly.
|
|
||||||
|
|
||||||
This isn't defined beyond that it is an upper bound on .ratio(), and
|
|
||||||
is faster to compute.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# viewing a and b as multisets, set matches to the cardinality
|
|
||||||
# of their intersection; this counts the number of matches
|
|
||||||
# without regard to order, so is clearly an upper bound
|
|
||||||
if self.fullbcount is None:
|
|
||||||
self.fullbcount = fullbcount = {}
|
|
||||||
for elt in self.b:
|
|
||||||
fullbcount[elt] = fullbcount.get(elt, 0) + 1
|
|
||||||
fullbcount = self.fullbcount
|
|
||||||
# avail[x] is the number of times x appears in 'b' less the
|
|
||||||
# number of times we've seen it in 'a' so far ... kinda
|
|
||||||
avail = {}
|
|
||||||
availhas, matches = avail.has_key, 0
|
|
||||||
for elt in self.a:
|
|
||||||
if availhas(elt):
|
|
||||||
numb = avail[elt]
|
|
||||||
else:
|
|
||||||
numb = fullbcount.get(elt, 0)
|
|
||||||
avail[elt] = numb - 1
|
|
||||||
if numb > 0:
|
|
||||||
matches = matches + 1
|
|
||||||
return 2.0 * matches / (len(self.a) + len(self.b))
|
|
||||||
|
|
||||||
def real_quick_ratio(self):
|
|
||||||
"""Return an upper bound on ratio() very quickly.
|
|
||||||
|
|
||||||
This isn't defined beyond that it is an upper bound on .ratio(), and
|
|
||||||
is faster to compute than either .ratio() or .quick_ratio().
|
|
||||||
"""
|
|
||||||
|
|
||||||
la, lb = len(self.a), len(self.b)
|
|
||||||
# can't have more matches than the number of elements in the
|
|
||||||
# shorter sequence
|
|
||||||
return 2.0 * min(la, lb) / (la + lb)
|
|
||||||
|
|
||||||
def get_close_matches(word, possibilities, n=3, cutoff=0.6):
|
|
||||||
"""Use SequenceMatcher to return list of the best "good enough" matches.
|
|
||||||
|
|
||||||
word is a sequence for which close matches are desired (typically a
|
|
||||||
string).
|
|
||||||
|
|
||||||
possibilities is a list of sequences against which to match word
|
|
||||||
(typically a list of strings).
|
|
||||||
|
|
||||||
Optional arg n (default 3) is the maximum number of close matches to
|
|
||||||
return. n must be > 0.
|
|
||||||
|
|
||||||
Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities
|
|
||||||
that don't score at least that similar to word are ignored.
|
|
||||||
|
|
||||||
The best (no more than n) matches among the possibilities are returned
|
|
||||||
in a list, sorted by similarity score, most similar first.
|
|
||||||
|
|
||||||
>>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
|
|
||||||
['apple', 'ape']
|
|
||||||
>>> import keyword
|
|
||||||
>>> get_close_matches("wheel", keyword.kwlist)
|
|
||||||
['while']
|
|
||||||
>>> get_close_matches("apple", keyword.kwlist)
|
|
||||||
[]
|
|
||||||
>>> get_close_matches("accept", keyword.kwlist)
|
|
||||||
['except']
|
|
||||||
"""
|
|
||||||
|
|
||||||
if not n > 0:
|
|
||||||
raise ValueError("n must be > 0: " + `n`)
|
|
||||||
if not 0.0 <= cutoff <= 1.0:
|
|
||||||
raise ValueError("cutoff must be in [0.0, 1.0]: " + `cutoff`)
|
|
||||||
result = []
|
|
||||||
s = SequenceMatcher()
|
|
||||||
s.set_seq2(word)
|
|
||||||
for x in possibilities:
|
|
||||||
s.set_seq1(x)
|
|
||||||
if s.real_quick_ratio() >= cutoff and \
|
|
||||||
s.quick_ratio() >= cutoff and \
|
|
||||||
s.ratio() >= cutoff:
|
|
||||||
result.append((s.ratio(), x))
|
|
||||||
# Sort by score.
|
|
||||||
result.sort()
|
|
||||||
# Retain only the best n.
|
|
||||||
result = result[-n:]
|
|
||||||
# Move best-scorer to head of list.
|
|
||||||
result.reverse()
|
|
||||||
# Strip scores.
|
|
||||||
# Python 2.x list comprehensions: return [x for score, x in result]
|
|
||||||
return_result = []
|
|
||||||
for score, x in result:
|
|
||||||
return_result.append(x)
|
|
||||||
return return_result
|
|
||||||
|
|
||||||
def _test():
|
|
||||||
import doctest, difflib
|
|
||||||
return doctest.testmod(difflib)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
_test()
|
|
18
lib/ndiff.py
18
lib/ndiff.py
@@ -4,8 +4,6 @@
|
|||||||
# Released to the public domain 08-Dec-2000,
|
# Released to the public domain 08-Dec-2000,
|
||||||
# by Tim Peters (tim.one@home.com).
|
# by Tim Peters (tim.one@home.com).
|
||||||
|
|
||||||
# Backported to Python 1.5.2 for ViewCVS by pf@artcom-gmbh.de, 24-Dec-2001
|
|
||||||
|
|
||||||
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
|
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
|
||||||
|
|
||||||
"""ndiff [-q] file1 file2
|
"""ndiff [-q] file1 file2
|
||||||
@@ -45,7 +43,7 @@ recovered by piping the output through
|
|||||||
See module comments for details and programmatic interface.
|
See module comments for details and programmatic interface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = 1, 6, 1
|
__version__ = 1, 5, 0
|
||||||
|
|
||||||
# SequenceMatcher tries to compute a "human-friendly diff" between
|
# SequenceMatcher tries to compute a "human-friendly diff" between
|
||||||
# two sequences (chiefly picturing a file as a sequence of lines,
|
# two sequences (chiefly picturing a file as a sequence of lines,
|
||||||
@@ -202,15 +200,15 @@ def fancy_replace(a, alo, ahi, b, blo, bhi):
|
|||||||
for tag, ai1, ai2, bj1, bj2 in cruncher.get_opcodes():
|
for tag, ai1, ai2, bj1, bj2 in cruncher.get_opcodes():
|
||||||
la, lb = ai2 - ai1, bj2 - bj1
|
la, lb = ai2 - ai1, bj2 - bj1
|
||||||
if tag == 'replace':
|
if tag == 'replace':
|
||||||
atags = atags + '^' * la
|
atags += '^' * la
|
||||||
btags = btags + '^' * lb
|
btags += '^' * lb
|
||||||
elif tag == 'delete':
|
elif tag == 'delete':
|
||||||
atags = atags + '-' * la
|
atags += '-' * la
|
||||||
elif tag == 'insert':
|
elif tag == 'insert':
|
||||||
btags = btags + '+' * lb
|
btags += '+' * lb
|
||||||
elif tag == 'equal':
|
elif tag == 'equal':
|
||||||
atags = atags + ' ' * la
|
atags += ' ' * la
|
||||||
btags = btags + ' ' * lb
|
btags += ' ' * lb
|
||||||
else:
|
else:
|
||||||
raise ValueError, 'unknown tag ' + `tag`
|
raise ValueError, 'unknown tag ' + `tag`
|
||||||
printq(aelt, belt, atags, btags)
|
printq(aelt, belt, atags, btags)
|
||||||
@@ -247,7 +245,7 @@ def printq(aline, bline, atags, btags):
|
|||||||
def count_leading(line, ch):
|
def count_leading(line, ch):
|
||||||
i, n = 0, len(line)
|
i, n = 0, len(line)
|
||||||
while i < n and line[i] == ch:
|
while i < n and line[i] == ch:
|
||||||
i = i+1
|
i += 1
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def fail(msg):
|
def fail(msg):
|
||||||
|
@@ -295,12 +295,6 @@ def build_commit(desc, files):
|
|||||||
ob.desc = ' '
|
ob.desc = ' '
|
||||||
|
|
||||||
for commit in files:
|
for commit in files:
|
||||||
dir_parts = filter(None, string.split(commit.GetDirectory(), '/'))
|
|
||||||
if dir_parts \
|
|
||||||
and ((dir_parts[0] == 'CVSROOT' and cfg.options.hide_cvsroot) \
|
|
||||||
or cfg.is_forbidden(dir_parts[0])):
|
|
||||||
continue
|
|
||||||
|
|
||||||
ctime = commit.GetTime()
|
ctime = commit.GetTime()
|
||||||
if not ctime:
|
if not ctime:
|
||||||
ctime = " ";
|
ctime = " ";
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
|
||||||
__version__ = '0.9.4'
|
__version__ = '0.9'
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
#
|
#
|
||||||
@@ -248,10 +248,9 @@ def redirect(location):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def error(msg, status='500 Internal Server Error'):
|
def error(msg, status='500 Internal Server Error'):
|
||||||
print 'Content-type: text/html'
|
|
||||||
print 'Status:', status
|
print 'Status:', status
|
||||||
print
|
print
|
||||||
print cgi.escape(msg)
|
print msg
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def generate_page(request, tname, data):
|
def generate_page(request, tname, data):
|
||||||
@@ -1106,8 +1105,7 @@ def view_directory(request):
|
|||||||
view_tag = query_dict.get('only_with_tag')
|
view_tag = query_dict.get('only_with_tag')
|
||||||
hideattic = int(query_dict.get('hideattic')) ### watch for errors in int()?
|
hideattic = int(query_dict.get('hideattic')) ### watch for errors in int()?
|
||||||
sortby = query_dict.get('sortby', 'file')
|
sortby = query_dict.get('sortby', 'file')
|
||||||
if not re.match('^[a-z]+$', sortby):
|
|
||||||
raise 'illegal value for sortby parameter'
|
|
||||||
search_re = query_dict.get('search')
|
search_re = query_dict.get('search')
|
||||||
|
|
||||||
# Search current directory
|
# Search current directory
|
||||||
@@ -1843,8 +1841,8 @@ def process_checkout(full_name, where, query_dict, default_mime_type):
|
|||||||
|
|
||||||
mime_type = query_dict.get('content-type')
|
mime_type = query_dict.get('content-type')
|
||||||
if mime_type:
|
if mime_type:
|
||||||
if not re.match('^[-_.a-zA-Z0-9/]+$', mime_type):
|
### validate it?
|
||||||
raise 'illegal value for content-type parameter'
|
pass
|
||||||
else:
|
else:
|
||||||
mime_type = default_mime_type
|
mime_type = default_mime_type
|
||||||
|
|
||||||
@@ -2186,8 +2184,6 @@ class DiffSource:
|
|||||||
self.left = None
|
self.left = None
|
||||||
self.right = None
|
self.right = None
|
||||||
self.state = 'no-changes'
|
self.state = 'no-changes'
|
||||||
self.left_col = [ ]
|
|
||||||
self.right_col = [ ]
|
|
||||||
|
|
||||||
def __getitem__(self, idx):
|
def __getitem__(self, idx):
|
||||||
if idx == self.idx:
|
if idx == self.idx:
|
||||||
@@ -2203,6 +2199,7 @@ class DiffSource:
|
|||||||
if item:
|
if item:
|
||||||
self.idx = idx
|
self.idx = idx
|
||||||
self.last = item
|
self.last = item
|
||||||
|
open('/tmp/log','a').write('idx=%d item=%s\n' % (idx,vars(item)))
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def _get_row(self):
|
def _get_row(self):
|
||||||
@@ -2217,10 +2214,9 @@ class DiffSource:
|
|||||||
self.save_line = None
|
self.save_line = None
|
||||||
else:
|
else:
|
||||||
line = self.fp.readline()
|
line = self.fp.readline()
|
||||||
|
|
||||||
if not line:
|
if not line:
|
||||||
if self.state == 'no-changes':
|
if self.state == 'no-changes':
|
||||||
self.state = 'done'
|
self.state == 'done'
|
||||||
return _item(type='no-changes')
|
return _item(type='no-changes')
|
||||||
|
|
||||||
# see if there are lines to flush
|
# see if there are lines to flush
|
||||||
@@ -2454,9 +2450,6 @@ def generate_tarball(out, relative, directory, tag, stack=[]):
|
|||||||
for file, pathname, isdir in get_file_data(directory):
|
for file, pathname, isdir in get_file_data(directory):
|
||||||
if pathname == _UNREADABLE_MARKER:
|
if pathname == _UNREADABLE_MARKER:
|
||||||
continue
|
continue
|
||||||
if (file == 'CVSROOT' and cfg.options.hide_cvsroot) \
|
|
||||||
or cfg.is_forbidden(file):
|
|
||||||
continue
|
|
||||||
if isdir:
|
if isdir:
|
||||||
subdirs.append(file)
|
subdirs.append(file)
|
||||||
else:
|
else:
|
||||||
@@ -2614,12 +2607,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
# if the file is in the Attic, then redirect
|
# if the file is in the Attic, then redirect
|
||||||
idx = string.rfind(full_name, '/')
|
idx = string.rfind(full_name, '/')
|
||||||
attic_name = full_name[:idx] + '/Attic' + full_name[idx:]
|
attic_name = full_name[:idx] + '/Attic' + full_name[idx:] + ',v'
|
||||||
if os.path.isfile(attic_name + ',v') or \
|
if os.path.isfile(attic_name):
|
||||||
full_name[-5:] == '.diff' and os.path.isfile(attic_name[:-5] + ',v'):
|
|
||||||
idx = string.rfind(url, '/')
|
idx = string.rfind(url, '/')
|
||||||
redirect(url[:idx] + '/Attic' + url[idx:] + \
|
redirect(url[:idx] + '/Attic' + url[idx:])
|
||||||
'?' + compat.urlencode(query_dict))
|
|
||||||
|
|
||||||
error('%s: unknown location' % request.url, '404 Not Found')
|
error('%s: unknown location' % request.url, '404 Not Found')
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td align=center valign=top bgcolor="white" width="1%">
|
<td align=center valign=top bgcolor="white" width="1%">
|
||||||
<b>Quickstart:</b>
|
<b>Quickstart:</b>
|
||||||
<a href="viewcvs-0.9.4.tar.gz">download</a>
|
<a href="viewcvs-0.9.tar.gz">download</a>
|
||||||
</td>
|
</td>
|
||||||
<td width="1%"><a href="http://sourceforge.net/"><img border=0
|
<td width="1%"><a href="http://sourceforge.net/"><img border=0
|
||||||
src="http://sourceforge.net/sflogo.php?group_id=18760&type=1"></a><br><a href="http://sourceforge.net/projects/viewcvs/">ViewCVS project page</a>
|
src="http://sourceforge.net/sflogo.php?group_id=18760&type=1"></a><br><a href="http://sourceforge.net/projects/viewcvs/">ViewCVS project page</a>
|
||||||
@@ -210,10 +210,10 @@
|
|||||||
The software is available for download:
|
The software is available for download:
|
||||||
</p>
|
</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<a href="viewcvs-0.9.4.tar.gz">Version 0.9.4 of ViewCVS as a gzipped
|
<a href="viewcvs-0.9.tar.gz">Version 0.9 of ViewCVS as a gzipped
|
||||||
tar</a>
|
tar</a>
|
||||||
<br>
|
<br>
|
||||||
<a href="viewcvs-0.9.4.zip">Version 0.9.4 of ViewCVS as a ZIP
|
<a href="viewcvs-0.9.zip">Version 0.9 of ViewCVS as a ZIP
|
||||||
file</a>
|
file</a>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<p>
|
<p>
|
||||||
@@ -299,7 +299,7 @@
|
|||||||
<address><a href="mailto:viewcvs@lyra.org">ViewCVS Users Group</a></address>
|
<address><a href="mailto:viewcvs@lyra.org">ViewCVS Users Group</a></address>
|
||||||
<!-- Created: Fri Dec 3 02:51:37 PST 1999 -->
|
<!-- Created: Fri Dec 3 02:51:37 PST 1999 -->
|
||||||
<!-- hhmts start -->
|
<!-- hhmts start -->
|
||||||
Last modified: Tue Jan 15 01:51:03 PST 2002
|
Last modified: Sun Dec 23 03:23:09 PST 2001
|
||||||
<!-- hhmts end -->
|
<!-- hhmts end -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user