Changeset 885 in tailor


Ignore:
Timestamp:
10/05/05 10:32:48 (8 years ago)
Author:
Aaron Kaplan <kaplan@…>
Hash name:
20051005083248-d21f0-8f92e53d5d5eb7c79537e5aa6081541b7014f5c6
Message:

Normalize CVS revision to make simpler the recognition of branches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vcpx/cvs.py

    r872 r885  
    1717from config import ConfigurationError 
    1818 
    19 def compare_cvs_revs(rev1, rev2): 
    20     """Compare two CVS revision numerically, not alphabetically.""" 
    21  
    22     if not rev1: rev1 = '0' 
    23     if not rev2: rev2 = '0' 
     19def normalize_cvs_rev(rev): 
     20    """Convert a revision string to a tuple of numbers, eliminating the 
     21    penultimate zero in a 'magic branch number' if there is one. 
     22    1.1.1.1 is converted to (1,1). """ 
     23    if not rev: rev = '0' 
    2424 
    2525    # handle locked files by taking only the first part of the 
    2626    # revision string to handle gracefully lines like "1.1 locked" 
    27     rev1 = rev1.split(' ')[0] 
    28     rev2 = rev2.split(' ')[0] 
    29     r1 = [int(n) for n in rev1.split('.')] 
    30     r2 = [int(n) for n in rev2.split('.')] 
     27    rev = rev.split(' ')[0] 
     28 
     29    r = [int(n) for n in rev.split('.')] 
     30    # convert "magic branch numbers" like 1.2.0.2 to regular 
     31    # branch numbers like 1.2.2. 
     32    if len(r) > 2 and r[-2] == 0: 
     33        r = r[0:-2] + r[-1:] 
     34 
     35    if r == [1,1,1,1]: 
     36        r = [1,1] 
     37 
     38    return tuple(r) 
     39 
     40def compare_cvs_revs(revstr1, revstr2): 
     41    """Compare two CVS revision strings numerically, not alphabetically.""" 
     42 
     43    r1 = normalize_cvs_rev(revstr1) 
     44    r2 = normalize_cvs_rev(revstr2) 
    3145 
    3246    return cmp(r1, r2) 
Note: See TracChangeset for help on using the changeset viewer.