Show the diff between two revisions.
507101
def on_diff(request, page_name):
    """"""
    old = request.args.get("old", type=int)
    new = request.args.get("new", type=int)
    error = ""
    diff = page = old_rev = new_rev = None

    if not (old and new):
        error = "No revisions specified."
    else:
        revisions = dict(
            (x.revision_id, x)
            for x in Revision.query.filter(
                (Revision.revision_id.in_((old, new)))
                & (Revision.page_id == Page.page_id)
                & (Page.name == page_name)
            )
        )
        if len(revisions) != 2:
            error = "At least one of the revisions requested does not exist."
        else:
            new_rev = revisions[new]
            old_rev = revisions[old]
            page = old_rev.page
            diff = unified_diff(
                (old_rev.text + "\n").splitlines(True),
                (new_rev.text + "\n").splitlines(True),
                page.name,
                page.name,
                format_datetime(old_rev.timestamp),
                format_datetime(new_rev.timestamp),
                3,
            )

    return Response(
        generate_template(
            "action_diff.html",
            error=error,
            old_revision=old_rev,
            new_revision=new_rev,
            page=page,
            diff=diff,
        )
    )
779014
def _split_diff(merge_result, context_lines=3):
    """"""
    collect = []
    for item in _visible_in_diff(merge_result, context_lines=context_lines):
        if item is None:
            if collect:
                yield collect
            collect = []
        else:
            collect.append(item)
885376
def _get_diff(self):
        """"""
        diff = []
        self._create_sot_file()
        command = ('show diff rollback-patch file {0} file {1}'.format(
                   'sot_file', self.replace_file.split('/')[-1]))
        diff_out = self.device.send_command(command)
        try:
            diff_out = diff_out.split(
                '#Generating Rollback Patch')[1].replace(
                    'Rollback Patch is Empty', '').strip()
            for line in diff_out.splitlines():
                if line:
                    if line[0].strip() != '!' and line[0].strip() != '.':
                        diff.append(line.rstrip(' '))
        except (AttributeError, KeyError):
            raise ReplaceConfigException(
                'Could not calculate diff. It\'s possible the given file doesn\'t exist.')
        return '\n'.join(diff)
419593
def diff_record(self, record):
        """"""
        rec = self.get_record(record._record_type, record.host)
        if rec is not None and record is not None:
            return {'removed': tuple(set(rec.results) - set(record.results)),
                    'added': tuple(set(record.results) - set(rec.recults))}
        else:
            return False
767400
def default_diff(latest_config, current_config):
    """"""
    # Pop off the fields we don't care about:
    pop_no_diff_fields(latest_config, current_config)

    diff = DeepDiff(
        latest_config,
        current_config,
        ignore_order=True
    )
    return diff
344388
def changed(self):
        '''
        
        '''
        def _changed(diffs, prefix):
            keys = []
            for key in diffs.keys():
                if not isinstance(diffs[key], dict):
                    continue

                if isinstance(diffs[key], dict) and 'old' not in diffs[key]:
                    keys.extend(_changed(diffs[key],
                                       prefix='{0}{1}.'.format(prefix, key)))
                    continue
                if self.ignore_unset_values:
                    if 'old' in diffs[key] and 'new' in diffs[key] and \
                            diffs[key]['old'] != self.NONE_VALUE and \
                            diffs[key]['new'] != self.NONE_VALUE:
                        if isinstance(diffs[key]['new'], dict):
                            keys.extend(
                                _changed(diffs[key]['new'],
                                         prefix='{0}{1}.'.format(prefix, key)))
                        else:
                            keys.append('{0}{1}'.format(prefix, key))
                    elif isinstance(diffs[key], dict):
                        keys.extend(
                            _changed(diffs[key],
                                     prefix='{0}{1}.'.format(prefix, key)))
                else:
                    if 'old' in diffs[key] and 'new' in diffs[key]:
                        if isinstance(diffs[key]['new'], dict):
                            keys.extend(
                                _changed(diffs[key]['new'],
                                         prefix='{0}{1}.'.format(prefix, key)))
                        else:
                            keys.append('{0}{1}'.format(prefix, key))
                    elif isinstance(diffs[key], dict):
                        keys.extend(
                            _changed(diffs[key],
                                     prefix='{0}{1}.'.format(prefix, key)))

            return keys

        return sorted(_changed(self._diffs, prefix=''))
219252
def _create_diff(diff, fun, key, prev, curr):

    '''
    
    '''

    if not fun(prev):
        _create_diff_action(diff, 'added', key, curr)
    elif fun(prev) and not fun(curr):
        _create_diff_action(diff, 'removed', key, prev)
    elif not fun(curr):
        _create_diff_action(diff, 'updated', key, curr)
