git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Adeodato Simó" <dato@net.com.org.es>
To: Jeff King <peff@peff.net>
Cc: Git ML <git@vger.kernel.org>
Subject: Bazaar's patience diff as GIT_EXTERNAL_DIFF
Date: Sat, 3 Jan 2009 17:24:11 +0100	[thread overview]
Message-ID: <20090103162411.GA9234@chistera.yi.org> (raw)
In-Reply-To: <20090102193904.GB9129@coredump.intra.peff.net>

[-- Attachment #1: Type: text/plain, Size: 974 bytes --]

* Jeff King [Fri, 02 Jan 2009 14:39:04 -0500]:

> If you just want to see the results on some real-world cases (and don't
> care about measuring performance), try installing bzr and using their
> patiencediff test program as a GIT_EXTERNAL_DIFF.

> On Debian, it's:

>   $ sudo apt-get install bzr
>   $ cat >$HOME/patience <<'EOF'
>     #!/bin/sh
>     exec python /usr/share/pyshared/bzrlib/patiencediff.py "$2" "$5"
>     EOF
>   $ chmod 755 patience
>   $ GIT_EXTERNAL_DIFF=$HOME/patience git diff

In case somebody's interested, I have this script lying around that does
that, and knows how to colorize the output using bzrtools, and honoring
color.{diff,ui}. No support for color.diff.<slot>, though.

-- 
Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
 
- Oh my God, you're pimping me out for a new roof?
- And windows!
                -- Andrew and Bree Van De Kamp

[-- Attachment #2: git_bzr_patience_diff --]
[-- Type: text/plain, Size: 1457 bytes --]

#! /usr/bin/python

import os
import sys
import stat
import subprocess

from bzrlib.patiencediff import unified_diff, PatienceSequenceMatcher
try:
    from bzrlib.plugins.bzrtools.colordiff import DiffWriter
except ImportError:
    _have_colordiff = False
else:
    _have_colordiff = True

##

def main():
    path = sys.argv[1]
    file1 = open(sys.argv[2], 'rb')
    file2 = open(sys.argv[5], 'rb')

    if use_color():
        writer = DiffWriter(sys.stdout, check_style=True)
    else:
        writer = sys.stdout

    for line in unified_diff(
            file1.readlines(), file2.readlines(),
            path, path, sequencematcher=PatienceSequenceMatcher):
        writer.write(line)

##

def use_color():
    if not _have_colordiff:
        return False

    for c in ['color.diff', 'color.ui']:
        p = subprocess.Popen(
                ['git', 'config', '--get', c], stdout=subprocess.PIPE)
        if p.wait() == 0:
            when = p.stdout.readline().strip()
            break
    else:
        return False

    if when == 'always':
        return True
    elif when in ['false', 'never']:
        return False
    elif when in ['true', 'auto']:
        stdout = sys.stdout.fileno()
        return (os.isatty(stdout) or
                stat.S_ISFIFO(os.fstat(sys.stdout.fileno()).st_mode))
    else:
        return False

##

if __name__ == '__main__':
    sys.exit(main())

  parent reply	other threads:[~2009-01-03 16:25 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04  0:40 libxdiff and patience diff Pierre Habouzit
2008-11-04  3:17 ` Davide Libenzi
2008-11-04  8:33   ` Pierre Habouzit
2008-11-04  5:39 ` Johannes Schindelin
2008-11-04  8:30   ` Pierre Habouzit
2008-11-04 14:34     ` Johannes Schindelin
2008-11-04 15:23       ` Pierre Habouzit
2008-11-04 15:57         ` Johannes Schindelin
2008-11-04 16:15           ` Pierre Habouzit
2009-01-01 16:38         ` [PATCH 0/3] Teach Git about the patience diff algorithm Johannes Schindelin
2009-01-01 16:38           ` [PATCH 1/3] Implement " Johannes Schindelin
2009-01-01 16:39           ` [PATCH 2/3] Introduce the diff option '--patience' Johannes Schindelin
2009-01-01 16:39           ` [PATCH 3/3] bash completions: Add the --patience option Johannes Schindelin
2009-01-01 19:45           ` [PATCH 0/3] Teach Git about the patience diff algorithm Linus Torvalds
2009-01-01 20:00             ` Linus Torvalds
2009-01-02 18:17               ` Johannes Schindelin
2009-01-02 18:49                 ` Linus Torvalds
2009-01-02 19:07                   ` Johannes Schindelin
2009-01-02 18:51                 ` Jeff King
2009-01-02 21:59               ` [PATCH 1/3 v2] Implement " Johannes Schindelin
2009-01-02 21:59                 ` Johannes Schindelin
2009-01-01 20:46             ` [PATCH 0/3] Teach Git about " Adeodato Simó
2009-01-02  1:56               ` Linus Torvalds
2009-01-02 10:55                 ` Clemens Buchacher
2009-01-02 10:58                   ` Clemens Buchacher
2009-01-02 16:42                     ` Linus Torvalds
2009-01-02 18:46                       ` Johannes Schindelin
2009-01-02 19:03                         ` Linus Torvalds
2009-01-02 19:22                           ` Johannes Schindelin
2009-01-02 19:39                           ` Jeff King
2009-01-02 19:50                             ` Jeff King
2009-01-02 20:52                               ` Jeff King
2009-01-02 23:05                                 ` Linus Torvalds
2009-01-03 16:24                             ` Adeodato Simó [this message]
2009-01-02 21:59                       ` Johannes Schindelin
2009-01-08 19:55                       ` Adeodato Simó
2009-01-08 20:06                         ` Adeodato Simó
2009-01-09  6:54                         ` Junio C Hamano
2009-01-09 13:07                           ` Johannes Schindelin
2009-01-09 15:59                             ` Adeodato Simó
2009-01-09 18:09                             ` Linus Torvalds
2009-01-09 18:13                               ` Linus Torvalds
2009-01-09 20:53                             ` Junio C Hamano
2009-01-10 11:36                               ` Johannes Schindelin
2009-01-02 11:03                   ` Junio C Hamano
2009-01-02 18:50                 ` Adeodato Simó
2009-01-06 11:17     ` Pierre Habouzit
2009-01-06 11:39       ` Pierre Habouzit
2009-01-06 19:40       ` Johannes Schindelin
2009-01-07 14:39         ` Pierre Habouzit
2009-01-07 17:01           ` Johannes Schindelin
2009-01-07 17:04             ` [PATCH v3 1/3] Implement " Johannes Schindelin
2009-01-07 18:10               ` Davide Libenzi
2009-01-07 18:32                 ` Johannes Schindelin
2009-01-07 20:09                   ` Davide Libenzi
2009-01-07 20:19                     ` Johannes Schindelin
2009-01-07 18:59                 ` Linus Torvalds
2009-01-07 20:00                   ` Johannes Schindelin
2009-01-07 20:11                   ` Davide Libenzi
2009-01-07 20:15         ` [PATCH 0/3] Teach Git about " Sam Vilain
2009-01-07 20:25           ` Linus Torvalds
2009-01-08  2:31             ` Sam Vilain
2009-01-07 20:38           ` Johannes Schindelin
2009-01-07 20:48             ` Junio C Hamano
2009-01-07 22:00               ` Johannes Schindelin
2009-01-07 22:45                 ` Pierre Habouzit
2009-01-07 23:03                   ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090103162411.GA9234@chistera.yi.org \
    --to=dato@net.com.org.es \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).