cdiff-1.0/0000755000076600000240000000000013031633112013067 5ustar ymattwstaff00000000000000cdiff-1.0/cdiff0000755000076600000240000000017713031166611014102 0ustar ymattwstaff00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import cdiff sys.exit(cdiff.main()) # vim:set et sts=4 sw=4 tw=79: cdiff-1.0/cdiff.py0000755000076600000240000007133213031631713014532 0ustar ymattwstaff00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """ Term based tool to view *colored*, *incremental* diff in a *Git/Mercurial/Svn* workspace or from stdin, with *side by side* and *auto pager* support. Requires python (>= 2.5.0) and ``less``. """ import sys import os import re import signal import subprocess import select import difflib META_INFO = { 'version' : '1.0', 'license' : 'BSD-3', 'author' : 'Matthew Wang', 'email' : 'mattwyl(@)gmail(.)com', 'url' : 'https://github.com/ymattw/cdiff', 'keywords' : 'colored incremental side-by-side diff', 'description' : ('View colored, incremental diff in a workspace or from ' 'stdin, with side by side and auto pager support') } if sys.hexversion < 0x02050000: raise SystemExit("*** Requires python >= 2.5.0") # pragma: no cover # Python < 2.6 does not have next() try: next except NameError: def next(obj): return obj.next() try: unicode except NameError: unicode = str COLORS = { 'reset' : '\x1b[0m', 'underline' : '\x1b[4m', 'reverse' : '\x1b[7m', 'red' : '\x1b[31m', 'green' : '\x1b[32m', 'yellow' : '\x1b[33m', 'blue' : '\x1b[34m', 'magenta' : '\x1b[35m', 'cyan' : '\x1b[36m', 'lightred' : '\x1b[1;31m', 'lightgreen' : '\x1b[1;32m', 'lightyellow' : '\x1b[1;33m', 'lightblue' : '\x1b[1;34m', 'lightmagenta' : '\x1b[1;35m', 'lightcyan' : '\x1b[1;36m', } # Keys for revision control probe, diff and log with diff VCS_INFO = { 'Git': { 'probe': ['git', 'rev-parse'], 'diff': ['git', 'diff', '--no-ext-diff'], 'log': ['git', 'log', '--patch'], }, 'Mercurial': { 'probe': ['hg', 'summary'], 'diff': ['hg', 'diff'], 'log': ['hg', 'log', '--patch'], }, 'Svn': { 'probe': ['svn', 'info'], 'diff': ['svn', 'diff'], 'log': ['svn', 'log', '--diff', '--use-merge-history'], }, } def colorize(text, start_color, end_color='reset'): return COLORS[start_color] + text + COLORS[end_color] class Hunk(object): def __init__(self, hunk_headers, hunk_meta, old_addr, new_addr): self._hunk_headers = hunk_headers self._hunk_meta = hunk_meta self._old_addr = old_addr # tuple (start, offset) self._new_addr = new_addr # tuple (start, offset) self._hunk_list = [] # list of tuple (attr, line) def append(self, hunk_line): """hunk_line is a 2-element tuple: (attr, text), where attr is: '-': old, '+': new, ' ': common """ self._hunk_list.append(hunk_line) def mdiff(self): r"""The difflib._mdiff() function returns an interator which returns a tuple: (from line tuple, to line tuple, boolean flag) from/to line tuple -- (line num, line text) line num -- integer or None (to indicate a context separation) line text -- original line text with following markers inserted: '\0+' -- marks start of added text '\0-' -- marks start of deleted text '\0^' -- marks start of changed text '\1' -- marks end of added/deleted/changed text boolean flag -- None indicates context separation, True indicates either "from" or "to" line contains a change, otherwise False. """ return difflib._mdiff(self._get_old_text(), self._get_new_text()) def _get_old_text(self): out = [] for (attr, line) in self._hunk_list: if attr != '+': out.append(line) return out def _get_new_text(self): out = [] for (attr, line) in self._hunk_list: if attr != '-': out.append(line) return out def is_completed(self): old_completed = self._old_addr[1] == len(self._get_old_text()) new_completed = self._new_addr[1] == len(self._get_new_text()) return old_completed and new_completed class UnifiedDiff(object): def __init__(self, headers, old_path, new_path, hunks): self._headers = headers self._old_path = old_path self._new_path = new_path self._hunks = hunks def is_old_path(self, line): return line.startswith('--- ') def is_new_path(self, line): return line.startswith('+++ ') def is_hunk_meta(self, line): """Minimal valid hunk meta is like '@@ -1 +1 @@', note extra chars might occur after the ending @@, e.g. in git log. '## ' usually indicates svn property changes in output from `svn log --diff` """ return (line.startswith('@@ -') and line.find(' @@') >= 8) or \ (line.startswith('## -') and line.find(' ##') >= 8) def parse_hunk_meta(self, hunk_meta): # @@ -3,7 +3,6 @@ a = hunk_meta.split()[1].split(',') # -3 7 if len(a) > 1: old_addr = (int(a[0][1:]), int(a[1])) else: # @@ -1 +1,2 @@ old_addr = (int(a[0][1:]), 1) b = hunk_meta.split()[2].split(',') # +3 6 if len(b) > 1: new_addr = (int(b[0][1:]), int(b[1])) else: # @@ -0,0 +1 @@ new_addr = (int(b[0][1:]), 1) return (old_addr, new_addr) def parse_hunk_line(self, line): return (line[0], line[1:]) def is_old(self, line): """Exclude old path and header line from svn log --diff output, allow '----' likely to see in diff from yaml file """ return line.startswith('-') and not self.is_old_path(line) and \ not re.match(r'^-{72}$', line.rstrip()) def is_new(self, line): return line.startswith('+') and not self.is_new_path(line) def is_common(self, line): return line.startswith(' ') def is_eof(self, line): # \ No newline at end of file # \ No newline at end of property return line.startswith(r'\ No newline at end of') def is_only_in_dir(self, line): return line.startswith('Only in ') def is_binary_differ(self, line): return re.match('^Binary files .* differ$', line.rstrip()) class PatchStream(object): def __init__(self, diff_hdl): self._diff_hdl = diff_hdl self._stream_header_size = 0 self._stream_header = [] # Test whether stream is empty by read 1 line line = self._diff_hdl.readline() if not line: self._is_empty = True else: self._stream_header.append(line) self._stream_header_size += 1 self._is_empty = False def is_empty(self): return self._is_empty def read_stream_header(self, stream_header_size): """Returns a small chunk for patch type detect, suppose to call once""" for i in range(1, stream_header_size): line = self._diff_hdl.readline() if not line: break self._stream_header.append(line) self._stream_header_size += 1 return self._stream_header def __iter__(self): for line in self._stream_header: yield line for line in self._diff_hdl: yield line class PatchStreamForwarder(object): """A blocking stream forwarder use `select` and line buffered mode. Feed input stream to a diff format translator and read output stream from it. Note input stream is non-seekable, and upstream has eaten some lines. """ def __init__(self, istream, translator): assert isinstance(istream, PatchStream) assert isinstance(translator, subprocess.Popen) self._istream = iter(istream) self._in = translator.stdin self._out = translator.stdout def _can_read(self, timeout=0): return select.select([self._out.fileno()], [], [], timeout)[0] def _forward_line(self): try: line = next(self._istream) self._in.write(line) except StopIteration: self._in.close() def __iter__(self): while True: if self._can_read(): line = self._out.readline() if line: yield line else: return elif not self._in.closed: self._forward_line() class DiffParser(object): def __init__(self, stream): header = [decode(line) for line in stream.read_stream_header(100)] size = len(header) if size >= 4 and (header[0].startswith('*** ') and header[1].startswith('--- ') and header[2].rstrip() == '***************' and header[3].startswith('*** ') and header[3].rstrip().endswith(' ****')): # For context diff, try use `filterdiff` to translate it to unified # format and provide a new stream # self._type = 'context' try: # Use line buffered mode so that to readline() in block mode self._translator = subprocess.Popen( ['filterdiff', '--format=unified'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1) except OSError: raise SystemExit('*** Context diff support depends on ' 'filterdiff') self._stream = PatchStreamForwarder(stream, self._translator) return for n in range(size): if (header[n].startswith('--- ') and (n < size - 1) and header[n + 1].startswith('+++ ')): self._type = 'unified' self._stream = stream break else: # `filterdiff` translates unknown diff to nothing, fall through to # unified diff give cdiff a chance to show everything as headers # sys.stderr.write("*** unknown format, fall through to 'unified'\n") self._type = 'unified' self._stream = stream def get_diff_generator(self): """parse all diff lines, construct a list of UnifiedDiff objects""" diff = UnifiedDiff([], None, None, []) headers = [] for line in self._stream: line = decode(line) if diff.is_old_path(line): # This is a new diff when current hunk is not yet genreated or # is completed. We yield previous diff if exists and construct # a new one for this case. Otherwise it's acutally an 'old' # line starts with '--- '. # if (not diff._hunks or diff._hunks[-1].is_completed()): if diff._old_path and diff._new_path and diff._hunks: yield diff diff = UnifiedDiff(headers, line, None, []) headers = [] else: diff._hunks[-1].append(diff.parse_hunk_line(line)) elif diff.is_new_path(line) and diff._old_path: if not diff._new_path: diff._new_path = line else: diff._hunks[-1].append(diff.parse_hunk_line(line)) elif diff.is_hunk_meta(line): hunk_meta = line try: old_addr, new_addr = diff.parse_hunk_meta(hunk_meta) except (IndexError, ValueError): raise RuntimeError('invalid hunk meta: %s' % hunk_meta) hunk = Hunk(headers, hunk_meta, old_addr, new_addr) headers = [] diff._hunks.append(hunk) elif diff._hunks and not headers and (diff.is_old(line) or diff.is_new(line) or diff.is_common(line)): diff._hunks[-1].append(diff.parse_hunk_line(line)) elif diff.is_eof(line): # ignore pass elif diff.is_only_in_dir(line) or \ diff.is_binary_differ(line): # 'Only in foo:' and 'Binary files ... differ' are considered # as separate diffs, so yield current diff, then this line # if diff._old_path and diff._new_path and diff._hunks: # Current diff is comppletely constructed yield diff headers.append(line) yield UnifiedDiff(headers, '', '', []) headers = [] diff = UnifiedDiff([], None, None, []) else: # All other non-recognized lines are considered as headers or # hunk headers respectively # headers.append(line) # Validate and yield the last patch set if it is not yielded yet if diff._old_path: assert diff._new_path is not None if diff._hunks: assert len(diff._hunks[-1]._hunk_meta) > 0 assert len(diff._hunks[-1]._hunk_list) > 0 yield diff if headers: # Tolerate dangling headers, just yield a UnifiedDiff object with # only header lines # yield UnifiedDiff(headers, '', '', []) class DiffMarker(object): def markup(self, diffs, side_by_side=False, width=0): """Returns a generator""" if side_by_side: for diff in diffs: for line in self._markup_side_by_side(diff, width): yield line else: for diff in diffs: for line in self._markup_traditional(diff): yield line def _markup_traditional(self, diff): """Returns a generator""" for line in diff._headers: yield self._markup_header(line) yield self._markup_old_path(diff._old_path) yield self._markup_new_path(diff._new_path) for hunk in diff._hunks: for hunk_header in hunk._hunk_headers: yield self._markup_hunk_header(hunk_header) yield self._markup_hunk_meta(hunk._hunk_meta) for old, new, changed in hunk.mdiff(): if changed: if not old[0]: # The '+' char after \x00 is kept # DEBUG: yield 'NEW: %s %s\n' % (old, new) line = new[1].strip('\x00\x01') yield self._markup_new(line) elif not new[0]: # The '-' char after \x00 is kept # DEBUG: yield 'OLD: %s %s\n' % (old, new) line = old[1].strip('\x00\x01') yield self._markup_old(line) else: # DEBUG: yield 'CHG: %s %s\n' % (old, new) yield self._markup_old('-') + \ self._markup_mix(old[1], 'red') yield self._markup_new('+') + \ self._markup_mix(new[1], 'green') else: yield self._markup_common(' ' + old[1]) def _markup_side_by_side(self, diff, width): """Returns a generator""" wrap_char = colorize('>', 'lightmagenta') def _normalize(line): return line.replace( '\t', ' ' * 8).replace('\n', '').replace('\r', '') def _fit_with_marker(text, markup_fn, width, pad=False): """Wrap or pad input pure text, then markup""" if len(text) > width: return markup_fn(text[:(width - 1)]) + wrap_char elif pad: pad_len = width - len(text) return '%s%*s' % (markup_fn(text), pad_len, '') else: return markup_fn(text) def _fit_with_marker_mix(text, base_color, width, pad=False): """Wrap or pad input text which contains mdiff tags, markup at the meantime, note only left side need to set `pad` """ out = [COLORS[base_color]] count = 0 tag_re = re.compile(r'\x00[+^-]|\x01') while text and count < width: if text.startswith('\x00-'): # del out.append(COLORS['reverse'] + COLORS[base_color]) text = text[2:] elif text.startswith('\x00+'): # add out.append(COLORS['reverse'] + COLORS[base_color]) text = text[2:] elif text.startswith('\x00^'): # change out.append(COLORS['underline'] + COLORS[base_color]) text = text[2:] elif text.startswith('\x01'): # reset out.append(COLORS['reset'] + COLORS[base_color]) text = text[1:] else: # FIXME: utf-8 wchar might break the rule here, e.g. # u'\u554a' takes double width of a single letter, also # this depends on your terminal font. I guess audience of # this tool never put that kind of symbol in their code :-) # out.append(text[0]) count += 1 text = text[1:] if count == width and tag_re.sub('', text): # Was stripped: output fulfil and still has normal char in text out[-1] = COLORS['reset'] + wrap_char elif count < width and pad: pad_len = width - count out.append('%s%*s' % (COLORS['reset'], pad_len, '')) else: out.append(COLORS['reset']) return ''.join(out) # Set up number width, note last hunk might be empty try: (start, offset) = diff._hunks[-1]._old_addr max1 = start + offset - 1 (start, offset) = diff._hunks[-1]._new_addr max2 = start + offset - 1 except IndexError: max1 = max2 = 0 num_width = max(len(str(max1)), len(str(max2))) # Set up line width if width <= 0: # Autodetection of text width according to terminal size try: # Each line is like "nnn TEXT nnn TEXT\n", so width is half of # [terminal size minus the line number columns and 3 separating # spaces # width = (terminal_size()[0] - num_width * 2 - 3) // 2 except Exception: # If terminal detection failed, set back to default width = 80 # Setup lineno and line format left_num_fmt = colorize('%%(left_num)%ds' % num_width, 'yellow') right_num_fmt = colorize('%%(right_num)%ds' % num_width, 'yellow') line_fmt = left_num_fmt + ' %(left)s ' + COLORS['reset'] + \ right_num_fmt + ' %(right)s\n' # yield header, old path and new path for line in diff._headers: yield self._markup_header(line) yield self._markup_old_path(diff._old_path) yield self._markup_new_path(diff._new_path) # yield hunks for hunk in diff._hunks: for hunk_header in hunk._hunk_headers: yield self._markup_hunk_header(hunk_header) yield self._markup_hunk_meta(hunk._hunk_meta) for old, new, changed in hunk.mdiff(): if old[0]: left_num = str(hunk._old_addr[0] + int(old[0]) - 1) else: left_num = ' ' if new[0]: right_num = str(hunk._new_addr[0] + int(new[0]) - 1) else: right_num = ' ' left = _normalize(old[1]) right = _normalize(new[1]) if changed: if not old[0]: left = '%*s' % (width, ' ') right = right.rstrip('\x01') if right.startswith('\x00+'): right = right[2:] right = _fit_with_marker( right, self._markup_new, width) elif not new[0]: left = left.rstrip('\x01') if left.startswith('\x00-'): left = left[2:] left = _fit_with_marker(left, self._markup_old, width) right = '' else: left = _fit_with_marker_mix(left, 'red', width, 1) right = _fit_with_marker_mix(right, 'green', width) else: left = _fit_with_marker( left, self._markup_common, width, 1) right = _fit_with_marker(right, self._markup_common, width) yield line_fmt % { 'left_num': left_num, 'left': left, 'right_num': right_num, 'right': right } def _markup_header(self, line): return colorize(line, 'cyan') def _markup_old_path(self, line): return colorize(line, 'yellow') def _markup_new_path(self, line): return colorize(line, 'yellow') def _markup_hunk_header(self, line): return colorize(line, 'lightcyan') def _markup_hunk_meta(self, line): return colorize(line, 'lightblue') def _markup_common(self, line): return colorize(line, 'reset') def _markup_old(self, line): return colorize(line, 'lightred') def _markup_new(self, line): return colorize(line, 'green') def _markup_mix(self, line, base_color): del_code = COLORS['reverse'] + COLORS[base_color] add_code = COLORS['reverse'] + COLORS[base_color] chg_code = COLORS['underline'] + COLORS[base_color] rst_code = COLORS['reset'] + COLORS[base_color] line = line.replace('\x00-', del_code) line = line.replace('\x00+', add_code) line = line.replace('\x00^', chg_code) line = line.replace('\x01', rst_code) return colorize(line, base_color) def markup_to_pager(stream, opts): """Pipe unified diff stream to pager (less). Note: have to create pager Popen object before the translator Popen object in PatchStreamForwarder, otherwise the `stdin=subprocess.PIPE` would cause trouble to the translator pipe (select() never see EOF after input stream ended), most likely python bug 12607 (http://bugs.python.org/issue12607) which was fixed in python 2.7.3. See issue #30 (https://github.com/ymattw/cdiff/issues/30) for more information. """ pager_cmd = ['less'] if not os.getenv('LESS'): # Args stolen from git source: github.com/git/git/blob/master/pager.c pager_cmd.extend(['-FRSX', '--shift 1']) pager = subprocess.Popen( pager_cmd, stdin=subprocess.PIPE, stdout=sys.stdout) diffs = DiffParser(stream).get_diff_generator() marker = DiffMarker() color_diff = marker.markup(diffs, side_by_side=opts.side_by_side, width=opts.width) for line in color_diff: pager.stdin.write(line.encode('utf-8')) pager.stdin.close() pager.wait() def check_command_status(arguments): """Return True if command returns 0.""" try: return subprocess.call( arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 except OSError: return False def revision_control_diff(args): """Return diff from revision control system.""" for _, ops in VCS_INFO.items(): if check_command_status(ops['probe']): return subprocess.Popen( ops['diff'] + args, stdout=subprocess.PIPE).stdout def revision_control_log(args): """Return log from revision control system.""" for _, ops in VCS_INFO.items(): if check_command_status(ops['probe']): return subprocess.Popen( ops['log'] + args, stdout=subprocess.PIPE).stdout def decode(line): """Decode UTF-8 if necessary.""" if isinstance(line, unicode): return line for encoding in ['utf-8', 'latin1']: try: return line.decode(encoding) except UnicodeDecodeError: pass return '*** cdiff: undecodable bytes ***\n' def terminal_size(): """Returns terminal size. Taken from https://gist.github.com/marsam/7268750 but removed win32 support which depends on 3rd party extension. """ width, height = None, None try: import struct import fcntl import termios s = struct.pack('HHHH', 0, 0, 0, 0) x = fcntl.ioctl(1, termios.TIOCGWINSZ, s) height, width = struct.unpack('HHHH', x)[0:2] except (IOError, AttributeError): pass return width, height def main(): signal.signal(signal.SIGPIPE, signal.SIG_DFL) signal.signal(signal.SIGINT, signal.SIG_DFL) from optparse import (OptionParser, BadOptionError, AmbiguousOptionError, OptionGroup) class PassThroughOptionParser(OptionParser): """Stop parsing on first unknown option (e.g. --cached, -U10) and pass them down. Note the `opt_str` in exception object does not give us chance to take the full option back, e.g. for '-U10' it will only contain '-U' and the '10' part will be lost. Ref: http://goo.gl/IqY4A (on stackoverflow). My hack is to try parse and insert a '--' in place and parse again. Let me know if someone has better solution. """ def _process_args(self, largs, rargs, values): left = largs[:] right = rargs[:] try: OptionParser._process_args(self, left, right, values) except (BadOptionError, AmbiguousOptionError): parsed_num = len(rargs) - len(right) - 1 rargs.insert(parsed_num, '--') OptionParser._process_args(self, largs, rargs, values) supported_vcs = sorted(VCS_INFO.keys()) usage = """%prog [options] [file|dir ...]""" parser = PassThroughOptionParser( usage=usage, description=META_INFO['description'], version='%%prog %s' % META_INFO['version']) parser.add_option( '-s', '--side-by-side', action='store_true', help='enable side-by-side mode') parser.add_option( '-w', '--width', type='int', default=80, metavar='N', help='set text width for side-by-side mode, 0 for auto detection, ' 'default is 80') parser.add_option( '-l', '--log', action='store_true', help='show log with changes from revision control') parser.add_option( '-c', '--color', default='auto', metavar='M', help="""colorize mode 'auto' (default), 'always', or 'never'""") # Hack: use OptionGroup text for extra help message after option list option_group = OptionGroup( parser, "Note", ("Option parser will stop on first unknown option " "and pass them down to underneath revision control. " "Environment variable CDIFF_OPTIONS may be used to " "specify default options that will be placed at the " "beginning of the argument list.")) parser.add_option_group(option_group) # Place possible options defined in CDIFF_OPTIONS at the beginning of argv cdiff_opts = [x for x in os.getenv('CDIFF_OPTIONS', '').split(' ') if x] opts, args = parser.parse_args(cdiff_opts + sys.argv[1:]) if opts.log: diff_hdl = revision_control_log(args) if not diff_hdl: sys.stderr.write(('*** Not in a supported workspace, supported ' 'are: %s\n') % ', '.join(supported_vcs)) return 1 elif sys.stdin.isatty(): diff_hdl = revision_control_diff(args) if not diff_hdl: sys.stderr.write(('*** Not in a supported workspace, supported ' 'are: %s\n\n') % ', '.join(supported_vcs)) parser.print_help() return 1 else: diff_hdl = (sys.stdin.buffer if hasattr(sys.stdin, 'buffer') else sys.stdin) stream = PatchStream(diff_hdl) # Don't let empty diff pass thru if stream.is_empty(): return 0 if opts.color == 'always' or \ (opts.color == 'auto' and sys.stdout.isatty()): markup_to_pager(stream, opts) else: # pipe out stream untouched to make sure it is still a patch byte_output = (sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout) for line in stream: byte_output.write(line) if diff_hdl is not sys.stdin: diff_hdl.close() return 0 if __name__ == '__main__': sys.exit(main()) # vim:set et sts=4 sw=4 tw=79: cdiff-1.0/CHANGES.rst0000644000076600000240000000630613031631675014712 0ustar ymattwstaff00000000000000 Change log ========== Version 1.0 (2016-12-31) - Use environment variable ``CDIFF_OPTIONS`` to hold default options Version 0.9.8 (2016-01-16) - More robust parser to tolerate evil unified diff Version 0.9.7 (2015-04-24) - Fix unexpected side-by-side output for diff of diff - Better color to work with solarized color scheme Version 0.9.6 (2014-06-20) - Fix TypeError exception in auto width logic Version 0.9.5 (2014-06-19) - Option ``--width 0`` now fits terminal size automatically - Enable smooth horizontal scrolling with less option ``--shift 1`` Version 0.9.4 (2014-06-04) - Respect the ``LESS`` environment variable - Support python 3.4 - Fix curl options in document Version 0.9.3 (2013-09-28) - Moved screenshots to 'gh-pages' branch - Handle all keyboard interrupts more completely - Explicitly set default encoding to utf-8 - Fixed broken output diff when I/O with filterdiff in nonblocking mode Version 0.9.2 (2013-06-21) - Enahanced option parser now pass unknown option to underneath revision control, user can use ``cdiff --cached``, ``cdiff -U5`` directly Version 0.9.1 (2013-05-20) - Use ``--no-ext-diff`` to disable GIT_EXTERNAL_DIFF and diff.external which might break cdiff output Version 0.9 (2013-03-23) - Supports reading context diff via ``filterdiff`` (patchutils) - Fixed a diff parser bug which misread git commit message as common line - Lots of code refactor Version 0.8 (2013-03-13) - Parser is now robust enough to handle dangling headers and short patch - PEP8 (with minor own flavors) and other code lint - Change 'Development Status' to stable Version 0.7.1 (2013-02-25) - Handle 'Binary files ... differ' - Document update for known issues Version 0.7 (2013-02-23) - Support reading diff or log for given files/dirs in workspace - Support diff generated from ``diff -ru dir1 dir2`` - Usage change: reading a patch and comparing two files need stdin redirect Version 0.6 (2013-02-20) - A few performance tuning and code clean up - Add unit test cases with coverage 70% - Show merge history in svn log Version 0.5.1 (2013-02-19) - Fixed incorrect yield on diff missing eof - Fixed a bug in diff format probe - Handle keyboard interrupt and large diffs in non-color mode - Code clean up Version 0.5 (2013-02-18) - Support read output from ``svn diff --log`` and ``hg log -p`` - Streamline reading large patch set - New ``--log (-l)`` option to read revision control diff log (thanks to `Steven Myint`_) Version 0.4 (2013-02-16) - New option *-c WHEN* (*--color WHEN*) to support auto test - Auto regression test now on Travis Version 0.3 (2013-02-07) - Support compare two files (wrapper of diff) Version 0.2 (2013-02-06) - Move cdiff.py to top dir for better meta info management Version 0.1 (2013-02-05) - New --version option - setup.py now read version from source code Version 0.0.4 (2013-02-04) - Add CHANGES for history track and better versioning Version 0.0.3 (2013-02-04) - Publish on PyPI, supports read patch from file, pipe and diff output from revision tools (thanks to `Steven Myint`_) .. _Steven Myint: https://github.com/myint .. vim:set ft=rst et sw=4 sts=4 tw=79: cdiff-1.0/LICENSE0000644000076600000240000000306213031166611014102 0ustar ymattwstaff00000000000000Software License Agreement (BSD-3 License) Copyright (c) 2013, Matthew Wang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of cdiff nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cdiff-1.0/Makefile0000644000076600000240000000245413031166611014541 0ustar ymattwstaff00000000000000# Makefile for testing TESTPYPI = pypitest PYPI = pypi .PHONY: dogfood lint doc-check doc-preview clean build dist-test dist \ test test3 cov cov3 html reg reg3 profile profile3 dogfood: ./cdiff.py git diff | ./cdiff.py -s lint: pep8 --ignore=E203 *.py tests/*.py doc-check: ./setup.py --long-description | rst2html.py --strict > /dev/null doc-preview: ./setup.py --long-description | rst2html.py --strict > output.html python -m webbrowser -n "file://$(shell pwd)/output.html" sleep 1 rm -f output.html test: lint doc-check cov reg test3: lint doc-check cov3 reg3 cov: coverage run tests/test_cdiff.py coverage report --show-missing cov3: python3 `which coverage` run tests/test_cdiff.py python3 `which coverage` report --show-missing html: coverage html python -m webbrowser -n "file://$(shell pwd)/htmlcov/index.html" reg: tests/regression.sh reg3: PYTHON=python3 tests/regression.sh profile: tests/profile.sh profile.tmp profile3: tests/profile.sh profile3.tmp clean: rm -f MANIFEST profile*.tmp* .coverage rm -rf build/ cdiff.egg-info/ dist/ __pycache__/ htmlcov/ build: ./setup.py build sdist dist-test: ./setup.py build sdist register upload -r $(TESTPYPI) rm -f ~/.pypirc dist: ./setup.py build sdist register upload -r $(PYPI) rm -f ~/.pypirc # vim:set noet ts=8 sw=8: cdiff-1.0/PKG-INFO0000644000076600000240000003212113031633112014163 0ustar ymattwstaff00000000000000Metadata-Version: 1.1 Name: cdiff Version: 1.0 Summary: View colored, incremental diff in a workspace or from stdin, with side by side and auto pager support Home-page: https://github.com/ymattw/cdiff Author: Matthew Wang Author-email: mattwyl(@)gmail(.)com License: BSD-3 Description: Cdiff ===== .. image:: https://travis-ci.org/ymattw/cdiff.png?branch=master :target: https://travis-ci.org/ymattw/cdiff :alt: Build status Term based tool to view *colored*, *incremental* diff in a *Git/Mercurial/Svn* workspace or from stdin, with *side by side* and *auto pager* support. Requires python (>= 2.5.0) and ``less``. .. image:: https://raw.github.com/ymattw/cdiff/gh-pages/img/default.png :alt: default :align: center .. image:: https://raw.github.com/ymattw/cdiff/gh-pages/img/side-by-side.png :alt: side by side :align: center :width: 900 px Installation ------------ Install with pip ~~~~~~~~~~~~~~~~ Cdiff is already listed on `PyPI`_, you can install with ``pip`` if you have the tool. .. _PyPI: http://pypi.python.org/pypi/cdiff .. code-block:: bash pip install --upgrade cdiff Install with setup.py ~~~~~~~~~~~~~~~~~~~~~ You can also run the setup.py from the source if you don't have ``pip``. .. code-block:: bash git clone https://github.com/ymattw/cdiff.git cd cdiff ./setup.py install Install with Homebrew ~~~~~~~~~~~~~~~~~~~~~ You can also install with Homebrew on Mac. (Thanks to `@josa42`_, `@bfontaine`_, `@hivehand`_ and `@nijikon`_ for contributing to the Homebrew `Formula`_). .. _`@josa42`: https://github.com/josa42 .. _`@bfontaine`: https://github.com/bfontaine .. _`@hivehand`: https://github.com/hivehand .. _`@nijikon`: https://github.com/nijikon .. _`Formula`: https://github.com/Homebrew/homebrew-core/blob/master/Formula/cdiff.rb .. code-block:: bash brew install cdiff Download directly ~~~~~~~~~~~~~~~~~ Just save `cdiff.py`_ to whatever directory which is in your ``$PATH``, for example, ``$HOME/bin`` is in my ``$PATH``, so I save the script there and name as ``cdiff``. .. _`cdiff.py`: https://raw.github.com/ymattw/cdiff/master/cdiff.py .. code-block:: bash curl -ksSL https://raw.github.com/ymattw/cdiff/master/cdiff.py > ~/bin/cdiff chmod +x ~/bin/cdiff Usage ----- Type ``cdiff -h`` to show usage:: $ cdiff -h Usage: cdiff [options] [file|dir ...] View colored, incremental diff in a workspace or from stdin, with side by side and auto pager support Options: --version show program's version number and exit -h, --help show this help message and exit -s, --side-by-side enable side-by-side mode -w N, --width=N set text width for side-by-side mode, 0 for auto detection, default is 80 -l, --log show log with changes from revision control -c M, --color=M colorize mode 'auto' (default), 'always', or 'never' Note: Option parser will stop on first unknown option and pass them down to underneath revision control. Environment variable CDIFF_OPTIONS may be used to specify default options that will be placed at the beginning of the argument list. Read diff from local modification in a *Git/Mercurial/Svn* workspace (output from e.g. ``git diff``, ``svn diff``): .. code-block:: bash cd proj-workspace cdiff # view colored incremental diff cdiff -s # view side by side, use default text width 80 cdiff -s -w 90 # use text width 90 other than default 80 cdiff -s -w 0 # auto set text width based on terminal size cdiff -s file1 dir2 # view modification of given files/dirs only cdiff -s -w90 -- -U10 # pass '-U10' to underneath revision diff tool cdiff -s -w90 -U10 # '--' is optional as it's unknown to cdiff cdiff -s --cached # show git staged diff (git diff --cached) cdiff -s -r1234 # show svn diff to revision 1234 Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g. ``git log -p``, ``svn log --diff``), note *--diff* option is new in svn 1.7.0: .. code-block:: bash cd proj-workspace cdiff -l # read log along with changes cdiff -ls # equivalent to cdiff -l -s, view side by side cdiff -ls -w90 # set text width 90 as well cdiff -ls file1 dir2 # see log with changes of given files/dirs only Environment variable ``CDIFF_OPTIONS`` may be used to specify default options that will be placed at the beginning of the argument list, for example: .. code-block:: bash export CDIFF_OPTIONS='-s -w0' cdiff foo # equivalent to "cdiff -s -w0 foo" If you feel more comfortable with a command such as ``git cdiff`` to trigger the cdiff command, you may symlink the executable to one named ``git-cdiff`` as follows: .. code-block:: bash cdiff_dir=$(dirname $(which cdiff)) ln -s "${cdiff_dir}/cdiff" "${cdiff_dir}/git-cdiff" Pipe in a diff: .. code-block:: bash git log -p -2 | cdiff # view git log with changes of last 2 commits git show 15bfa | cdiff -s # view a given git commit, side by side svn diff -r1234 | cdiff -s # view svn diff comparing to given revision diff -u file1 file2 | cdiff # view diff between two files (note the '-u') diff -ur dir1 dir2 | cdiff # view diff between two dirs # View diff in a GitHub pull request, side by side curl https://github.com/ymattw/cdiff/pull/11.diff | cdiff -s # View a patch file in unified or context format, the latter depends on # command `filterdiff` from package `patchutils` which is available in # major Linux distros and MacPorts. # cdiff -s < foo.patch Redirect output to another patch file is safe: .. code-block:: bash svn diff -r PREV | cdiff -s > my.patch Notes ----- Cdiff has following known issues: - Does not recognize `normal` diff, and depends on ``filterdiff`` (patchutils) to read `context` diff - Side by side mode has alignment problem for wide chars - Terminal might be in a mess on exception (type ``reset`` can fix it) Pull requests are very welcome, please make sure your changes can pass unit tests and regression tests by run ``make test`` (required tool *coverage* can be installed with ``pip install coverage``). Also watch out `travis build`_ after push, make sure it passes as well. .. _`travis build`: https://travis-ci.org/ymattw/cdiff/pull_requests See also -------- I have another tool `coderev`_ which generates side-by-side diff pages for code review from two given files or directories, I found it's not easy to extend to support git so invented `cdiff`. Idea of ansi color markup is also from project `colordiff`_. .. _coderev: https://github.com/ymattw/coderev .. _colordiff: https://github.com/daveewart/colordiff .. vim:set ft=rst et sw=4 sts=4 tw=79: Change log ========== Version 1.0 (2016-12-31) - Use environment variable ``CDIFF_OPTIONS`` to hold default options Version 0.9.8 (2016-01-16) - More robust parser to tolerate evil unified diff Version 0.9.7 (2015-04-24) - Fix unexpected side-by-side output for diff of diff - Better color to work with solarized color scheme Version 0.9.6 (2014-06-20) - Fix TypeError exception in auto width logic Version 0.9.5 (2014-06-19) - Option ``--width 0`` now fits terminal size automatically - Enable smooth horizontal scrolling with less option ``--shift 1`` Version 0.9.4 (2014-06-04) - Respect the ``LESS`` environment variable - Support python 3.4 - Fix curl options in document Version 0.9.3 (2013-09-28) - Moved screenshots to 'gh-pages' branch - Handle all keyboard interrupts more completely - Explicitly set default encoding to utf-8 - Fixed broken output diff when I/O with filterdiff in nonblocking mode Version 0.9.2 (2013-06-21) - Enahanced option parser now pass unknown option to underneath revision control, user can use ``cdiff --cached``, ``cdiff -U5`` directly Version 0.9.1 (2013-05-20) - Use ``--no-ext-diff`` to disable GIT_EXTERNAL_DIFF and diff.external which might break cdiff output Version 0.9 (2013-03-23) - Supports reading context diff via ``filterdiff`` (patchutils) - Fixed a diff parser bug which misread git commit message as common line - Lots of code refactor Version 0.8 (2013-03-13) - Parser is now robust enough to handle dangling headers and short patch - PEP8 (with minor own flavors) and other code lint - Change 'Development Status' to stable Version 0.7.1 (2013-02-25) - Handle 'Binary files ... differ' - Document update for known issues Version 0.7 (2013-02-23) - Support reading diff or log for given files/dirs in workspace - Support diff generated from ``diff -ru dir1 dir2`` - Usage change: reading a patch and comparing two files need stdin redirect Version 0.6 (2013-02-20) - A few performance tuning and code clean up - Add unit test cases with coverage 70% - Show merge history in svn log Version 0.5.1 (2013-02-19) - Fixed incorrect yield on diff missing eof - Fixed a bug in diff format probe - Handle keyboard interrupt and large diffs in non-color mode - Code clean up Version 0.5 (2013-02-18) - Support read output from ``svn diff --log`` and ``hg log -p`` - Streamline reading large patch set - New ``--log (-l)`` option to read revision control diff log (thanks to `Steven Myint`_) Version 0.4 (2013-02-16) - New option *-c WHEN* (*--color WHEN*) to support auto test - Auto regression test now on Travis Version 0.3 (2013-02-07) - Support compare two files (wrapper of diff) Version 0.2 (2013-02-06) - Move cdiff.py to top dir for better meta info management Version 0.1 (2013-02-05) - New --version option - setup.py now read version from source code Version 0.0.4 (2013-02-04) - Add CHANGES for history track and better versioning Version 0.0.3 (2013-02-04) - Publish on PyPI, supports read patch from file, pipe and diff output from revision tools (thanks to `Steven Myint`_) .. _Steven Myint: https://github.com/myint .. vim:set ft=rst et sw=4 sts=4 tw=79: Keywords: colored incremental side-by-side diff Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Topic :: Utilities Classifier: License :: OSI Approved :: BSD License Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: POSIX Classifier: Operating System :: Unix Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 cdiff-1.0/README.rst0000644000076600000240000001506213031363123014564 0ustar ymattwstaff00000000000000Cdiff ===== .. image:: https://travis-ci.org/ymattw/cdiff.png?branch=master :target: https://travis-ci.org/ymattw/cdiff :alt: Build status Term based tool to view *colored*, *incremental* diff in a *Git/Mercurial/Svn* workspace or from stdin, with *side by side* and *auto pager* support. Requires python (>= 2.5.0) and ``less``. .. image:: https://raw.github.com/ymattw/cdiff/gh-pages/img/default.png :alt: default :align: center .. image:: https://raw.github.com/ymattw/cdiff/gh-pages/img/side-by-side.png :alt: side by side :align: center :width: 900 px Installation ------------ Install with pip ~~~~~~~~~~~~~~~~ Cdiff is already listed on `PyPI`_, you can install with ``pip`` if you have the tool. .. _PyPI: http://pypi.python.org/pypi/cdiff .. code-block:: bash pip install --upgrade cdiff Install with setup.py ~~~~~~~~~~~~~~~~~~~~~ You can also run the setup.py from the source if you don't have ``pip``. .. code-block:: bash git clone https://github.com/ymattw/cdiff.git cd cdiff ./setup.py install Install with Homebrew ~~~~~~~~~~~~~~~~~~~~~ You can also install with Homebrew on Mac. (Thanks to `@josa42`_, `@bfontaine`_, `@hivehand`_ and `@nijikon`_ for contributing to the Homebrew `Formula`_). .. _`@josa42`: https://github.com/josa42 .. _`@bfontaine`: https://github.com/bfontaine .. _`@hivehand`: https://github.com/hivehand .. _`@nijikon`: https://github.com/nijikon .. _`Formula`: https://github.com/Homebrew/homebrew-core/blob/master/Formula/cdiff.rb .. code-block:: bash brew install cdiff Download directly ~~~~~~~~~~~~~~~~~ Just save `cdiff.py`_ to whatever directory which is in your ``$PATH``, for example, ``$HOME/bin`` is in my ``$PATH``, so I save the script there and name as ``cdiff``. .. _`cdiff.py`: https://raw.github.com/ymattw/cdiff/master/cdiff.py .. code-block:: bash curl -ksSL https://raw.github.com/ymattw/cdiff/master/cdiff.py > ~/bin/cdiff chmod +x ~/bin/cdiff Usage ----- Type ``cdiff -h`` to show usage:: $ cdiff -h Usage: cdiff [options] [file|dir ...] View colored, incremental diff in a workspace or from stdin, with side by side and auto pager support Options: --version show program's version number and exit -h, --help show this help message and exit -s, --side-by-side enable side-by-side mode -w N, --width=N set text width for side-by-side mode, 0 for auto detection, default is 80 -l, --log show log with changes from revision control -c M, --color=M colorize mode 'auto' (default), 'always', or 'never' Note: Option parser will stop on first unknown option and pass them down to underneath revision control. Environment variable CDIFF_OPTIONS may be used to specify default options that will be placed at the beginning of the argument list. Read diff from local modification in a *Git/Mercurial/Svn* workspace (output from e.g. ``git diff``, ``svn diff``): .. code-block:: bash cd proj-workspace cdiff # view colored incremental diff cdiff -s # view side by side, use default text width 80 cdiff -s -w 90 # use text width 90 other than default 80 cdiff -s -w 0 # auto set text width based on terminal size cdiff -s file1 dir2 # view modification of given files/dirs only cdiff -s -w90 -- -U10 # pass '-U10' to underneath revision diff tool cdiff -s -w90 -U10 # '--' is optional as it's unknown to cdiff cdiff -s --cached # show git staged diff (git diff --cached) cdiff -s -r1234 # show svn diff to revision 1234 Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g. ``git log -p``, ``svn log --diff``), note *--diff* option is new in svn 1.7.0: .. code-block:: bash cd proj-workspace cdiff -l # read log along with changes cdiff -ls # equivalent to cdiff -l -s, view side by side cdiff -ls -w90 # set text width 90 as well cdiff -ls file1 dir2 # see log with changes of given files/dirs only Environment variable ``CDIFF_OPTIONS`` may be used to specify default options that will be placed at the beginning of the argument list, for example: .. code-block:: bash export CDIFF_OPTIONS='-s -w0' cdiff foo # equivalent to "cdiff -s -w0 foo" If you feel more comfortable with a command such as ``git cdiff`` to trigger the cdiff command, you may symlink the executable to one named ``git-cdiff`` as follows: .. code-block:: bash cdiff_dir=$(dirname $(which cdiff)) ln -s "${cdiff_dir}/cdiff" "${cdiff_dir}/git-cdiff" Pipe in a diff: .. code-block:: bash git log -p -2 | cdiff # view git log with changes of last 2 commits git show 15bfa | cdiff -s # view a given git commit, side by side svn diff -r1234 | cdiff -s # view svn diff comparing to given revision diff -u file1 file2 | cdiff # view diff between two files (note the '-u') diff -ur dir1 dir2 | cdiff # view diff between two dirs # View diff in a GitHub pull request, side by side curl https://github.com/ymattw/cdiff/pull/11.diff | cdiff -s # View a patch file in unified or context format, the latter depends on # command `filterdiff` from package `patchutils` which is available in # major Linux distros and MacPorts. # cdiff -s < foo.patch Redirect output to another patch file is safe: .. code-block:: bash svn diff -r PREV | cdiff -s > my.patch Notes ----- Cdiff has following known issues: - Does not recognize `normal` diff, and depends on ``filterdiff`` (patchutils) to read `context` diff - Side by side mode has alignment problem for wide chars - Terminal might be in a mess on exception (type ``reset`` can fix it) Pull requests are very welcome, please make sure your changes can pass unit tests and regression tests by run ``make test`` (required tool *coverage* can be installed with ``pip install coverage``). Also watch out `travis build`_ after push, make sure it passes as well. .. _`travis build`: https://travis-ci.org/ymattw/cdiff/pull_requests See also -------- I have another tool `coderev`_ which generates side-by-side diff pages for code review from two given files or directories, I found it's not easy to extend to support git so invented `cdiff`. Idea of ansi color markup is also from project `colordiff`_. .. _coderev: https://github.com/ymattw/coderev .. _colordiff: https://github.com/daveewart/colordiff .. vim:set ft=rst et sw=4 sts=4 tw=79: cdiff-1.0/setup.py0000755000076600000240000000244413031166611014615 0ustar ymattwstaff00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import with_statement import sys from distutils.core import setup from cdiff import META_INFO as _meta if sys.hexversion < 0x02050000: raise SystemExit("*** Requires python >= 2.5.0") with open('README.rst') as doc: long_description = doc.read() with open('CHANGES.rst') as changes: long_description += changes.read() setup( name='cdiff', version=_meta['version'], author=_meta['author'], author_email=_meta['email'], license=_meta['license'], description=_meta['description'], long_description=long_description, keywords=_meta['keywords'], url=_meta['url'], # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 5 - Production/Stable', 'Topic :: Utilities', 'License :: OSI Approved :: BSD License', 'Environment :: Console', 'Intended Audience :: Developers', 'Operating System :: MacOS :: MacOS X', 'Operating System :: POSIX', 'Operating System :: Unix', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', ], py_modules=['cdiff'], scripts=['cdiff'], ) # vim:set et sts=4 sw=4 tw=79: cdiff-1.0/tests/0000755000076600000240000000000013031633112014231 5ustar ymattwstaff00000000000000cdiff-1.0/tests/context/0000755000076600000240000000000013031633112015715 5ustar ymattwstaff00000000000000cdiff-1.0/tests/context/in.diff0000644000076600000240000000406113031166611017163 0ustar ymattwstaff00000000000000*** a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 --- b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 *************** *** 467,472 **** --- 467,479 ---- dom.unlink() self.confirm(domstr == str.replace("\n", "\r\n")) + def testPrettyTextNode(self): + str = 'B' + dom = parseString(str) + dom2 = parseString(dom.toprettyxml()) + self.confirm(dom.childNodes[0].childNodes[0].toxml()== + dom2.childNodes[0].childNodes[0].toxml()) + def testProcessingInstruction(self): dom = parseString('') pi = dom.documentElement.firstChild *** a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 --- b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 *************** *** 836,842 **** _write_data(writer, attrs[a_name].value) writer.write("\"") if self.childNodes: ! writer.write(">%s"%(newl)) for node in self.childNodes: node.writexml(writer,indent+addindent,addindent,newl) writer.write("%s%s" % (indent,self.tagName,newl)) --- 836,844 ---- _write_data(writer, attrs[a_name].value) writer.write("\"") if self.childNodes: ! writer.write(">") ! if self.childNodes[0].nodeType != Node.TEXT_NODE: # Strict check ! writer.write(newl) for node in self.childNodes: node.writexml(writer,indent+addindent,addindent,newl) writer.write("%s%s" % (indent,self.tagName,newl)) *************** *** 1061,1067 **** return newText def writexml(self, writer, indent="", addindent="", newl=""): ! _write_data(writer, "%s%s%s"%(indent, self.data, newl)) # DOM Level 3 (WD 9 April 2002) --- 1063,1069 ---- return newText def writexml(self, writer, indent="", addindent="", newl=""): ! _write_data(writer, self.data) # DOM Level 3 (WD 9 April 2002) cdiff-1.0/tests/context/out.normal0000644000076600000240000000367013031166611017751 0ustar ymattwstaff00000000000000--- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@  dom.unlink()  self.confirm(domstr == str.replace("\n", "\r\n")) + + def testPrettyTextNode(self): + str = 'B' + dom = parseString(str) + dom2 = parseString(dom.toprettyxml()) + self.confirm(dom.childNodes[0].childNodes[0].toxml()== + dom2.childNodes[0].childNodes[0].toxml())   def testProcessingInstruction(self):  dom = parseString('')  pi = dom.documentElement.firstChild --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  _write_data(writer, attrs[a_name].value)  writer.write("\"")  if self.childNodes: - writer.write(">%s"%(newl)) + writer.write(">") + if self.childNodes[0].nodeType != Node.TEXT_NODE: # Strict check + writer.write(newl)  for node in self.childNodes:  node.writexml(writer,indent+addindent,addindent,newl)  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@  return newText   def writexml(self, writer, indent="", addindent="", newl=""): - _write_data(writer, "%s%s%s"%(indent, self.data, newl)) + _write_data(writer, self.data)   # DOM Level 3 (WD 9 April 2002)   cdiff-1.0/tests/context/out.side-by-side0000644000076600000240000001211413031166611020730 0ustar ymattwstaff00000000000000--- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@ 467  dom.unlink() 467  dom.unlink() 468  self.confirm(domstr == str.replace("\n", "\r\n")) 468  self.confirm(domstr == str.replace("\n", "\r\n"))   469    470  def testPrettyTextNode(self):   471  str = 'B'   472  dom = parseString(str)   473  dom2 = parseString(dom.toprettyxml())   474  self.confirm(dom.childNodes[0].childNodes[0].toxml()==   475  dom2.childNodes[0].childNodes[0].toxml()) 469  476  470  def testProcessingInstruction(self): 477  def testProcessingInstruction(self): 471  dom = parseString('') 478  dom = parseString('') 472  pi = dom.documentElement.firstChild 479  pi = dom.documentElement.firstChild --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  836  _write_data(writer, attrs[a_name].value)  836  _write_data(writer, attrs[a_name].value)  837  writer.write("\"")  837  writer.write("\"")  838  if self.childNodes:  838  if self.childNodes:  839  writer.write(">%s"%(newl))  839  writer.write(">")    840  if self.childNodes[0].nodeType != Node.TEXT_NODE: # Strict check    841  writer.write(newl)  840  for node in self.childNodes:  842  for node in self.childNodes:  841  node.writexml(writer,indent+addindent,addindent,newl)  843  node.writexml(writer,indent+addindent,addindent,newl)  842  writer.write("%s%s" % (indent,self.tagName,newl))  844  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@ 1061  return newText 1063  return newText 1062  1064  1063  def writexml(self, writer, indent="", addindent="", newl=""): 1065  def writexml(self, writer, indent="", addindent="", newl=""): 1064  _write_data(writer, "%s%s%s"%(indent, self.data, newl)) 1066  _write_data(writer, self.data) 1065  1067  1066  # DOM Level 3 (WD 9 April 2002) 1068  # DOM Level 3 (WD 9 April 2002) 1067  1069  cdiff-1.0/tests/context/out.w700000644000076600000240000001145313031166611017074 0ustar ymattwstaff00000000000000--- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@ 467  dom.unlink() 467  dom.unlink() 468  self.confirm(domstr == str.replace("\n", "\r\n")) 468  self.confirm(domstr == str.replace("\n", "\r\n"))   469    470  def testPrettyTextNode(self):   471  str = 'B'   472  dom = parseString(str)   473  dom2 = parseString(dom.toprettyxml())   474  self.confirm(dom.childNodes[0].childNodes[0].toxml()==   475  dom2.childNodes[0].childNodes[0].toxml()) 469  476  470  def testProcessingInstruction(self): 477  def testProcessingInstruction(self): 471  dom = parseString('') 478  dom = parseString('') 472  pi = dom.documentElement.firstChild 479  pi = dom.documentElement.firstChild --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  836  _write_data(writer, attrs[a_name].value)  836  _write_data(writer, attrs[a_name].value)  837  writer.write("\"")  837  writer.write("\"")  838  if self.childNodes:  838  if self.childNodes:  839  writer.write(">%s"%(newl))  839  writer.write(">")    840  if self.childNodes[0].nodeType != Node.TEXT_NODE: # S>    841  writer.write(newl)  840  for node in self.childNodes:  842  for node in self.childNodes:  841  node.writexml(writer,indent+addindent,addindent,newl)  843  node.writexml(writer,indent+addindent,addindent,newl)  842  writer.write("%s%s" % (indent,self.tagName,newl))  844  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@ 1061  return newText 1063  return newText 1062  1064  1063  def writexml(self, writer, indent="", addindent="", newl=""): 1065  def writexml(self, writer, indent="", addindent="", newl=""): 1064  _write_data(writer, "%s%s%s"%(indent, self.data, newl)) 1066  _write_data(writer, self.data) 1065  1067  1066  # DOM Level 3 (WD 9 April 2002) 1068  # DOM Level 3 (WD 9 April 2002) 1067  1069  cdiff-1.0/tests/crlf/0000755000076600000240000000000013031633112015157 5ustar ymattwstaff00000000000000cdiff-1.0/tests/crlf/in.diff0000644000076600000240000000202113031166611016417 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@ ## About Coderev is a toolkit generates static side-by-side html pages for code review. -Typical use case is to generate diff pages for local modification in svn/cvs workspace and send page link to teammates for code review. See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo. @@ -18,9 +17,10 @@ ## Usage of coderev.sh -Just type `./coderev.sh -h` to see the usage. +Just type `./coderev.sh --help` to see the usage. Usage: + coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \ [-F comment-file | -m 'comment...'] [file...] @@ -145,3 +145,5 @@ specify column number where lines are broken and wrapped for sdiff, default is no line wrapping -y, --yes do not prompt for overwriting + +# EOF cdiff-1.0/tests/crlf/out.normal0000644000076600000240000000251713031166611017212 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@  ## About   Coderev is a toolkit generates static side-by-side html pages for code review. -Typical use case is to generate diff pages for local modification in svn/cvs  workspace and send page link to teammates for code review.   See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo. @@ -18,9 +17,10 @@   ## Usage of coderev.sh  -Just type `./coderev.sh -h` to see the usage. +Just type `./coderev.sh --help` to see the usage.   Usage: +  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \  [-F comment-file | -m 'comment...'] [file...]  @@ -145,3 +145,5 @@  specify column number where lines are broken and  wrapped for sdiff, default is no line wrapping  -y, --yes do not prompt for overwriting + +# EOF  cdiff-1.0/tests/crlf/out.side-by-side0000644000076600000240000000724013031166611020176 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@  3 ## About  3 ## About  4   4   5 Coderev is a toolkit generates static side-by-side html pages for code review.  5 Coderev is a toolkit generates static side-by-side html pages for code review.  6 Typical use case is to generate diff pages for local modification in svn/cvs    7 workspace and send page link to teammates for code review.  6 workspace and send page link to teammates for code review.  8   7   9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.  8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo. @@ -18,9 +17,10 @@  18   17   19 ## Usage of coderev.sh  18 ## Usage of coderev.sh  20   19   21 Just type `./coderev.sh -h` to see the usage.  20 Just type `./coderev.sh --help` to see the usage.  22   21   23  Usage:  22  Usage:    23   24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \  24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \  25  [-F comment-file | -m 'comment...'] [file...]  25  [-F comment-file | -m 'comment...'] [file...]  26   26  @@ -145,3 +145,5 @@ 145  specify column number where lines are broken and 145  specify column number where lines are broken and 146  wrapped for sdiff, default is no line wrapping 146  wrapped for sdiff, default is no line wrapping 147  -y, --yes do not prompt for overwriting 147  -y, --yes do not prompt for overwriting   148    149 # EOF cdiff-1.0/tests/crlf/out.w700000644000076600000240000000704413031166611016337 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@  3 ## About  3 ## About  4   4   5 Coderev is a toolkit generates static side-by-side html pages for cod>  5 Coderev is a toolkit generates static side-by-side html pages for cod>  6 Typical use case is to generate diff pages for local modification in >    7 workspace and send page link to teammates for code review.  6 workspace and send page link to teammates for code review.  8   7   9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f>  8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f> @@ -18,9 +17,10 @@  18   17   19 ## Usage of coderev.sh  18 ## Usage of coderev.sh  20   19   21 Just type `./coderev.sh -h` to see the usage.  20 Just type `./coderev.sh --help` to see the usage.  22   21   23  Usage:  22  Usage:    23   24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>  24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>  25  [-F comment-file | -m 'comment...'] [file...]  25  [-F comment-file | -m 'comment...'] [file...]  26   26  @@ -145,3 +145,5 @@ 145  specify column number where lines are bro> 145  specify column number where lines are bro> 146  wrapped for sdiff, default is no line wra> 146  wrapped for sdiff, default is no line wra> 147  -y, --yes do not prompt for overwriting 147  -y, --yes do not prompt for overwriting   148    149 # EOF cdiff-1.0/tests/diff-of-diff/0000755000076600000240000000000013031633112016451 5ustar ymattwstaff00000000000000cdiff-1.0/tests/diff-of-diff/in.diff0000644000076600000240000000216513031166611017722 0ustar ymattwstaff00000000000000Index: patch-Alias.xs =================================================================== --- patch-Alias.xs (revision 384635) +++ patch-Alias.xs (revision 384636) @@ -140,17 +140,21 @@ tmp = kLISTOP->op_first; if (inside) op_null(tmp); -@@ -2001,6 +2035,9 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { +@@ -2001,6 +2035,13 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { while (kid->op_sibling != last) kid = kid->op_sibling; kid->op_sibling = Nullop; +#ifdef op_sibling_splice ++#if (PERL_COMBI_VERSION >= 5021011) ++ kid->op_moresib = 0; ++#else + kid->op_lastsib = 1; +#endif ++#endif cLISTOPx(cUNOPo->op_first)->op_last = kid; if (kid->op_type == OP_NULL && inside) kid->op_flags &= ~OPf_SPECIAL; -@@ -2008,6 +2045,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { +@@ -2008,6 +2049,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { return o; } @@ -165,7 +169,7 @@ MODULE = Data::Alias PACKAGE = Data::Alias -@@ -2025,6 +2070,10 @@ BOOT: +@@ -2025,6 +2074,10 @@ BOOT: PL_check[OP_RV2CV] = da_ck_rv2cv; da_old_ck_entersub = PL_check[OP_ENTERSUB]; PL_check[OP_ENTERSUB] = da_ck_entersub; cdiff-1.0/tests/diff-of-diff/out.normal0000644000076600000240000000313113031166611020475 0ustar ymattwstaff00000000000000Index: patch-Alias.xs =================================================================== --- patch-Alias.xs (revision 384635) +++ patch-Alias.xs (revision 384636) @@ -140,17 +140,21 @@  tmp = kLISTOP->op_first;  if (inside)  op_null(tmp); -@@ -2001,6 +2035,9 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { +@@ -2001,6 +2035,13 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) {  while (kid->op_sibling != last)  kid = kid->op_sibling;  kid->op_sibling = Nullop;  +#ifdef op_sibling_splice ++#if (PERL_COMBI_VERSION >= 5021011) ++ kid->op_moresib = 0; ++#else  + kid->op_lastsib = 1; ++#endif  +#endif  cLISTOPx(cUNOPo->op_first)->op_last = kid;  if (kid->op_type == OP_NULL && inside)  kid->op_flags &= ~OPf_SPECIAL; -@@ -2008,6 +2045,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { +@@ -2008,6 +2049,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) {  return o;  }  @@ -165,7 +169,7 @@   MODULE = Data::Alias PACKAGE = Data::Alias  -@@ -2025,6 +2070,10 @@ BOOT: +@@ -2025,6 +2074,10 @@ BOOT:  PL_check[OP_RV2CV] = da_ck_rv2cv;  da_old_ck_entersub = PL_check[OP_ENTERSUB];  PL_check[OP_ENTERSUB] = da_ck_entersub; cdiff-1.0/tests/diff-of-diff/out.side-by-side0000644000076600000240000001130113031166611021461 0ustar ymattwstaff00000000000000Index: patch-Alias.xs =================================================================== --- patch-Alias.xs (revision 384635) +++ patch-Alias.xs (revision 384636) @@ -140,17 +140,21 @@ 140  tmp = kLISTOP->op_first; 140  tmp = kLISTOP->op_first; 141  if (inside) 141  if (inside) 142  op_null(tmp); 142  op_null(tmp); 143 @@ -2001,6 +2035,9 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 143 @@ -2001,6 +2035,13 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 144  while (kid->op_sibling != last) 144  while (kid->op_sibling != last) 145  kid = kid->op_sibling; 145  kid = kid->op_sibling; 146  kid->op_sibling = Nullop; 146  kid->op_sibling = Nullop; 147 +#ifdef op_sibling_splice 147 +#ifdef op_sibling_splice   148 +#if (PERL_COMBI_VERSION >= 5021011)   149 + kid->op_moresib = 0;   150 +#else 148 + kid->op_lastsib = 1; 151 + kid->op_lastsib = 1;   152 +#endif 149 +#endif 153 +#endif 150  cLISTOPx(cUNOPo->op_first)->op_last = kid; 154  cLISTOPx(cUNOPo->op_first)->op_last = kid; 151  if (kid->op_type == OP_NULL && inside) 155  if (kid->op_type == OP_NULL && inside) 152  kid->op_flags &= ~OPf_SPECIAL; 156  kid->op_flags &= ~OPf_SPECIAL; 153 @@ -2008,6 +2045,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 157 @@ -2008,6 +2049,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 154  return o; 158  return o; 155  } 159  } 156   160   @@ -165,7 +169,7 @@ 165   169   166  MODULE = Data::Alias PACKAGE = Data::Alias 170  MODULE = Data::Alias PACKAGE = Data::Alias 167   171   168 @@ -2025,6 +2070,10 @@ BOOT: 172 @@ -2025,6 +2074,10 @@ BOOT: 169  PL_check[OP_RV2CV] = da_ck_rv2cv; 173  PL_check[OP_RV2CV] = da_ck_rv2cv; 170  da_old_ck_entersub = PL_check[OP_ENTERSUB]; 174  da_old_ck_entersub = PL_check[OP_ENTERSUB]; 171  PL_check[OP_ENTERSUB] = da_ck_entersub; 175  PL_check[OP_ENTERSUB] = da_ck_entersub; cdiff-1.0/tests/diff-of-diff/out.w700000644000076600000240000001065113031166611017627 0ustar ymattwstaff00000000000000Index: patch-Alias.xs =================================================================== --- patch-Alias.xs (revision 384635) +++ patch-Alias.xs (revision 384636) @@ -140,17 +140,21 @@ 140  tmp = kLISTOP->op_first; 140  tmp = kLISTOP->op_first; 141  if (inside) 141  if (inside) 142  op_null(tmp); 142  op_null(tmp); 143 @@ -2001,6 +2035,9 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 143 @@ -2001,6 +2035,13 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 144  while (kid->op_sibling != last) 144  while (kid->op_sibling != last) 145  kid = kid->op_sibling; 145  kid = kid->op_sibling; 146  kid->op_sibling = Nullop; 146  kid->op_sibling = Nullop; 147 +#ifdef op_sibling_splice 147 +#ifdef op_sibling_splice   148 +#if (PERL_COMBI_VERSION >= 5021011)   149 + kid->op_moresib = 0;   150 +#else 148 + kid->op_lastsib = 1; 151 + kid->op_lastsib = 1;   152 +#endif 149 +#endif 153 +#endif 150  cLISTOPx(cUNOPo->op_first)->op_last = kid; 154  cLISTOPx(cUNOPo->op_first)->op_last = kid; 151  if (kid->op_type == OP_NULL && inside) 155  if (kid->op_type == OP_NULL && inside) 152  kid->op_flags &= ~OPf_SPECIAL; 156  kid->op_flags &= ~OPf_SPECIAL; 153 @@ -2008,6 +2045,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 157 @@ -2008,6 +2049,14 @@ STATIC OP *da_ck_entersub(pTHX_ OP *o) { 154  return o; 158  return o; 155  } 159  } 156   160   @@ -165,7 +169,7 @@ 165   169   166  MODULE = Data::Alias PACKAGE = Data::Alias 170  MODULE = Data::Alias PACKAGE = Data::Alias 167   171   168 @@ -2025,6 +2070,10 @@ BOOT: 172 @@ -2025,6 +2074,10 @@ BOOT: 169  PL_check[OP_RV2CV] = da_ck_rv2cv; 173  PL_check[OP_RV2CV] = da_ck_rv2cv; 170  da_old_ck_entersub = PL_check[OP_ENTERSUB]; 174  da_old_ck_entersub = PL_check[OP_ENTERSUB]; 171  PL_check[OP_ENTERSUB] = da_ck_entersub; 175  PL_check[OP_ENTERSUB] = da_ck_entersub; cdiff-1.0/tests/diff-ru/0000755000076600000240000000000013031633112015565 5ustar ymattwstaff00000000000000cdiff-1.0/tests/diff-ru/in.diff0000644000076600000240000000135013031166611017031 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-22 20:26:43.000000000 +0800 +++ b/README 2013-02-22 20:27:51.000000000 +0800 @@ -1,6 +1,6 @@ -# To generate expected output, chdir to a subdir and use following command, then +# To generate expected output, cd to a subdir and use following command, then # review with `less -R` -# ../../cdiff.py -c always in.diff > out.normal ../../cdiff.py -c always -s in.diff > out.side-by-side ../../cdiff.py -c always -s in.diff -w70 > out.w70 +# EOF Only in a: a1 Only in b: b1 diff -ru a/common/foo.txt b/common/foo.txt --- a/common/foo.txt 2013-02-22 20:28:32.000000000 +0800 +++ b/common/foo.txt 2013-02-22 20:30:18.000000000 +0800 @@ -1 +1 @@ -Hello +world Only in b: date.txt Only in a: time.txt cdiff-1.0/tests/diff-ru/out.normal0000644000076600000240000000215113031166611017612 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-22 20:26:43.000000000 +0800 +++ b/README 2013-02-22 20:27:51.000000000 +0800 @@ -1,6 +1,6 @@ -# To generate expected output, chdir to a subdir and use following command, then +# To generate expected output, cd to a subdir and use following command, then  # review with `less -R` -#  ../../cdiff.py -c always in.diff > out.normal  ../../cdiff.py -c always -s in.diff > out.side-by-side  ../../cdiff.py -c always -s in.diff -w70 > out.w70 +# EOF Only in a: a1 Only in b: b1 diff -ru a/common/foo.txt b/common/foo.txt --- a/common/foo.txt 2013-02-22 20:28:32.000000000 +0800 +++ b/common/foo.txt 2013-02-22 20:30:18.000000000 +0800 @@ -1 +1 @@ -Hello +world Only in b: date.txt Only in a: time.txt  cdiff-1.0/tests/diff-ru/out.side-by-side0000644000076600000240000000341013031166611020577 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-22 20:26:43.000000000 +0800 +++ b/README 2013-02-22 20:27:51.000000000 +0800 @@ -1,6 +1,6 @@ 1 # To generate expected output, chdir to a subdir and use following command, then 1 # To generate expected output, cd to a subdir and use following command, then 2 # review with `less -R` 2 # review with `less -R` 3 #   4 ../../cdiff.py -c always in.diff > out.normal  3 ../../cdiff.py -c always in.diff > out.normal  5 ../../cdiff.py -c always -s in.diff > out.side-by-side 4 ../../cdiff.py -c always -s in.diff > out.side-by-side 6 ../../cdiff.py -c always -s in.diff -w70 > out.w70 5 ../../cdiff.py -c always -s in.diff -w70 > out.w70   6 # EOF Only in a: a1 Only in b: b1 diff -ru a/common/foo.txt b/common/foo.txt --- a/common/foo.txt 2013-02-22 20:28:32.000000000 +0800 +++ b/common/foo.txt 2013-02-22 20:30:18.000000000 +0800 @@ -1 +1 @@ 1 Hello 1 world Only in b: date.txt Only in a: time.txt  cdiff-1.0/tests/diff-ru/out.w700000644000076600000240000000332113031166611016737 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-22 20:26:43.000000000 +0800 +++ b/README 2013-02-22 20:27:51.000000000 +0800 @@ -1,6 +1,6 @@ 1 # To generate expected output, chdir to a subdir and use following co> 1 # To generate expected output, cd to a subdir and use following comma> 2 # review with `less -R` 2 # review with `less -R` 3 #   4 ../../cdiff.py -c always in.diff > out.normal  3 ../../cdiff.py -c always in.diff > out.normal  5 ../../cdiff.py -c always -s in.diff > out.side-by-side 4 ../../cdiff.py -c always -s in.diff > out.side-by-side 6 ../../cdiff.py -c always -s in.diff -w70 > out.w70 5 ../../cdiff.py -c always -s in.diff -w70 > out.w70   6 # EOF Only in a: a1 Only in b: b1 diff -ru a/common/foo.txt b/common/foo.txt --- a/common/foo.txt 2013-02-22 20:28:32.000000000 +0800 +++ b/common/foo.txt 2013-02-22 20:30:18.000000000 +0800 @@ -1 +1 @@ 1 Hello 1 world Only in b: date.txt Only in a: time.txt  cdiff-1.0/tests/diff-ru-bin/0000755000076600000240000000000013031633112016333 5ustar ymattwstaff00000000000000cdiff-1.0/tests/diff-ru-bin/in.diff0000644000076600000240000000130413031166611017576 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-23 19:51:41.000000000 +0800 +++ b/README 2013-02-23 19:52:06.000000000 +0800 @@ -1,6 +1,6 @@ -# To generate expected output, chdir to a subdir and use following command, then +# To generate expected output, cd to a subdir and use following command, then # review with `less -R` -# ../../cdiff.py -c always < in.diff > out.normal ../../cdiff.py -c always -s < in.diff > out.side-by-side ../../cdiff.py -c always -s < in.diff -w70 > out.w70 +# EOF Binary files a/foo.pdf and b/foo.pdf differ diff -ru a/foo.txt b/foo.txt --- a/foo.txt 2013-02-23 19:55:03.000000000 +0800 +++ b/foo.txt 2013-02-23 19:55:10.000000000 +0800 @@ -1,2 +1,2 @@ -Hello +hella world cdiff-1.0/tests/diff-ru-bin/out.normal0000644000076600000240000000177413031166611020372 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-23 19:51:41.000000000 +0800 +++ b/README 2013-02-23 19:52:06.000000000 +0800 @@ -1,6 +1,6 @@ -# To generate expected output, chdir to a subdir and use following command, then +# To generate expected output, cd to a subdir and use following command, then  # review with `less -R` -#  ../../cdiff.py -c always < in.diff > out.normal  ../../cdiff.py -c always -s < in.diff > out.side-by-side  ../../cdiff.py -c always -s < in.diff -w70 > out.w70 +# EOF Binary files a/foo.pdf and b/foo.pdf differ diff -ru a/foo.txt b/foo.txt --- a/foo.txt 2013-02-23 19:55:03.000000000 +0800 +++ b/foo.txt 2013-02-23 19:55:10.000000000 +0800 @@ -1,2 +1,2 @@ -Hello +hella  world  cdiff-1.0/tests/diff-ru-bin/out.side-by-side0000644000076600000240000000341413031166611021351 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-23 19:51:41.000000000 +0800 +++ b/README 2013-02-23 19:52:06.000000000 +0800 @@ -1,6 +1,6 @@ 1 # To generate expected output, chdir to a subdir and use following command, then 1 # To generate expected output, cd to a subdir and use following command, then 2 # review with `less -R` 2 # review with `less -R` 3 #   4 ../../cdiff.py -c always < in.diff > out.normal 3 ../../cdiff.py -c always < in.diff > out.normal 5 ../../cdiff.py -c always -s < in.diff > out.side-by-side 4 ../../cdiff.py -c always -s < in.diff > out.side-by-side 6 ../../cdiff.py -c always -s < in.diff -w70 > out.w70 5 ../../cdiff.py -c always -s < in.diff -w70 > out.w70   6 # EOF Binary files a/foo.pdf and b/foo.pdf differ diff -ru a/foo.txt b/foo.txt --- a/foo.txt 2013-02-23 19:55:03.000000000 +0800 +++ b/foo.txt 2013-02-23 19:55:10.000000000 +0800 @@ -1,2 +1,2 @@ 1 Hello 1 hella 2 world 2 world cdiff-1.0/tests/diff-ru-bin/out.w700000644000076600000240000000331313031166611017506 0ustar ymattwstaff00000000000000diff -ru a/README b/README --- a/README 2013-02-23 19:51:41.000000000 +0800 +++ b/README 2013-02-23 19:52:06.000000000 +0800 @@ -1,6 +1,6 @@ 1 # To generate expected output, chdir to a subdir and use following co> 1 # To generate expected output, cd to a subdir and use following comma> 2 # review with `less -R` 2 # review with `less -R` 3 #   4 ../../cdiff.py -c always < in.diff > out.normal 3 ../../cdiff.py -c always < in.diff > out.normal 5 ../../cdiff.py -c always -s < in.diff > out.side-by-side 4 ../../cdiff.py -c always -s < in.diff > out.side-by-side 6 ../../cdiff.py -c always -s < in.diff -w70 > out.w70 5 ../../cdiff.py -c always -s < in.diff -w70 > out.w70   6 # EOF Binary files a/foo.pdf and b/foo.pdf differ diff -ru a/foo.txt b/foo.txt --- a/foo.txt 2013-02-23 19:55:03.000000000 +0800 +++ b/foo.txt 2013-02-23 19:55:10.000000000 +0800 @@ -1,2 +1,2 @@ 1 Hello 1 hella 2 world 2 world cdiff-1.0/tests/evil-udiff/0000755000076600000240000000000013031633112016263 5ustar ymattwstaff00000000000000cdiff-1.0/tests/evil-udiff/in.diff0000644000076600000240000000064713031166611017537 0ustar ymattwstaff00000000000000--- evil.orig 2013-06-01 16:36:29.676003599 -0500 +++ evil.new 2013-06-01 16:36:28.280056137 -0500 @@ -1,12 +1,12 @@ blah blah blah -humbug +bah humbug one two three four five six --- vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500 +++ vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500 @@ -1,6 +1,6 @@ blah blah blah humbug one two three four five six -eight nine ten +seven eight nine ten zero cdiff-1.0/tests/evil-udiff/out.normal0000644000076600000240000000130613031166611020311 0ustar ymattwstaff00000000000000--- evil.orig 2013-06-01 16:36:29.676003599 -0500 +++ evil.new 2013-06-01 16:36:28.280056137 -0500 @@ -1,12 +1,12 @@  blah blah blah -humbug +bah humbug  one two three  four five six --- vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500 +++ vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500  @@ -1,6 +1,6 @@  blah blah blah  humbug  one two three  four five six -eight nine ten +seven eight nine ten  zero cdiff-1.0/tests/evil-udiff/out.side-by-side0000644000076600000240000000361613031166611021305 0ustar ymattwstaff00000000000000--- evil.orig 2013-06-01 16:36:29.676003599 -0500 +++ evil.new 2013-06-01 16:36:28.280056137 -0500 @@ -1,12 +1,12 @@  1 blah blah blah  1 blah blah blah  2 humbug  2 bah humbug  3 one two three  3 one two three  4 four five six  4 four five six  5 -- vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500  5 ++ vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500  6 @@ -1,6 +1,6 @@  6 @@ -1,6 +1,6 @@  7 blah blah blah  7 blah blah blah  8 humbug  8 humbug  9 one two three  9 one two three 10 four five six 10 four five six 11 eight nine ten 11 seven eight nine ten 12 zero 12 zero cdiff-1.0/tests/evil-udiff/out.w700000644000076600000240000000342613031166611017443 0ustar ymattwstaff00000000000000--- evil.orig 2013-06-01 16:36:29.676003599 -0500 +++ evil.new 2013-06-01 16:36:28.280056137 -0500 @@ -1,12 +1,12 @@  1 blah blah blah  1 blah blah blah  2 humbug  2 bah humbug  3 one two three  3 one two three  4 four five six  4 four five six  5 -- vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500  5 ++ vim73/src/ui.c 2013-06-01 14:48:45.012467754 -0500  6 @@ -1,6 +1,6 @@  6 @@ -1,6 +1,6 @@  7 blah blah blah  7 blah blah blah  8 humbug  8 humbug  9 one two three  9 one two three 10 four five six 10 four five six 11 eight nine ten 11 seven eight nine ten 12 zero 12 zero cdiff-1.0/tests/git/0000755000076600000240000000000013031633112015014 5ustar ymattwstaff00000000000000cdiff-1.0/tests/git/in.diff0000644000076600000240000000322313031166611016261 0ustar ymattwstaff00000000000000commit 15bfa564b9db08fb277a343a3d0a01d377800606 Author: Matthew Wang Date: Thu Jan 31 15:27:17 2013 +0800 Default width is now 80 diff --git a/src/cdiff.py b/src/cdiff.py index 13f725f..bf15ef1 100755 --- a/src/cdiff.py +++ b/src/cdiff.py @@ -128,9 +128,7 @@ class Diff(object): yield self._markup_common(' ' + old[1]) def markup_side_by_side(self, width): - """width of 0 means infinite width, None means auto detect. Returns a - generator - """ + """Returns a generator""" def _normalize(line): return line.replace('\t', ' ' * 8).replace('\n', '') @@ -147,7 +145,8 @@ class Diff(object): return markup # Setup line width and number width - if not width: width = 80 + if width <= 0: + width = 80 (start, offset) = self._hunks[-1].get_old_addr() max1 = start + offset - 1 (start, offset) = self._hunks[-1].get_new_addr() @@ -430,13 +429,10 @@ if __name__ == '__main__': parser = optparse.OptionParser(usage) parser.add_option('-s', '--side-by-side', action='store_true', help=('show in side-by-side mode')) - parser.add_option('-w', '--width', type='int', default=None, - help='set line width (side-by-side mode only)') + parser.add_option('-w', '--width', type='int', default=80, + help='set line width (side-by-side mode only), default is 80') opts, args = parser.parse_args() - if opts.width and opts.width < 0: - opts.width = 0 - if len(args) >= 1: diff_hdl = open(args[0], 'r') elif sys.stdin.isatty(): cdiff-1.0/tests/git/out.normal0000644000076600000240000000440513031166611017045 0ustar ymattwstaff00000000000000commit 15bfa564b9db08fb277a343a3d0a01d377800606 Author: Matthew Wang Date: Thu Jan 31 15:27:17 2013 +0800   Default width is now 80  diff --git a/src/cdiff.py b/src/cdiff.py index 13f725f..bf15ef1 100755 --- a/src/cdiff.py +++ b/src/cdiff.py @@ -128,9 +128,7 @@ class Diff(object):  yield self._markup_common(' ' + old[1])   def markup_side_by_side(self, width): - """width of 0 means infinite width, None means auto detect. Returns a + """Returns a generator""" - generator - """  def _normalize(line):  return line.replace('\t', ' ' * 8).replace('\n', '')  @@ -147,7 +145,8 @@ class Diff(object):  return markup   # Setup line width and number width - if not width: width = 80 + if width <= 0: + width = 80  (start, offset) = self._hunks[-1].get_old_addr()  max1 = start + offset - 1  (start, offset) = self._hunks[-1].get_new_addr() @@ -430,13 +429,10 @@ if __name__ == '__main__':  parser = optparse.OptionParser(usage)  parser.add_option('-s', '--side-by-side', action='store_true',  help=('show in side-by-side mode')) - parser.add_option('-w', '--width', type='int', default=None, + parser.add_option('-w', '--width', type='int', default=80, - help='set line width (side-by-side mode only)') + help='set line width (side-by-side mode only), default is 80')  opts, args = parser.parse_args() - - if opts.width and opts.width < 0: - opts.width = 0   if len(args) >= 1:  diff_hdl = open(args[0], 'r')  elif sys.stdin.isatty():  cdiff-1.0/tests/git/out.side-by-side0000644000076600000240000001167013031166611020035 0ustar ymattwstaff00000000000000commit 15bfa564b9db08fb277a343a3d0a01d377800606 Author: Matthew Wang Date: Thu Jan 31 15:27:17 2013 +0800   Default width is now 80  diff --git a/src/cdiff.py b/src/cdiff.py index 13f725f..bf15ef1 100755 --- a/src/cdiff.py +++ b/src/cdiff.py @@ -128,9 +128,7 @@ class Diff(object): 128  yield self._markup_common(' ' + old[1]) 128  yield self._markup_common(' ' + old[1]) 129  129  130  def markup_side_by_side(self, width): 130  def markup_side_by_side(self, width): 131  """width of 0 means infinite width, None means auto detect. Returns a 131  """Returns a generator""" 132  generator   133  """   134  def _normalize(line): 132  def _normalize(line): 135  return line.replace('\t', ' ' * 8).replace('\n', '') 133  return line.replace('\t', ' ' * 8).replace('\n', '') 136  134  @@ -147,7 +145,8 @@ class Diff(object): 147  return markup 145  return markup 148  146  149  # Setup line width and number width 147  # Setup line width and number width 150  if not width: width = 80 148  if width <= 0:   149  width = 80 151  (start, offset) = self._hunks[-1].get_old_addr() 150  (start, offset) = self._hunks[-1].get_old_addr() 152  max1 = start + offset - 1 151  max1 = start + offset - 1 153  (start, offset) = self._hunks[-1].get_new_addr() 152  (start, offset) = self._hunks[-1].get_new_addr() @@ -430,13 +429,10 @@ if __name__ == '__main__': 430  parser = optparse.OptionParser(usage) 429  parser = optparse.OptionParser(usage) 431  parser.add_option('-s', '--side-by-side', action='store_true', 430  parser.add_option('-s', '--side-by-side', action='store_true', 432  help=('show in side-by-side mode')) 431  help=('show in side-by-side mode')) 433  parser.add_option('-w', '--width', type='int', default=None, 432  parser.add_option('-w', '--width', type='int', default=80, 434  help='set line width (side-by-side mode only)') 433  help='set line width (side-by-side mode only), default is 80') 435  opts, args = parser.parse_args() 434  opts, args = parser.parse_args() 436    437  if opts.width and opts.width < 0:   438  opts.width = 0   439  435  440  if len(args) >= 1: 436  if len(args) >= 1: 441  diff_hdl = open(args[0], 'r') 437  diff_hdl = open(args[0], 'r') 442  elif sys.stdin.isatty(): 438  elif sys.stdin.isatty(): cdiff-1.0/tests/git/out.w700000644000076600000240000001127613031166611016176 0ustar ymattwstaff00000000000000commit 15bfa564b9db08fb277a343a3d0a01d377800606 Author: Matthew Wang Date: Thu Jan 31 15:27:17 2013 +0800   Default width is now 80  diff --git a/src/cdiff.py b/src/cdiff.py index 13f725f..bf15ef1 100755 --- a/src/cdiff.py +++ b/src/cdiff.py @@ -128,9 +128,7 @@ class Diff(object): 128  yield self._markup_common(' ' + old[1]) 128  yield self._markup_common(' ' + old[1]) 129  129  130  def markup_side_by_side(self, width): 130  def markup_side_by_side(self, width): 131  """width of 0 means infinite width, None means auto detect. R> 131  """Returns a generator""" 132  generator   133  """   134  def _normalize(line): 132  def _normalize(line): 135  return line.replace('\t', ' ' * 8).replace('\n', '') 133  return line.replace('\t', ' ' * 8).replace('\n', '') 136  134  @@ -147,7 +145,8 @@ class Diff(object): 147  return markup 145  return markup 148  146  149  # Setup line width and number width 147  # Setup line width and number width 150  if not width: width = 80 148  if width <= 0:   149  width = 80 151  (start, offset) = self._hunks[-1].get_old_addr() 150  (start, offset) = self._hunks[-1].get_old_addr() 152  max1 = start + offset - 1 151  max1 = start + offset - 1 153  (start, offset) = self._hunks[-1].get_new_addr() 152  (start, offset) = self._hunks[-1].get_new_addr() @@ -430,13 +429,10 @@ if __name__ == '__main__': 430  parser = optparse.OptionParser(usage) 429  parser = optparse.OptionParser(usage) 431  parser.add_option('-s', '--side-by-side', action='store_true', 430  parser.add_option('-s', '--side-by-side', action='store_true', 432  help=('show in side-by-side mode')) 431  help=('show in side-by-side mode')) 433  parser.add_option('-w', '--width', type='int', default=None, 432  parser.add_option('-w', '--width', type='int', default=80, 434  help='set line width (side-by-side mode only)') 433  help='set line width (side-by-side mode only), default is> 435  opts, args = parser.parse_args() 434  opts, args = parser.parse_args() 436    437  if opts.width and opts.width < 0:   438  opts.width = 0   439  435  440  if len(args) >= 1: 436  if len(args) >= 1: 441  diff_hdl = open(args[0], 'r') 437  diff_hdl = open(args[0], 'r') 442  elif sys.stdin.isatty(): 438  elif sys.stdin.isatty(): cdiff-1.0/tests/git-bin/0000755000076600000240000000000013031633112015562 5ustar ymattwstaff00000000000000cdiff-1.0/tests/git-bin/in.diff0000644000076600000240000000117113031166611017027 0ustar ymattwstaff00000000000000diff --git a/2pdf.sh b/2pdf.sh index 529d8a3..ad71911 100755 --- a/2pdf.sh +++ b/2pdf.sh @@ -13,3 +13,5 @@ INPUT=${1:-foo.html} OUTPUT=${INPUT%.html}.pdf wkhtmltopdf --page-size A4 $INPUT $OUTPUT # very very long comments ends here + +# EOF diff --git a/example.pdf b/example.pdf index 1eacfd8..3696851 100644 Binary files a/example.pdf and b/example.pdf differ diff --git a/foo.html b/foo.html index d2fd3fb..13afa6e 100644 --- a/foo.html +++ b/foo.html @@ -1,4 +1,4 @@ - + diff --git a/foo.pdf b/foo.pdf index 0e90017..3c3b90d 100644 Binary files a/foo.pdf and b/foo.pdf differ cdiff-1.0/tests/git-bin/out.normal0000644000076600000240000000167613031166611017622 0ustar ymattwstaff00000000000000diff --git a/2pdf.sh b/2pdf.sh index 529d8a3..ad71911 100755 --- a/2pdf.sh +++ b/2pdf.sh @@ -13,3 +13,5 @@ INPUT=${1:-foo.html}  OUTPUT=${INPUT%.html}.pdf   wkhtmltopdf --page-size A4 $INPUT $OUTPUT # very very long comments ends here + +# EOF diff --git a/example.pdf b/example.pdf index 1eacfd8..3696851 100644 Binary files a/example.pdf and b/example.pdf differ diff --git a/foo.html b/foo.html index d2fd3fb..13afa6e 100644 --- a/foo.html +++ b/foo.html @@ -1,4 +1,4 @@ - +    diff --git a/foo.pdf b/foo.pdf index 0e90017..3c3b90d 100644 Binary files a/foo.pdf and b/foo.pdf differ  cdiff-1.0/tests/git-bin/out.side-by-side0000644000076600000240000000361513031166611020603 0ustar ymattwstaff00000000000000diff --git a/2pdf.sh b/2pdf.sh index 529d8a3..ad71911 100755 --- a/2pdf.sh +++ b/2pdf.sh @@ -13,3 +13,5 @@ INPUT=${1:-foo.html} 13 OUTPUT=${INPUT%.html}.pdf 13 OUTPUT=${INPUT%.html}.pdf 14  14  15 wkhtmltopdf --page-size A4 $INPUT $OUTPUT # very very long comments ends here 15 wkhtmltopdf --page-size A4 $INPUT $OUTPUT # very very long comments ends here   16    17 # EOF diff --git a/example.pdf b/example.pdf index 1eacfd8..3696851 100644 Binary files a/example.pdf and b/example.pdf differ diff --git a/foo.html b/foo.html index d2fd3fb..13afa6e 100644 --- a/foo.html +++ b/foo.html @@ -1,4 +1,4 @@ 1  1  2  2  3  3  4  4  diff --git a/foo.pdf b/foo.pdf index 0e90017..3c3b90d 100644 Binary files a/foo.pdf and b/foo.pdf differ  cdiff-1.0/tests/git-bin/out.w700000644000076600000240000000350113031166611016734 0ustar ymattwstaff00000000000000diff --git a/2pdf.sh b/2pdf.sh index 529d8a3..ad71911 100755 --- a/2pdf.sh +++ b/2pdf.sh @@ -13,3 +13,5 @@ INPUT=${1:-foo.html} 13 OUTPUT=${INPUT%.html}.pdf 13 OUTPUT=${INPUT%.html}.pdf 14  14  15 wkhtmltopdf --page-size A4 $INPUT $OUTPUT # very very long comments > 15 wkhtmltopdf --page-size A4 $INPUT $OUTPUT # very very long comments >   16    17 # EOF diff --git a/example.pdf b/example.pdf index 1eacfd8..3696851 100644 Binary files a/example.pdf and b/example.pdf differ diff --git a/foo.html b/foo.html index d2fd3fb..13afa6e 100644 --- a/foo.html +++ b/foo.html @@ -1,4 +1,4 @@ 1  1  2  2  3  3  4  4  diff --git a/foo.pdf b/foo.pdf index 0e90017..3c3b90d 100644 Binary files a/foo.pdf and b/foo.pdf differ  cdiff-1.0/tests/git-log/0000755000076600000240000000000013031633112015573 5ustar ymattwstaff00000000000000cdiff-1.0/tests/git-log/in.diff0000644000076600000240000000171413031166611017043 0ustar ymattwstaff00000000000000commit 65f33a326fb1d81e9b56cfa9dbe3af887ed91c8d Author: Steven Myint Date: Fri Mar 22 14:59:34 2013 -0700 Remove unused imports diff --git a/libmodernize/fixes/__init__.py b/libmodernize/fixes/__init__.py index f8628f1..2e06052 100644 --- a/libmodernize/fixes/__init__.py +++ b/libmodernize/fixes/__init__.py @@ -1,7 +1,3 @@ -import sys -from lib2to3 import refactor - - lib2to3_fix_names = set([ 'lib2to3.fixes.fix_apply', 'lib2to3.fixes.fix_except', commit 2e80837bf815d0686138beec9a5bb94e3282204d Author: Steven Myint Date: Fri Mar 22 14:33:55 2013 -0700 Format docstring diff --git a/libmodernize/main.py b/libmodernize/main.py index caf847d..b24db29 100644 --- a/libmodernize/main.py +++ b/libmodernize/main.py @@ -14,6 +14,7 @@ def main(args=None): """Main program. Returns a suggested exit status (0, 1, 2). + """ # Set up option parser parser = optparse.OptionParser(usage="modernize [options] file|dir ...") cdiff-1.0/tests/git-log/out.normal0000644000076600000240000000243513031166611017625 0ustar ymattwstaff00000000000000commit 65f33a326fb1d81e9b56cfa9dbe3af887ed91c8d Author: Steven Myint Date: Fri Mar 22 14:59:34 2013 -0700   Remove unused imports  diff --git a/libmodernize/fixes/__init__.py b/libmodernize/fixes/__init__.py index f8628f1..2e06052 100644 --- a/libmodernize/fixes/__init__.py +++ b/libmodernize/fixes/__init__.py @@ -1,7 +1,3 @@ -import sys -from lib2to3 import refactor - -  lib2to3_fix_names = set([  'lib2to3.fixes.fix_apply',  'lib2to3.fixes.fix_except',  commit 2e80837bf815d0686138beec9a5bb94e3282204d Author: Steven Myint Date: Fri Mar 22 14:33:55 2013 -0700   Format docstring  diff --git a/libmodernize/main.py b/libmodernize/main.py index caf847d..b24db29 100644 --- a/libmodernize/main.py +++ b/libmodernize/main.py @@ -14,6 +14,7 @@ def main(args=None):  """Main program.   Returns a suggested exit status (0, 1, 2). +  """  # Set up option parser  parser = optparse.OptionParser(usage="modernize [options] file|dir ...")  cdiff-1.0/tests/git-log/out.side-by-side0000644000076600000240000000477613031166611020625 0ustar ymattwstaff00000000000000commit 65f33a326fb1d81e9b56cfa9dbe3af887ed91c8d Author: Steven Myint Date: Fri Mar 22 14:59:34 2013 -0700   Remove unused imports  diff --git a/libmodernize/fixes/__init__.py b/libmodernize/fixes/__init__.py index f8628f1..2e06052 100644 --- a/libmodernize/fixes/__init__.py +++ b/libmodernize/fixes/__init__.py @@ -1,7 +1,3 @@ 1 import sys   2 from lib2to3 import refactor   3    4    5 lib2to3_fix_names = set([ 1 lib2to3_fix_names = set([ 6  'lib2to3.fixes.fix_apply', 2  'lib2to3.fixes.fix_apply', 7  'lib2to3.fixes.fix_except', 3  'lib2to3.fixes.fix_except',  commit 2e80837bf815d0686138beec9a5bb94e3282204d Author: Steven Myint Date: Fri Mar 22 14:33:55 2013 -0700   Format docstring  diff --git a/libmodernize/main.py b/libmodernize/main.py index caf847d..b24db29 100644 --- a/libmodernize/main.py +++ b/libmodernize/main.py @@ -14,6 +14,7 @@ def main(args=None): 14  """Main program. 14  """Main program. 15  15  16  Returns a suggested exit status (0, 1, 2). 16  Returns a suggested exit status (0, 1, 2).   17  17  """ 18  """ 18  # Set up option parser 19  # Set up option parser 19  parser = optparse.OptionParser(usage="modernize [options] file|dir ...") 20  parser = optparse.OptionParser(usage="modernize [options] file|dir ...") cdiff-1.0/tests/git-log/out.w700000644000076600000240000000465213031166611016755 0ustar ymattwstaff00000000000000commit 65f33a326fb1d81e9b56cfa9dbe3af887ed91c8d Author: Steven Myint Date: Fri Mar 22 14:59:34 2013 -0700   Remove unused imports  diff --git a/libmodernize/fixes/__init__.py b/libmodernize/fixes/__init__.py index f8628f1..2e06052 100644 --- a/libmodernize/fixes/__init__.py +++ b/libmodernize/fixes/__init__.py @@ -1,7 +1,3 @@ 1 import sys   2 from lib2to3 import refactor   3    4    5 lib2to3_fix_names = set([ 1 lib2to3_fix_names = set([ 6  'lib2to3.fixes.fix_apply', 2  'lib2to3.fixes.fix_apply', 7  'lib2to3.fixes.fix_except', 3  'lib2to3.fixes.fix_except',  commit 2e80837bf815d0686138beec9a5bb94e3282204d Author: Steven Myint Date: Fri Mar 22 14:33:55 2013 -0700   Format docstring  diff --git a/libmodernize/main.py b/libmodernize/main.py index caf847d..b24db29 100644 --- a/libmodernize/main.py +++ b/libmodernize/main.py @@ -14,6 +14,7 @@ def main(args=None): 14  """Main program. 14  """Main program. 15  15  16  Returns a suggested exit status (0, 1, 2). 16  Returns a suggested exit status (0, 1, 2).   17  17  """ 18  """ 18  # Set up option parser 19  # Set up option parser 19  parser = optparse.OptionParser(usage="modernize [options] file|di> 20  parser = optparse.OptionParser(usage="modernize [options] file|di> cdiff-1.0/tests/git-perm/0000755000076600000240000000000013031633112015755 5ustar ymattwstaff00000000000000cdiff-1.0/tests/git-perm/in.diff0000644000076600000240000000017413031166611017224 0ustar ymattwstaff00000000000000diff --git a/cdiff b/cdiff old mode 100755 new mode 100644 diff --git a/cdiff.py b/cdiff.py old mode 100755 new mode 100644 cdiff-1.0/tests/git-perm/out.normal0000644000076600000240000000030513031166611020001 0ustar ymattwstaff00000000000000diff --git a/cdiff b/cdiff old mode 100755 new mode 100644 diff --git a/cdiff.py b/cdiff.py old mode 100755 new mode 100644  cdiff-1.0/tests/git-perm/out.side-by-side0000644000076600000240000000030513031166611020767 0ustar ymattwstaff00000000000000diff --git a/cdiff b/cdiff old mode 100755 new mode 100644 diff --git a/cdiff.py b/cdiff.py old mode 100755 new mode 100644  cdiff-1.0/tests/git-perm/out.w700000644000076600000240000000030513031166611017126 0ustar ymattwstaff00000000000000diff --git a/cdiff b/cdiff old mode 100755 new mode 100644 diff --git a/cdiff.py b/cdiff.py old mode 100755 new mode 100644  cdiff-1.0/tests/hg-log/0000755000076600000240000000000013031633112015406 5ustar ymattwstaff00000000000000cdiff-1.0/tests/hg-log/in.diff0000644000076600000240000000404513031166611016656 0ustar ymattwstaff00000000000000# HG changeset patch # User Dan Kenigsberg # Date 1317492169 -10800 # Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a # Parent b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d xml.dom.minidom toprettyxml: omit whitespace for Text nodes http://bugs.python.org/issue4147 This patch was very lightly tested, but I think it is nicer than the former one, as Text.writexml() should better know not to wrap its data with whitespace. Ever. diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@ dom.unlink() self.confirm(domstr == str.replace("\n", "\r\n")) + def testPrettyTextNode(self): + str = 'B' + dom = parseString(str) + dom2 = parseString(dom.toprettyxml()) + self.confirm(dom.childNodes[0].childNodes[0].toxml()== + dom2.childNodes[0].childNodes[0].toxml()) + def testProcessingInstruction(self): dom = parseString('') pi = dom.documentElement.firstChild diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@ _write_data(writer, attrs[a_name].value) writer.write("\"") if self.childNodes: - writer.write(">%s"%(newl)) + writer.write(">") + if self.childNodes[0].nodeType != Node.TEXT_NODE: + writer.write(newl) for node in self.childNodes: node.writexml(writer,indent+addindent,addindent,newl) writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@ return newText def writexml(self, writer, indent="", addindent="", newl=""): - _write_data(writer, "%s%s%s"%(indent, self.data, newl)) + _write_data(writer, self.data) # DOM Level 3 (WD 9 April 2002) cdiff-1.0/tests/hg-log/out.normal0000644000076600000240000000514713031166611017443 0ustar ymattwstaff00000000000000# HG changeset patch # User Dan Kenigsberg # Date 1317492169 -10800 # Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a # Parent b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d xml.dom.minidom toprettyxml: omit whitespace for Text nodes  http://bugs.python.org/issue4147  This patch was very lightly tested, but I think it is nicer than the former one, as Text.writexml() should better know not to wrap its data with whitespace. Ever.  diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@  dom.unlink()  self.confirm(domstr == str.replace("\n", "\r\n")) + + def testPrettyTextNode(self): + str = 'B' + dom = parseString(str) + dom2 = parseString(dom.toprettyxml()) + self.confirm(dom.childNodes[0].childNodes[0].toxml()== + dom2.childNodes[0].childNodes[0].toxml())   def testProcessingInstruction(self):  dom = parseString('')  pi = dom.documentElement.firstChild diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  _write_data(writer, attrs[a_name].value)  writer.write("\"")  if self.childNodes: - writer.write(">%s"%(newl)) + writer.write(">") + if self.childNodes[0].nodeType != Node.TEXT_NODE: + writer.write(newl)  for node in self.childNodes:  node.writexml(writer,indent+addindent,addindent,newl)  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@  return newText   def writexml(self, writer, indent="", addindent="", newl=""): - _write_data(writer, "%s%s%s"%(indent, self.data, newl)) + _write_data(writer, self.data)   # DOM Level 3 (WD 9 April 2002)   cdiff-1.0/tests/hg-log/out.side-by-side0000644000076600000240000001337313031166611020431 0ustar ymattwstaff00000000000000# HG changeset patch # User Dan Kenigsberg # Date 1317492169 -10800 # Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a # Parent b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d xml.dom.minidom toprettyxml: omit whitespace for Text nodes  http://bugs.python.org/issue4147  This patch was very lightly tested, but I think it is nicer than the former one, as Text.writexml() should better know not to wrap its data with whitespace. Ever.  diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@ 467  dom.unlink() 467  dom.unlink() 468  self.confirm(domstr == str.replace("\n", "\r\n")) 468  self.confirm(domstr == str.replace("\n", "\r\n"))   469    470  def testPrettyTextNode(self):   471  str = 'B'   472  dom = parseString(str)   473  dom2 = parseString(dom.toprettyxml())   474  self.confirm(dom.childNodes[0].childNodes[0].toxml()==   475  dom2.childNodes[0].childNodes[0].toxml()) 469  476  470  def testProcessingInstruction(self): 477  def testProcessingInstruction(self): 471  dom = parseString('') 478  dom = parseString('') 472  pi = dom.documentElement.firstChild 479  pi = dom.documentElement.firstChild diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  836  _write_data(writer, attrs[a_name].value)  836  _write_data(writer, attrs[a_name].value)  837  writer.write("\"")  837  writer.write("\"")  838  if self.childNodes:  838  if self.childNodes:  839  writer.write(">%s"%(newl))  839  writer.write(">")    840  if self.childNodes[0].nodeType != Node.TEXT_NODE:    841  writer.write(newl)  840  for node in self.childNodes:  842  for node in self.childNodes:  841  node.writexml(writer,indent+addindent,addindent,newl)  843  node.writexml(writer,indent+addindent,addindent,newl)  842  writer.write("%s%s" % (indent,self.tagName,newl))  844  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@ 1061  return newText 1063  return newText 1062  1064  1063  def writexml(self, writer, indent="", addindent="", newl=""): 1065  def writexml(self, writer, indent="", addindent="", newl=""): 1064  _write_data(writer, "%s%s%s"%(indent, self.data, newl)) 1066  _write_data(writer, self.data) 1065  1067  1066  # DOM Level 3 (WD 9 April 2002) 1068  # DOM Level 3 (WD 9 April 2002) 1067  1069  cdiff-1.0/tests/hg-log/out.w700000644000076600000240000001273113031166611016565 0ustar ymattwstaff00000000000000# HG changeset patch # User Dan Kenigsberg # Date 1317492169 -10800 # Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a # Parent b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d xml.dom.minidom toprettyxml: omit whitespace for Text nodes  http://bugs.python.org/issue4147  This patch was very lightly tested, but I think it is nicer than the former one, as Text.writexml() should better know not to wrap its data with whitespace. Ever.  diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@ 467  dom.unlink() 467  dom.unlink() 468  self.confirm(domstr == str.replace("\n", "\r\n")) 468  self.confirm(domstr == str.replace("\n", "\r\n"))   469    470  def testPrettyTextNode(self):   471  str = 'B'   472  dom = parseString(str)   473  dom2 = parseString(dom.toprettyxml())   474  self.confirm(dom.childNodes[0].childNodes[0].toxml()==   475  dom2.childNodes[0].childNodes[0].toxml()) 469  476  470  def testProcessingInstruction(self): 477  def testProcessingInstruction(self): 471  dom = parseString('') 478  dom = parseString('') 472  pi = dom.documentElement.firstChild 479  pi = dom.documentElement.firstChild diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  836  _write_data(writer, attrs[a_name].value)  836  _write_data(writer, attrs[a_name].value)  837  writer.write("\"")  837  writer.write("\"")  838  if self.childNodes:  838  if self.childNodes:  839  writer.write(">%s"%(newl))  839  writer.write(">")    840  if self.childNodes[0].nodeType != Node.TEXT_NODE:    841  writer.write(newl)  840  for node in self.childNodes:  842  for node in self.childNodes:  841  node.writexml(writer,indent+addindent,addindent,newl)  843  node.writexml(writer,indent+addindent,addindent,newl)  842  writer.write("%s%s" % (indent,self.tagName,newl))  844  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@ 1061  return newText 1063  return newText 1062  1064  1063  def writexml(self, writer, indent="", addindent="", newl=""): 1065  def writexml(self, writer, indent="", addindent="", newl=""): 1064  _write_data(writer, "%s%s%s"%(indent, self.data, newl)) 1066  _write_data(writer, self.data) 1065  1067  1066  # DOM Level 3 (WD 9 April 2002) 1068  # DOM Level 3 (WD 9 April 2002) 1067  1069  cdiff-1.0/tests/latin1/0000755000076600000240000000000013031633112015421 5ustar ymattwstaff00000000000000cdiff-1.0/tests/latin1/in.diff0000644000076600000240000000026013031166611016664 0ustar ymattwstaff00000000000000diff --git a/test/latin1.cc b/test/latin1.cc index a556e5c..d81bb0c 100644 --- a/test/latin1.cc +++ b/test/latin1.cc @@ -1,4 +1,3 @@ -// é int latin1() { static int x; cdiff-1.0/tests/latin1/out.normal0000644000076600000240000000040413031166611017445 0ustar ymattwstaff00000000000000diff --git a/test/latin1.cc b/test/latin1.cc index a556e5c..d81bb0c 100644 --- a/test/latin1.cc +++ b/test/latin1.cc @@ -1,4 +1,3 @@ -// é  int latin1()  {  static int x;  cdiff-1.0/tests/latin1/out.side-by-side0000644000076600000240000000116613031166611020441 0ustar ymattwstaff00000000000000diff --git a/test/latin1.cc b/test/latin1.cc index a556e5c..d81bb0c 100644 --- a/test/latin1.cc +++ b/test/latin1.cc @@ -1,4 +1,3 @@ 1 // é   2 int latin1() 1 int latin1() 3 { 2 { 4  static int x; 3  static int x; cdiff-1.0/tests/latin1/out.w700000644000076600000240000000113013031166611016567 0ustar ymattwstaff00000000000000diff --git a/test/latin1.cc b/test/latin1.cc index a556e5c..d81bb0c 100644 --- a/test/latin1.cc +++ b/test/latin1.cc @@ -1,4 +1,3 @@ 1 // é   2 int latin1() 1 int latin1() 3 { 2 { 4  static int x; 3  static int x; cdiff-1.0/tests/profile.sh0000755000076600000240000000105113031166611016232 0ustar ymattwstaff00000000000000#!/bin/bash OUTPUT=${1:?"output file required"} SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1 CDIFF_PY=$SELF_DIR/../cdiff.py # To test with py3k: PYTHON=python3 make test PYTHON=${PYTHON:-python} set -o errexit STATS="stats.$$.tmp" for i in {1..100}; do cat "tests/svn/in.diff"; done \ | $PYTHON -m cProfile -o $STATS $CDIFF_PY -c always -s -w 60 \ > /dev/null $PYTHON -c "import pstats; p = pstats.Stats('$STATS'); \ p.strip_dirs().sort_stats('time').print_stats('cdiff')" \ | tee $OUTPUT rm -f $STATS # vim:set et sts=4 sw=4: cdiff-1.0/tests/README0000644000076600000240000000041113031166611015112 0ustar ymattwstaff00000000000000# To generate expected output, chdir to a subdir and use following command, then # review with `less -R` # ../../cdiff.py -c always < in.diff > out.normal ../../cdiff.py -c always -s < in.diff > out.side-by-side ../../cdiff.py -c always -s < in.diff -w70 > out.w70 cdiff-1.0/tests/regression.sh0000755000076600000240000000313113031166611016753 0ustar ymattwstaff00000000000000#!/bin/bash TOP_DIR=$(cd $(dirname $0)/.. && pwd) || exit 1 cd $TOP_DIR || exit 1 CDIFF=./cdiff # To test with py3k: PYTHON=python3 make test PYTHON=${PYTHON:-python} function pass() { if [[ -t 1 ]]; then echo -e "\x1b[032mPASS\x1b[0m" "$*" else echo "PASS" "$*" fi } function fail() { if [[ -t 1 ]]; then echo -e "\x1b[01;31mFAIL\x1b[0m" "$*" else echo "FAIL" "$*" fi } function cmp_output() { local input=${1:?} local expected_out=${2:?} local cdiff_opt=${3:-""} local cmd cmd=$(printf "%-8s $CDIFF %-18s < %-30s " $PYTHON "$cdiff_opt" "$input") printf "$cmd" if eval $cmd 2>/dev/null | diff -ubq $expected_out - >& /dev/null; then pass return 0 else fail "!= $expected_out" return 1 fi } function main() { local total=0 local e=0 local d for d in tests/*/; do d=${d%/} [[ -f $d/in.diff ]] || continue cmp_output $d/in.diff $d/out.normal "-c always" || ((e++)) cmp_output $d/in.diff $d/out.side-by-side "-c always -s" || ((e++)) cmp_output $d/in.diff $d/out.w70 "-c always -s -w70" || ((e++)) cmp_output $d/in.diff $d/in.diff "-c auto" || ((e++)) cmp_output $d/in.diff $d/in.diff "-c auto -s" || ((e++)) cmp_output $d/in.diff $d/in.diff "-c auto -s -w70" || ((e++)) (( total += 6 )) done if (( e > 0 )); then echo "*** $e out of $total tests failed." >&2 return 1 else echo "All $total tests passed." return 0 fi } main "$@" # vim:set et sts=4 sw=4: cdiff-1.0/tests/strange/0000755000076600000240000000000013031633112015674 5ustar ymattwstaff00000000000000cdiff-1.0/tests/strange/in.diff0000644000076600000240000000071013031166611017137 0ustar ymattwstaff00000000000000commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d Author: Matthew Wang Date: Sun Jan 6 21:56:54 2013 +0800 simplify with seperate node.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/README b/README index 7e70850..b5eb369 100644 --- a/README +++ b/README @@ -1 +1,2 @@ Sun Feb 3 13:57:05 CST 2013 +Sun Feb 3 13:57:15 CST 2013 cdiff-1.0/tests/strange/out.normal0000644000076600000240000000120013031166611017713 0ustar ymattwstaff00000000000000commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d Author: Matthew Wang Date: Sun Jan 6 21:56:54 2013 +0800   simplify with seperate node.py  diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/README b/README index 7e70850..b5eb369 100644 --- a/README +++ b/README @@ -1 +1,2 @@  Sun Feb 3 13:57:05 CST 2013 +Sun Feb 3 13:57:15 CST 2013  cdiff-1.0/tests/strange/out.side-by-side0000644000076600000240000000170713031166611020715 0ustar ymattwstaff00000000000000commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d Author: Matthew Wang Date: Sun Jan 6 21:56:54 2013 +0800   simplify with seperate node.py  diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@    1 *.pyc diff --git a/README b/README index 7e70850..b5eb369 100644 --- a/README +++ b/README @@ -1 +1,2 @@ 1 Sun Feb 3 13:57:05 CST 2013 1 Sun Feb 3 13:57:05 CST 2013   2 Sun Feb 3 13:57:15 CST 2013 cdiff-1.0/tests/strange/out.w700000644000076600000240000000165113031166611017052 0ustar ymattwstaff00000000000000commit 57263369bd810ba3a2c2dfd32a905f1e7d59cc6d Author: Matthew Wang Date: Sun Jan 6 21:56:54 2013 +0800   simplify with seperate node.py  diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@    1 *.pyc diff --git a/README b/README index 7e70850..b5eb369 100644 --- a/README +++ b/README @@ -1 +1,2 @@ 1 Sun Feb 3 13:57:05 CST 2013 1 Sun Feb 3 13:57:05 CST 2013   2 Sun Feb 3 13:57:15 CST 2013 cdiff-1.0/tests/svn/0000755000076600000240000000000013031633112015037 5ustar ymattwstaff00000000000000cdiff-1.0/tests/svn/in.diff0000644000076600000240000000201713031166611016304 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@ ## About Coderev is a toolkit generates static side-by-side html pages for code review. -Typical use case is to generate diff pages for local modification in svn/cvs workspace and send page link to teammates for code review. See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo. @@ -18,9 +17,10 @@ ## Usage of coderev.sh -Just type `./coderev.sh -h` to see the usage. +Just type `./coderev.sh --help` to see the usage. Usage: + coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \ [-F comment-file | -m 'comment...'] [file...] @@ -145,3 +145,5 @@ specify column number where lines are broken and wrapped for sdiff, default is no line wrapping -y, --yes do not prompt for overwriting + +# EOF \ No newline at end of file cdiff-1.0/tests/svn/out.normal0000644000076600000240000000246113031166611017070 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@  ## About   Coderev is a toolkit generates static side-by-side html pages for code review. -Typical use case is to generate diff pages for local modification in svn/cvs  workspace and send page link to teammates for code review.   See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo. @@ -18,9 +17,10 @@   ## Usage of coderev.sh  -Just type `./coderev.sh -h` to see the usage. +Just type `./coderev.sh --help` to see the usage.   Usage: +  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \  [-F comment-file | -m 'comment...'] [file...]  @@ -145,3 +145,5 @@  specify column number where lines are broken and  wrapped for sdiff, default is no line wrapping  -y, --yes do not prompt for overwriting + +# EOF  cdiff-1.0/tests/svn/out.side-by-side0000644000076600000240000000723113031166611020056 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@  3 ## About  3 ## About  4   4   5 Coderev is a toolkit generates static side-by-side html pages for code review.  5 Coderev is a toolkit generates static side-by-side html pages for code review.  6 Typical use case is to generate diff pages for local modification in svn/cvs    7 workspace and send page link to teammates for code review.  6 workspace and send page link to teammates for code review.  8   7   9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.  8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo. @@ -18,9 +17,10 @@  18   17   19 ## Usage of coderev.sh  18 ## Usage of coderev.sh  20   19   21 Just type `./coderev.sh -h` to see the usage.  20 Just type `./coderev.sh --help` to see the usage.  22   21   23  Usage:  22  Usage:    23   24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \  24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \  25  [-F comment-file | -m 'comment...'] [file...]  25  [-F comment-file | -m 'comment...'] [file...]  26   26  @@ -145,3 +145,5 @@ 145  specify column number where lines are broken and 145  specify column number where lines are broken and 146  wrapped for sdiff, default is no line wrapping 146  wrapped for sdiff, default is no line wrapping 147  -y, --yes do not prompt for overwriting 147  -y, --yes do not prompt for overwriting   148    149 # EOF cdiff-1.0/tests/svn/out.w700000644000076600000240000000703513031166611016217 0ustar ymattwstaff00000000000000Index: README.md =================================================================== --- README.md (revision 41) +++ README.md (working copy) @@ -3,7 +3,6 @@  3 ## About  3 ## About  4   4   5 Coderev is a toolkit generates static side-by-side html pages for cod>  5 Coderev is a toolkit generates static side-by-side html pages for cod>  6 Typical use case is to generate diff pages for local modification in >    7 workspace and send page link to teammates for code review.  6 workspace and send page link to teammates for code review.  8   7   9 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f>  8 See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) f> @@ -18,9 +17,10 @@  18   17   19 ## Usage of coderev.sh  18 ## Usage of coderev.sh  20   19   21 Just type `./coderev.sh -h` to see the usage.  20 Just type `./coderev.sh --help` to see the usage.  22   21   23  Usage:  22  Usage:    23   24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>  24  coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name>  25  [-F comment-file | -m 'comment...'] [file...]  25  [-F comment-file | -m 'comment...'] [file...]  26   26  @@ -145,3 +145,5 @@ 145  specify column number where lines are bro> 145  specify column number where lines are bro> 146  wrapped for sdiff, default is no line wra> 146  wrapped for sdiff, default is no line wra> 147  -y, --yes do not prompt for overwriting 147  -y, --yes do not prompt for overwriting   148    149 # EOF cdiff-1.0/tests/svn-log/0000755000076600000240000000000013031633112015616 5ustar ymattwstaff00000000000000cdiff-1.0/tests/svn-log/in.diff0000644000076600000240000000271013031166611017063 0ustar ymattwstaff00000000000000------------------------------------------------------------------------ r1235 | ymattw | 2011-09-01 17:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines Interpreter fix Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 1234) +++ src/share/example.sh (revision 1235) @@ -1,3 +1,3 @@ -#!/bin/sh +#!/bin/bash # # Test program, also try run me as yroot (sudo ./example.sh) ------------------------------------------------------------------------ r1234 | ymattw | 2011-09-01 16:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines Implement common tool to run command as headless account Index: ChangeLog =================================================================== --- ChangeLog (revision 1233) +++ ChangeLog (revision 1234) @@ -1,3 +1,6 @@ +Version 0.0.4 + * Add prototype of perl module + Version 0.0.3 * Implement '-d' option * Add configfile to set global debug flag Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 0) +++ src/share/example.sh (revision 1234) @@ -0,0 +1,4 @@ +#!/bin/sh +# +# Test program, also try run me as yroot (sudo ./example.sh) +# Property changes on: src/share/example.sh ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property cdiff-1.0/tests/svn-log/out.normal0000644000076600000240000000361113031166611017645 0ustar ymattwstaff00000000000000------------------------------------------------------------------------ r1235 | ymattw | 2011-09-01 17:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines  Interpreter fix   Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 1234) +++ src/share/example.sh (revision 1235) @@ -1,3 +1,3 @@ -#!/bin/sh +#!/bin/bash  #  # Test program, also try run me as yroot (sudo ./example.sh)  ------------------------------------------------------------------------ r1234 | ymattw | 2011-09-01 16:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines  Implement common tool to run command as headless account   Index: ChangeLog =================================================================== --- ChangeLog (revision 1233) +++ ChangeLog (revision 1234) @@ -1,3 +1,6 @@ +Version 0.0.4 + * Add prototype of perl module +  Version 0.0.3  * Implement '-d' option  * Add configfile to set global debug flag Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 0) +++ src/share/example.sh (revision 1234) @@ -0,0 +1,4 @@ +#!/bin/sh +# +# Test program, also try run me as yroot (sudo ./example.sh) +#  Property changes on: src/share/example.sh ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* Added: svn:keywords ## -0,0 +1 ## +Id  cdiff-1.0/tests/svn-log/out.side-by-side0000644000076600000240000000672313031166611020642 0ustar ymattwstaff00000000000000------------------------------------------------------------------------ r1235 | ymattw | 2011-09-01 17:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines  Interpreter fix   Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 1234) +++ src/share/example.sh (revision 1235) @@ -1,3 +1,3 @@ 1 #!/bin/sh 1 #!/bin/bash 2 # 2 # 3 # Test program, also try run me as yroot (sudo ./example.sh) 3 # Test program, also try run me as yroot (sudo ./example.sh)  ------------------------------------------------------------------------ r1234 | ymattw | 2011-09-01 16:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines  Implement common tool to run command as headless account   Index: ChangeLog =================================================================== --- ChangeLog (revision 1233) +++ ChangeLog (revision 1234) @@ -1,3 +1,6 @@   1 Version 0.0.4   2  * Add prototype of perl module   3  1 Version 0.0.3 4 Version 0.0.3 2  * Implement '-d' option 5  * Implement '-d' option 3  * Add configfile to set global debug flag 6  * Add configfile to set global debug flag Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 0) +++ src/share/example.sh (revision 1234) @@ -0,0 +1,4 @@    1 #!/bin/sh    2 #    3 # Test program, also try run me as yroot (sudo ./example.sh)    4 #  Property changes on: src/share/example.sh ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ##    1 * Added: svn:keywords ## -0,0 +1 ##    1 Id cdiff-1.0/tests/svn-log/out.w700000644000076600000240000000647513031166611017005 0ustar ymattwstaff00000000000000------------------------------------------------------------------------ r1235 | ymattw | 2011-09-01 17:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines  Interpreter fix   Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 1234) +++ src/share/example.sh (revision 1235) @@ -1,3 +1,3 @@ 1 #!/bin/sh 1 #!/bin/bash 2 # 2 # 3 # Test program, also try run me as yroot (sudo ./example.sh) 3 # Test program, also try run me as yroot (sudo ./example.sh)  ------------------------------------------------------------------------ r1234 | ymattw | 2011-09-01 16:00:02 +0800 (Thu, 01 Sep 2011) | 3 lines  Implement common tool to run command as headless account   Index: ChangeLog =================================================================== --- ChangeLog (revision 1233) +++ ChangeLog (revision 1234) @@ -1,3 +1,6 @@   1 Version 0.0.4   2  * Add prototype of perl module   3  1 Version 0.0.3 4 Version 0.0.3 2  * Implement '-d' option 5  * Implement '-d' option 3  * Add configfile to set global debug flag 6  * Add configfile to set global debug flag Index: src/share/example.sh =================================================================== --- src/share/example.sh (revision 0) +++ src/share/example.sh (revision 1234) @@ -0,0 +1,4 @@    1 #!/bin/sh    2 #    3 # Test program, also try run me as yroot (sudo ./example.sh)    4 #  Property changes on: src/share/example.sh ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ##    1 * Added: svn:keywords ## -0,0 +1 ##    1 Id cdiff-1.0/tests/svn-merge/0000755000076600000240000000000013031633112016134 5ustar ymattwstaff00000000000000cdiff-1.0/tests/svn-merge/in.diff0000644000076600000240000000050613031166611017402 0ustar ymattwstaff00000000000000Index: . ================================================================== --- . (revision 10) +++ . (working copy) Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo Merged /repository/foo/branches/foo-bar:r4-9 Merged /repository/foo/trunk/foo:r2-3 cdiff-1.0/tests/svn-merge/out.normal0000644000076600000240000000066313031166611020167 0ustar ymattwstaff00000000000000Index: . ================================================================== --- . (revision 10) +++ . (working copy)  Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo  Merged /repository/foo/branches/foo-bar:r4-9  Merged /repository/foo/trunk/foo:r2-3  cdiff-1.0/tests/svn-merge/out.side-by-side0000644000076600000240000000066313031166611021155 0ustar ymattwstaff00000000000000Index: . ================================================================== --- . (revision 10) +++ . (working copy)  Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo  Merged /repository/foo/branches/foo-bar:r4-9  Merged /repository/foo/trunk/foo:r2-3  cdiff-1.0/tests/svn-merge/out.w700000644000076600000240000000066313031166611017314 0ustar ymattwstaff00000000000000Index: . ================================================================== --- . (revision 10) +++ . (working copy)  Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo  Merged /repository/foo/branches/foo-bar:r4-9  Merged /repository/foo/trunk/foo:r2-3  cdiff-1.0/tests/svn-property/0000755000076600000240000000000013031633112016721 5ustar ymattwstaff00000000000000cdiff-1.0/tests/svn-property/in.diff0000644000076600000240000000024613031166611020170 0ustar ymattwstaff00000000000000Index: foo =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream cdiff-1.0/tests/svn-property/out.normal0000644000076600000240000000033513031166611020750 0ustar ymattwstaff00000000000000Index: foo =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream  cdiff-1.0/tests/svn-property/out.side-by-side0000644000076600000240000000033513031166611021736 0ustar ymattwstaff00000000000000Index: foo =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream  cdiff-1.0/tests/svn-property/out.w700000644000076600000240000000033513031166611020075 0ustar ymattwstaff00000000000000Index: foo =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream  cdiff-1.0/tests/test_cdiff.py0000755000076600000240000006005413031363123016727 0ustar ymattwstaff00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Unit test for cdiff""" import sys import unittest import tempfile import subprocess import os sys.path.insert(0, '') import cdiff # nopep8 class Sequential(object): """A non-seekable iterator, mock of file object""" def __init__(self, items): self._items = items self._index = 0 def __iter__(self): while True: try: item = self._items[self._index] except IndexError: raise StopIteration yield item self._index += 1 def readline(self): try: item = self._items[self._index] except IndexError: return '' self._index += 1 return item class PatchStreamTest(unittest.TestCase): def test_is_empty(self): stream = cdiff.PatchStream(Sequential([])) self.assertTrue(stream.is_empty()) stream = cdiff.PatchStream(Sequential(['hello', 'world'])) self.assertFalse(stream.is_empty()) def test_read_stream_header(self): stream = cdiff.PatchStream(Sequential([])) self.assertEqual(stream.read_stream_header(1), []) items = ['hello', 'world', 'again'] stream = cdiff.PatchStream(Sequential(items)) self.assertEqual(stream.read_stream_header(2), items[:2]) stream = cdiff.PatchStream(Sequential(items)) self.assertEqual(stream.read_stream_header(4), items[:]) def test_iter_after_read_stream_header(self): items = ['hello', 'world', 'again', 'and', 'again'] stream = cdiff.PatchStream(Sequential(items)) _ = stream.read_stream_header(2) out = list(stream) self.assertEqual(out, items) class DecodeTest(unittest.TestCase): def test_normal(self): utext = 'hello'.encode('utf-8') self.assertEqual('hello', cdiff.decode(utext)) def test_latin_1(self): text = '\x80\x02q\x01(U' if sys.version_info[0] == 2: decoded_text = text.decode('latin-1') else: decoded_text = text self.assertEqual(decoded_text, cdiff.decode(text)) class HunkTest(unittest.TestCase): def test_get_old_text(self): hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2)) hunk.append(('-', 'foo\n')) hunk.append(('+', 'bar\n')) hunk.append((' ', 'common\n')) self.assertEqual(hunk._get_old_text(), ['foo\n', 'common\n']) def test_get_new_text(self): hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2)) hunk.append(('-', 'foo\n')) hunk.append(('+', 'bar\n')) hunk.append((' ', 'common\n')) self.assertEqual(hunk._get_new_text(), ['bar\n', 'common\n']) class DiffMarkupTest(unittest.TestCase): def _init_diff(self): """Return a minimal diff contains all required samples header --- old +++ new hunk header @@ -1,4 +1,4 @@ -hhello +helloo +spammm world -garb -Again +again """ hunk = cdiff.Hunk(['hunk header\n'], '@@ -1,4 +1,4 @@\n', (1, 4), (1, 4)) hunk.append(('-', 'hhello\n')) hunk.append(('+', 'helloo\n')) hunk.append(('+', 'spammm\n')) hunk.append((' ', 'world\n')) hunk.append(('-', 'garb\n')) hunk.append(('-', 'Again\n')) hunk.append(('+', 'again\n')) diff = cdiff.UnifiedDiff( ['header\n'], '--- old\n', '+++ new\n', [hunk]) return diff def test_markup_mix(self): marker = cdiff.DiffMarker() line = 'foo \x00-del\x01 \x00+add\x01 \x00^chg\x01 bar' base_color = 'red' self.assertEqual( marker._markup_mix(line, base_color), '\x1b[31mfoo \x1b[7m\x1b[31mdel\x1b[0m\x1b[31m ' '\x1b[7m\x1b[31madd\x1b[0m\x1b[31m ' '\x1b[4m\x1b[31mchg\x1b[0m\x1b[31m bar\x1b[0m') def test_markup_traditional_hunk_header(self): hunk = cdiff.Hunk(['hunk header\n'], '@@ -0 +0 @@\n', (0, 0), (0, 0)) diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = cdiff.DiffMarker() out = list(marker._markup_traditional(diff)) self.assertEqual(len(out), 4) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;34m@@ -0 +0 @@\n\x1b[0m') def test_markup_traditional_old_changed(self): hunk = cdiff.Hunk([], '@@ -1 +0,0 @@\n', (1, 0), (0, 0)) hunk.append(('-', 'spam\n')) diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = cdiff.DiffMarker() out = list(marker._markup_traditional(diff)) self.assertEqual(len(out), 4) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;34m@@ -1 +0,0 @@\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;31m-spam\n\x1b[0m') def test_markup_traditional_new_changed(self): hunk = cdiff.Hunk([], '@@ -0,0 +1 @@\n', (0, 0), (1, 0)) hunk.append(('+', 'spam\n')) diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = cdiff.DiffMarker() out = list(marker._markup_traditional(diff)) self.assertEqual(len(out), 4) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;34m@@ -0,0 +1 @@\n\x1b[0m') self.assertEqual(out[3], '\x1b[32m+spam\n\x1b[0m') def test_markup_traditional_both_changed(self): hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@\n', (1, 2), (1, 2)) hunk.append(('-', 'hella\n')) hunk.append(('+', 'hello\n')) hunk.append((' ', 'common\n')) diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk]) marker = cdiff.DiffMarker() out = list(marker._markup_traditional(diff)) self.assertEqual(len(out), 6) self.assertEqual(out[0], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[2], '\x1b[1;34m@@ -1,2 +1,2 @@\n\x1b[0m') self.assertEqual( out[3], '\x1b[1;31m-\x1b[0m\x1b[31mhell' '\x1b[4m\x1b[31ma\x1b[0m\x1b[31m\n\x1b[0m') self.assertEqual( out[4], '\x1b[32m+\x1b[0m\x1b[32mhell' '\x1b[4m\x1b[32mo\x1b[0m\x1b[32m\n\x1b[0m') self.assertEqual(out[5], '\x1b[0m common\n\x1b[0m') def test_markup_side_by_side_padded(self): diff = self._init_diff() marker = cdiff.DiffMarker() out = list(marker._markup_side_by_side(diff, 7)) self.assertEqual(len(out), 10) sys.stdout.write('\n') for markup in out: sys.stdout.write(markup) self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[4], '\x1b[1;34m@@ -1,4 +1,4 @@\n\x1b[0m') self.assertEqual( out[5], '\x1b[33m1\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhello\x1b[0m ' '\x1b[0m\x1b[33m1\x1b[0m ' '\x1b[32mhello\x1b[7m\x1b[32mo\x1b[0m\x1b[32m\x1b[0m\n') self.assertEqual( out[6], '\x1b[33m ' '\x1b[0m ' '\x1b[0m\x1b[33m2\x1b[0m ' '\x1b[32mspammm\x1b[0m\n') self.assertEqual( out[7], '\x1b[33m2\x1b[0m ' '\x1b[0mworld\x1b[0m ' '\x1b[0m\x1b[33m3\x1b[0m ' '\x1b[0mworld\x1b[0m\n') self.assertEqual( out[8], '\x1b[33m3\x1b[0m ' '\x1b[1;31mgarb\x1b[0m ' '\x1b[0m\x1b[33m ' '\x1b[0m \n') self.assertEqual( out[9], '\x1b[33m4\x1b[0m ' '\x1b[31m\x1b[4m\x1b[31mA\x1b[0m\x1b[31mgain\x1b[0m ' '\x1b[0m\x1b[33m4\x1b[0m ' '\x1b[32m\x1b[4m\x1b[32ma\x1b[0m\x1b[32mgain\x1b[0m\n') # This test is not valid anymore def __test_markup_side_by_side_neg_width(self): diff = self._init_diff() marker = cdiff.DiffMarker() out = list(marker._markup_side_by_side(diff, -1)) self.assertEqual(len(out), 10) self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[4], '\x1b[1;34m@@ -1,4 +1,4 @@\n\x1b[0m') self.assertEqual( out[5], '\x1b[33m1\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhello\x1b[0m ' + (' ' * 74) + '\x1b[0m\x1b[33m1\x1b[0m ' '\x1b[32mhello\x1b[7m\x1b[32mo\x1b[0m\x1b[32m\x1b[0m\n') self.assertEqual( out[6], '\x1b[33m ' '\x1b[0m ' + (' ' * 80) + '\x1b[0m\x1b[33m2\x1b[0m ' '\x1b[32mspammm\x1b[0m\n') self.assertEqual( out[7], '\x1b[33m2\x1b[0m ' '\x1b[0mworld\x1b[0m ' + (' ' * 75) + '\x1b[0m\x1b[33m3\x1b[0m ' '\x1b[0mworld\x1b[0m\n') self.assertEqual( out[8], '\x1b[33m3\x1b[0m ' '\x1b[1;31mgarb\x1b[0m ' '\x1b[0m\x1b[33m ' '\x1b[0m \n') self.assertEqual( out[9], '\x1b[33m4\x1b[0m ' '\x1b[31m\x1b[4m\x1b[31mA\x1b[0m\x1b[31mgain\x1b[0m ' + (' ' * 75) + '\x1b[0m\x1b[33m4\x1b[0m ' '\x1b[32m\x1b[4m\x1b[32ma\x1b[0m\x1b[32mgain\x1b[0m\n') def test_markup_side_by_side_off_by_one(self): diff = self._init_diff() marker = cdiff.DiffMarker() out = list(marker._markup_side_by_side(diff, 6)) self.assertEqual(len(out), 10) sys.stdout.write('\n') for markup in out: sys.stdout.write(markup) self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[4], '\x1b[1;34m@@ -1,4 +1,4 @@\n\x1b[0m') self.assertEqual( out[5], '\x1b[33m1\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhello\x1b[0m ' '\x1b[0m\x1b[33m1\x1b[0m ' '\x1b[32mhello\x1b[7m\x1b[32mo\x1b[0m\n') self.assertEqual( out[6], '\x1b[33m \x1b[0m ' '\x1b[0m\x1b[33m2\x1b[0m ' '\x1b[32mspammm\x1b[0m\n') self.assertEqual( out[7], '\x1b[33m2\x1b[0m ' '\x1b[0mworld\x1b[0m ' '\x1b[0m\x1b[33m3\x1b[0m ' '\x1b[0mworld\x1b[0m\n') self.assertEqual( out[8], '\x1b[33m3\x1b[0m ' '\x1b[1;31mgarb\x1b[0m ' '\x1b[0m\x1b[33m ' '\x1b[0m \n') self.assertEqual( out[9], '\x1b[33m4\x1b[0m ' '\x1b[31m\x1b[4m\x1b[31mA\x1b[0m\x1b[31mgain\x1b[0m ' '\x1b[0m\x1b[33m4\x1b[0m ' '\x1b[32m\x1b[4m\x1b[32ma\x1b[0m\x1b[32mgain\x1b[0m\n') def test_markup_side_by_side_wrapped(self): diff = self._init_diff() marker = cdiff.DiffMarker() out = list(marker._markup_side_by_side(diff, 5)) self.assertEqual(len(out), 10) sys.stdout.write('\n') for markup in out: sys.stdout.write(markup) self.assertEqual(out[0], '\x1b[36mheader\n\x1b[0m') self.assertEqual(out[1], '\x1b[33m--- old\n\x1b[0m') self.assertEqual(out[2], '\x1b[33m+++ new\n\x1b[0m') self.assertEqual(out[3], '\x1b[1;36mhunk header\n\x1b[0m') self.assertEqual(out[4], '\x1b[1;34m@@ -1,4 +1,4 @@\n\x1b[0m') self.assertEqual( out[5], '\x1b[33m1\x1b[0m ' '\x1b[31m\x1b[7m\x1b[31mh\x1b[0m\x1b[31mhel\x1b[0m\x1b[1;35m>\x1b[0m ' # nopep8 '\x1b[0m\x1b[33m1\x1b[0m ' '\x1b[32mhell\x1b[0m\x1b[1;35m>\x1b[0m\n') self.assertEqual( out[6], '\x1b[33m \x1b[0m ' '\x1b[0m\x1b[33m2\x1b[0m ' '' '\x1b[32mspam\x1b[0m\x1b[1;35m>\x1b[0m\n') self.assertEqual( out[7], '\x1b[33m2\x1b[0m ' '\x1b[0mworld\x1b[0m ' '\x1b[0m\x1b[33m3\x1b[0m ' '\x1b[0mworld\x1b[0m\n') self.assertEqual( out[8], '\x1b[33m3\x1b[0m ' '\x1b[1;31mgarb\x1b[0m ' '\x1b[0m\x1b[33m ' '\x1b[0m \n') self.assertEqual( out[9], '\x1b[33m4\x1b[0m ' '\x1b[31m\x1b[4m\x1b[31mA\x1b[0m\x1b[31mgain\x1b[0m ' '\x1b[0m\x1b[33m4\x1b[0m ' '\x1b[32m\x1b[4m\x1b[32ma\x1b[0m\x1b[32mgain\x1b[0m\n') class UnifiedDiffTest(unittest.TestCase): diff = cdiff.UnifiedDiff(None, None, None, None) def test_is_hunk_meta_normal(self): self.assertTrue(self.diff.is_hunk_meta('@@ -1 +1 @@')) self.assertTrue(self.diff.is_hunk_meta('@@ -3,7 +3,6 @@')) self.assertTrue(self.diff.is_hunk_meta('@@ -3,7 +3,6 @@ class Foo')) self.assertTrue(self.diff.is_hunk_meta('@@ -3,7 +3,6 @@ class Foo\n')) self.assertTrue( self.diff.is_hunk_meta('@@ -3,7 +3,6 @@ class Foo\r\n')) def test_is_hunk_meta_svn_prop(self): self.assertTrue(self.diff.is_hunk_meta('## -0,0 +1 ##')) self.assertTrue(self.diff.is_hunk_meta('## -0,0 +1 ##\n')) self.assertTrue(self.diff.is_hunk_meta('## -0,0 +1 ##\r\n')) def test_is_hunk_meta_neg(self): self.assertFalse(self.diff.is_hunk_meta('@@ -1 + @@')) self.assertFalse(self.diff.is_hunk_meta('@@ -this is not a hunk meta')) self.assertFalse(self.diff.is_hunk_meta('## -this is not either')) def test_parse_hunk_meta_normal(self): self.assertEqual(self.diff.parse_hunk_meta('@@ -3,7 +3,6 @@'), ((3, 7), (3, 6))) def test_parse_hunk_meta_missing(self): self.assertEqual(self.diff.parse_hunk_meta('@@ -3 +3,6 @@'), ((3, 1), (3, 6))) self.assertEqual(self.diff.parse_hunk_meta('@@ -3,7 +3 @@'), ((3, 7), (3, 1))) self.assertEqual(self.diff.parse_hunk_meta('@@ -3 +3 @@'), ((3, 1), (3, 1))) def test_parse_hunk_meta_svn_prop(self): self.assertEqual(self.diff.parse_hunk_meta('## -0,0 +1 ##'), ((0, 0), (1, 1))) def test_is_old(self): self.assertTrue(self.diff.is_old('-hello world')) self.assertTrue(self.diff.is_old('----')) # yaml def test_is_old_neg(self): self.assertFalse(self.diff.is_old('--- considered as old path')) self.assertFalse(self.diff.is_old('-' * 72)) # svn log --diff def test_is_new(self): self.assertTrue(self.diff.is_new('+hello world')) self.assertTrue(self.diff.is_new('++++hello world')) def test_is_new_neg(self): self.assertFalse(self.diff.is_new('+++ considered as new path')) class DiffParserTest(unittest.TestCase): def test_type_detect_unified(self): patch = """\ spam --- a +++ b @@ -1,2 +1,2 @@ """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) self.assertEqual(parser._type, 'unified') def test_type_detect_context(self): patch = """\ *** /path/to/original timestamp --- /path/to/new timestamp *************** *** 1,1 **** --- 1,2 ---- + This is an important This part of the """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) self.assertEqual(parser._type, 'context') def test_type_detect_neg(self): patch = """\ spam --- a spam +++ b """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) self.assertEqual(parser._type, 'unified') def test_parse_invalid_hunk_meta(self): patch = """\ spam --- a +++ b spam @@ -a,a +0 @@ """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) self.assertRaises(RuntimeError, list, parser.get_diff_generator()) def test_parse_dangling_header(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common spam """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 2) self.assertEqual(len(out[1]._headers), 1) self.assertEqual(out[1]._headers[0], 'spam\n') self.assertEqual(out[1]._old_path, '') self.assertEqual(out[1]._new_path, '') self.assertEqual(len(out[1]._hunks), 0) def test_parse_missing_new_path(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common --- c """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) self.assertRaises(AssertionError, list, parser.get_diff_generator()) def test_parse_missing_hunk_meta(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common --- c +++ d """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 2) self.assertEqual(len(out[1]._headers), 0) self.assertEqual(out[1]._old_path, '--- c\n') self.assertEqual(out[1]._new_path, '+++ d\n') self.assertEqual(len(out[1]._hunks), 0) def test_parse_missing_hunk_list(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common --- c +++ d @@ -1,2 +1,2 @@ """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) self.assertRaises(AssertionError, list, parser.get_diff_generator()) def test_parse_only_in_dir(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common Only in foo: foo --- c +++ d @@ -1,2 +1,2 @@ -foo +bar common """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 3) self.assertEqual(len(out[1]._hunks), 0) self.assertEqual(out[1]._headers, ['Only in foo: foo\n']) self.assertEqual(len(out[2]._hunks), 1) self.assertEqual(len(out[2]._hunks[0]._hunk_list), 3) def test_parse_only_in_dir_at_last(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common Only in foo: foo """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 2) self.assertEqual(len(out[1]._hunks), 0) self.assertEqual(out[1]._headers, ['Only in foo: foo\n']) def test_parse_binary_differ_diff_ru(self): patch = """\ --- a +++ b @@ -1,2 +1,2 @@ -foo +bar common Binary files a/1.pdf and b/1.pdf differ --- c +++ d @@ -1,2 +1,2 @@ -foo +bar common """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 3) self.assertEqual(len(out[1]._hunks), 0) self.assertEqual(out[1]._old_path, '') self.assertEqual(out[1]._new_path, '') self.assertEqual(len(out[1]._headers), 1) self.assertTrue(out[1]._headers[0].startswith('Binary files')) self.assertEqual(len(out[2]._hunks), 1) self.assertEqual(len(out[2]._hunks[0]._hunk_list), 3) def test_parse_binary_differ_git(self): patch = """\ diff --git a/foo b/foo index 529d8a3..ad71911 100755 --- a/foo +++ b/foo @@ -1,2 +1,2 @@ -foo +bar common diff --git a/example.pdf b/example.pdf index 1eacfd8..3696851 100644 Binary files a/example.pdf and b/example.pdf differ diff --git a/bar b/bar index 529e8a3..ad71921 100755 --- a/bar +++ b/bar @@ -1,2 +1,2 @@ -foo +bar common """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 3) self.assertEqual(len(out[1]._hunks), 0) self.assertEqual(out[1]._old_path, '') self.assertEqual(out[1]._new_path, '') self.assertEqual(len(out[1]._headers), 3) self.assertTrue(out[1]._headers[2].startswith('Binary files')) self.assertEqual(len(out[2]._hunks), 1) self.assertEqual(len(out[2]._hunks[0]._hunk_list), 3) def test_parse_svn_prop(self): patch = """\ --- a +++ b Added: svn:executable ## -0,0 +1 ## +* \\ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id """ items = patch.splitlines(True) stream = cdiff.PatchStream(Sequential(items)) parser = cdiff.DiffParser(stream) out = list(parser.get_diff_generator()) self.assertEqual(len(out), 1) self.assertEqual(len(out[0]._hunks), 2) hunk = out[0]._hunks[1] self.assertEqual(hunk._hunk_headers, ['Added: svn:keywords\n']) self.assertEqual(hunk._hunk_list, [('+', 'Id\n')]) class MainTest(unittest.TestCase): def setUp(self): self._cwd = os.getcwd() self._ws = tempfile.mkdtemp(prefix='test_cdiff') self._non_ws = tempfile.mkdtemp(prefix='test_cdiff') cmd = ('cd %s; git init; git config user.name me; ' 'git config user.email me@example.org') % self._ws subprocess.call(cmd, shell=True, stdout=subprocess.PIPE) self._change_file('init') def tearDown(self): os.chdir(self._cwd) cmd = ['/bin/rm', '-rf', self._ws, self._non_ws] subprocess.call(cmd) def _change_file(self, text): cmd = ['/bin/sh', '-c', 'cd %s; echo "%s" > foo' % (self._ws, text)] subprocess.call(cmd) def _commit_file(self): cmd = ['/bin/sh', '-c', 'cd %s; git add foo; git commit foo -m update' % self._ws] subprocess.call(cmd, stdout=subprocess.PIPE) def test_preset_options(self): os.environ['CDIFF_OPTIONS'] = '--help' self.assertRaises(SystemExit, cdiff.main) os.environ.pop('CDIFF_OPTIONS', None) def test_read_diff(self): sys.argv = sys.argv[:1] self._change_file('read_diff') os.chdir(self._ws) ret = cdiff.main() os.chdir(self._cwd) self.assertEqual(ret, 0) # Following 3 tests does not pass on Travis anymore due to tty problem def _test_read_log(self): sys.argv = [sys.argv[0], '--log'] self._change_file('read_log') self._commit_file() os.chdir(self._ws) ret = cdiff.main() os.chdir(self._cwd) self.assertEqual(ret, 0) def _test_read_diff_neg(self): sys.argv = sys.argv[:1] os.chdir(self._non_ws) ret = cdiff.main() os.chdir(self._cwd) self.assertNotEqual(ret, 0) def _test_read_log_neg(self): sys.argv = [sys.argv[0], '--log'] os.chdir(self._non_ws) ret = cdiff.main() os.chdir(self._cwd) self.assertNotEqual(ret, 0) if __name__ == '__main__': unittest.main() # vim:set et sts=4 sw=4 tw=80: