Attachment 'wikiutil-2003-02-13.diff'

Download

   1 --- ../../moin/MoinMoin/wikiutil.py	Thu Feb 13 13:53:42 2003
   2 +++ wikiutil.py	Thu Feb 13 13:39:41 2003
   3 @@ -515,24 +515,83 @@
   4          Returns a tuple of diff return code, page file name,
   5          backup page file name, and a list of lines of diff output.
   6      """
   7 -    # build the diff command and execute it
   8      backup_file = os.path.join(config.backup_dir, oldpage)
   9      page_file = os.path.join(config.text_dir, quoteFilename(pagename))
  10 -    options = '-u'
  11 -    if kw.get('ignorews', 0): options = options + ' -b'
  12 -    cmd = "%(diff)s %(options)s %(backup)s %(page)s" % {
  13 -        "diff": config.external_diff,
  14 -        "options": options,
  15 -        "backup": backup_file,
  16 -        "page": page_file,
  17 -    }
  18 -    diff = util.popen(cmd, "r")
  19 -    lines = diff.readlines()
  20 -    rc = diff.close()
  21 -    ##print "cmd =", cmd, "<br>"
  22 -    ##print "rc =", rc, "<br>"
  23 +    backup = None
  24 +    page = None
  25 +    try:
  26 +        fd = open(backup_file)
  27 +        backup = fd.readlines()
  28 +    finally:
  29 +        fd.close()
  30 +    try:
  31 +        fd = open(page_file)
  32 +        page = fd.readlines()
  33 +    finally:
  34 +        fd.close()
  35 +
  36 +    if not backup or not page: return -1, page_file, backup_file, []
  37 +        
  38 +    import difflib
  39 +    false = lambda s: None 
  40 +    if kw.get('ignorews', 0):
  41 +        d = difflib.Differ(false)
  42 +    else:
  43 +        d = difflib.Differ(false, false)
  44 +
  45 +    lines = list(d.compare(backup, page))
  46  
  47 -    return rc, page_file, backup_file, lines
  48 +    # return empty list if there were no changes
  49 +    change = None
  50 +    for l in lines:
  51 +        if l[0] != ' ':
  52 +            change = 1
  53 +            break
  54 +    if not change: return 0, page_file, backup_file, []
  55 +            
  56 +
  57 +    if not "we want the unchanged lines, too":
  58 +        if "no questionmark lines":
  59 +            lines = filter(lambda line : line[0]!='?', lines)
  60 +        return 0, page_file, backup_file, lines
  61 +
  62 +
  63 +    # calculate the hunks and remove the unchanged lines between them
  64 +    i = 0              # actual index in lines
  65 +    count = 0          # number of unchanged lines
  66 +    lcount_old = 0     # line count old file
  67 +    lcount_new = 0     # line count new file
  68 +    while i < len(lines):
  69 +        marker = lines[i][0]
  70 +        if marker == ' ':
  71 +            count = count + 1
  72 +            i = i + 1
  73 +            lcount_old = lcount_old + 1
  74 +            lcount_new = lcount_new + 1
  75 +        elif marker in ['-', '+']:
  76 +            if (count == i) and count > 3:
  77 +                lines[:i-3] = []
  78 +                i = 4
  79 +                count = 0
  80 +            elif count > 6:
  81 +                # remove lines and insert new hunk indicator
  82 +                lines[i-count+3:i-3] = ['@@ -%i, +%i @@\n' %
  83 +                                        (lcount_old, lcount_new)]
  84 +                i = i - count + 8
  85 +                count = 0
  86 +            else:
  87 +                count = 0
  88 +                i = i + 1                            
  89 +            if marker == '-': lcount_old = lcount_old + 1
  90 +            else: lcount_new = lcount_new + 1
  91 +        elif marker == '?':
  92 +            lines[i:i+1] = []
  93 +
  94 +    # remove unchanged lines a the end
  95 +    if count > 3:
  96 +        lines[-count+3:] = []
  97 +    
  98 +    return 0, page_file, backup_file, lines
  99  
 100  
 101  #############################################################################

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2003-12-31 09:44:19, 6.2 KB) [[attachment:fix-attachfile-filename.diff]]
  • [get | view] (2004-01-04 08:55:32, 0.6 KB) [[attachment:fix-twisted-httphost.diff]]
  • [get | view] (2004-01-16 08:39:21, 1.6 KB) [[attachment:macro-sendpage.diff]]
  • [get | view] (2003-12-31 09:20:52, 7.0 KB) [[attachment:raise-but-exit.diff]]
  • [get | view] (2003-12-07 18:15:55, 0.2 KB) [[attachment:version.txt]]
  • [get | view] (2003-12-07 18:15:55, 3.1 KB) [[attachment:wikiaction-2003-02-13.diff]]
  • [get | view] (2003-12-07 18:15:55, 3.2 KB) [[attachment:wikiutil-2003-02-13.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.