976410
def _diff(text_0, text_1):
    """"""
    diff = difflib.ndiff(text_0.splitlines(), text_1.splitlines())
    return _diff_removed_lines(diff)
864275
def highlight_differences(s1, s2, color):
    """"""
    ls1, ls2 = len(s1), len(s2)

    diff_indices = [i for i, (a, b) in enumerate(zip(s1, s2)) if a != b]

    print(s1)

    if ls2 > ls1:
        colorise.cprint('_' * (ls2-ls1), fg=color)
    else:
        print()

    colorise.highlight(s2, indices=diff_indices, fg=color, end='')

    if ls1 > ls2:
        colorise.cprint('_' * (ls1-ls2), fg=color)
    else:
        print()
1263329
def rev(self, i):
        """"""
        on = copy(self)
        on.revision = i
        return on
282095
def check(self, diff):
        """"""
        path = diff.b_path
        assert any(
            path.endswith(ext)
            for ext in importlib.machinery.SOURCE_SUFFIXES
        )
1367081
function(instance, opt){
      var previousVersion = instance._previousDataValues;
      var currentVersion = instance.dataValues;

      // Disallow change of revision
      instance.set(options.revisionAttribute, instance._previousDataValues[options.revisionAttribute]);

      // Get diffs
      var diffs = getDifferences(previousVersion, currentVersion, options.exclude);

      if(diffs && diffs.length > 0){
         instance.set(options.revisionAttribute, (instance.get(options.revisionAttribute) || 0) + 1);
         if(!instance.context){
            instance.context = {};
         }
         instance.context.diffs = diffs;
      }
   }
72228
def diff(old, new):
    
    protocol = new.protocol
    version = new.version
    revision = new.revision
    metric = new.metric
    # calculate differences
    in_both = _find_unchanged(old.graph, new.graph)
    added_nodes, added_edges = _make_diff(old.graph, new.graph, in_both)
    removed_nodes, removed_edges = _make_diff(new.graph, old.graph, in_both)
    changed_edges = _find_changed(old.graph, new.graph, in_both)
    # create netjson objects
    # or assign None if no changes
    if added_nodes.nodes() or added_edges.edges():
        added = _netjson_networkgraph(protocol, version, revision, metric,
                                      added_nodes.nodes(data=True),
                                      added_edges.edges(data=True),
                                      dict=True)
    else:
        added = None
    if removed_nodes.nodes() or removed_edges.edges():
        removed = _netjson_networkgraph(protocol, version, revision, metric,
                                        removed_nodes.nodes(data=True),
                                        removed_edges.edges(data=True),
                                        dict=True)
    else:
        removed = None
    if changed_edges:
        changed = _netjson_networkgraph(protocol, version, revision, metric,
                                        [],
                                        changed_edges,
                                        dict=True)
    else:
        changed = None
    return OrderedDict((
        ('added', added),
        ('removed', removed),
        ('changed', changed)
    ))
396602
def diff(self):
        
        latest = self.latest
        current = NetJsonParser(self.json())
        return diff(current, latest)
167591
def diff_summary(self, old, new, rel_path=None):
        
        full_url_or_path = self.__url_or_path
        if rel_path is not None:
            full_url_or_path += '/' + rel_path
        result = self.run_command(
            'diff',
            ['--old', '{0}@{1}'.format(full_url_or_path, old),
             '--new', '{0}@{1}'.format(full_url_or_path, new),
             '--summarize', '--xml'],
            do_combine=True)
        root = xml.etree.ElementTree.fromstring(result)
        diff = []
        for element in root.findall('paths/path'):
            diff.append({
                'path': element.text,
                'item': element.attrib['item'],
                'kind': element.attrib['kind']})
        return diff
82890
def diff(self, obj=None):
        """"""
        if self.no_resource:
            return NOOP

        if not self.present:
            if self.existing:
                return DEL

            return NOOP

        if not obj:
            obj = self.obj()

        is_diff = NOOP
        if self.present and self.existing:
            if isinstance(self.existing, dict):
                current = dict(self.existing)
                if 'refresh_interval' in current:
                    del current['refresh_interval']

                if diff_dict(current, obj):
                    is_diff = CHANGED
            elif is_unicode(self.existing):
                if self.existing != obj:
                    is_diff = CHANGED

        elif self.present and not self.existing:
            is_diff = ADD

        return is_diff
548538
def versions(self, rev=None, index=None):
        """"""
        raise NotImplementedError
        _revisions = [line.split()[0] for line in self.log.split('\n') if line]
        _versions = [Version(self.obj.repo.commit(r)) for r in _revisions if rev is None or r.startswith(rev)]
        if index is not None and len(_versions) > index:
            _versions = _versions[index]
        return _versions