From: Catalin Marinas <catalin.marinas@arm.com>
To: git@vger.kernel.org, "Karl Hasselström" <kha@treskal.com>
Subject: [StGit PATCH 9/9] Use the default git colouring scheme rather than specific scripts
Date: Tue, 28 Apr 2009 16:10:25 +0100 [thread overview]
Message-ID: <20090428151025.27261.15964.stgit@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <20090428150742.27261.19620.stgit@pc1117.cambridge.arm.com>
This patch adds the mechanism to check if the output is tty for the
diff and show commands and passes the --color option to git if the
color.diff config option is set auto or true. The patch also changes the
default pager to 'less -FRSX' from the diffcol.sh script.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
contrib/diffcol.sh | 51 ----------------------------------------------
examples/gitconfig | 4 ++--
setup.py | 3 +--
stgit/commands/common.py | 8 +++++++
stgit/commands/diff.py | 2 ++
stgit/commands/show.py | 1 +
stgit/config.py | 10 +++++----
7 files changed, 19 insertions(+), 60 deletions(-)
delete mode 100755 contrib/diffcol.sh
diff --git a/contrib/diffcol.sh b/contrib/diffcol.sh
deleted file mode 100755
index eecc87a..0000000
--- a/contrib/diffcol.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/bin/bash
-
-# Code copied from Quilt (http://savannah.nongnu.org/projects/quilt)
-#
-# Copyright 2006 - the Quilt authors
-#
-# This script is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-
-setup_colors()
-{
- local C="diffhdr=1;36:diffhdradd=1;32:diffadd=32:diffhdrmod=1;35:diffmod=35:diffhdrrem=1;31:diffrem=31:diffhunk=36:diffctx=34:diffcctx=33:default=0"
- [ -n "$DIFF_COLORS" ] && C="$C:$DIFF_COLORS"
-
- C=${C//=/=\'$'\e'[}
- C=col${C//:/m\'; col}m\'
- #coldefault=$(tput op)
- eval $C
-}
-
-setup_colors
-
-gawk '{
- if (/^(Index:|diff --git) /)
- print "'$coldiffhdr'" $0 "'$coldefault'"
- else if (/^======*$/)
- print "'$coldiffhdr'" $0 "'$coldefault'"
- else if (/^\+\+\+/)
- print "'$coldiffhdradd'" $0 "'$coldefault'"
- else if (/^\*\*\*/)
- print "'$coldiffhdrmod'" $0 "'$coldefault'"
- else if (/^---/)
- print "'$coldiffhdrrem'" $0 "'$coldefault'"
- else if (/^(\+|new( file)? mode )/)
- print "'$coldiffadd'" $0 "'$coldefault'"
- else if (/^(-|(deleted file|old) mode )/)
- print "'$coldiffrem'" $0 "'$coldefault'"
- else if (/^!/)
- print "'$coldiffmod'" $0 "'$coldefault'"
- else if (/^@@ \-[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@/)
- print gensub(/^(@@[^@]*@@)([ \t]*)(.*)/,
- "'$coldiffhunk'" "\\1" "'$coldefault'" \
- "\\2" \
- "'$coldiffctx'" "\\3" "'$coldefault'", "")
- else if (/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/)
- print "'$coldiffcctx'" $0 "'$coldefault'"
- else {
- print
- }
-}' $1 | less -R -S
diff --git a/examples/gitconfig b/examples/gitconfig
index f6e3a79..e235e14 100644
--- a/examples/gitconfig
+++ b/examples/gitconfig
@@ -42,8 +42,8 @@
#editor = /usr/bin/vi
# this value overrides the default PAGER environment variable
- #pager = ~/share/stgit/contrib/diffcol.sh
- #pager = filterdiff --annotate | colordiff | less -FRX
+ #pager = less -FRSX
+ #pager = filterdiff --annotate | colordiff | less -FRSX
# GIT pull and fetch commands (should take the same arguments as
# git fetch or git pull). By default:
diff --git a/setup.py b/setup.py
index fb67958..73ce2e5 100755
--- a/setup.py
+++ b/setup.py
@@ -58,8 +58,7 @@ def __run_setup():
('share/stgit/templates', glob.glob('templates/*.tmpl')),
('share/stgit/examples', glob.glob('examples/*.tmpl')),
('share/stgit/examples', ['examples/gitconfig']),
- ('share/stgit/contrib', ['contrib/diffcol.sh',
- 'contrib/stgbashprompt.sh']),
+ ('share/stgit/contrib', ['contrib/stgbashprompt.sh']),
('share/stgit/completion', ['stgit-completion.bash'])
])
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 6bb3685..e46412e 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -83,6 +83,14 @@ def git_commit(name, repository, branch_name = None):
except libgit.RepositoryException:
raise CmdException('%s: Unknown patch or revision name' % name)
+def color_diff_flags():
+ """Return the git flags for coloured diff output if the configuration and
+ stdout allows."""
+ if sys.stdout.isatty() and config.get('color.diff') in ['true', 'auto']:
+ return ['--color']
+ else:
+ return []
+
def check_local_changes():
if git.local_changes():
raise CmdException('local changes in the tree. Use "refresh" or'
diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py
index 7d2f719..8b8ebe3 100644
--- a/stgit/commands/diff.py
+++ b/stgit/commands/diff.py
@@ -72,6 +72,8 @@ def func(parser, options, args):
rev1 = 'HEAD'
rev2 = None
+ if not options.stat:
+ options.diff_flags.extend(color_diff_flags())
diff_str = git.diff(args, git_id(crt_series, rev1),
rev2 and git_id(crt_series, rev2),
diff_flags = options.diff_flags)
diff --git a/stgit/commands/show.py b/stgit/commands/show.py
index 895943a..b7a8aa9 100644
--- a/stgit/commands/show.py
+++ b/stgit/commands/show.py
@@ -61,6 +61,7 @@ def func(parser, options, args):
# individual patches or commit ids
patches = args
+ options.diff_flags.extend(color_diff_flags())
commit_ids = [git_id(crt_series, patch) for patch in patches]
commit_str = '\n'.join([git.pretty_commit(commit_id,
flags = options.diff_flags)
diff --git a/stgit/config.py b/stgit/config.py
index efce097..4f16978 100644
--- a/stgit/config.py
+++ b/stgit/config.py
@@ -37,7 +37,8 @@ class GitConfig:
'stgit.autoimerge': 'no',
'stgit.keepoptimized': 'no',
'stgit.extensions': '.ancestor .current .patched',
- 'stgit.shortnr': '5'
+ 'stgit.shortnr': '5',
+ 'stgit.pager': 'less -FRSX'
}
__cache={}
@@ -109,10 +110,9 @@ config=GitConfig()
def config_setup():
global config
- # Set the PAGER environment to the config value (if any)
- pager = config.get('stgit.pager')
- if pager:
- os.environ['PAGER'] = pager
+ # Set the PAGER environment to the config value if not already set
+ if not 'PAGER' in os.environ:
+ os.environ['PAGER'] = config.get('stgit.pager')
# FIXME: handle EDITOR the same way ?
class ConfigOption:
next prev parent reply other threads:[~2009-04-28 15:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-28 15:09 [StGit PATCH 0/9] Various StGit updates Catalin Marinas
2009-04-28 15:09 ` [StGit PATCH 1/9] Show "Pushing <patch>...done" when pushing a patch Catalin Marinas
2009-04-29 6:04 ` Karl Hasselström
2009-04-28 15:09 ` [StGit PATCH 2/9] Show some progress information when checking for upstream merges Catalin Marinas
2009-04-29 6:07 ` Karl Hasselström
2009-04-28 15:09 ` [StGit PATCH 3/9] Do not sleep after the last patch sent by e-mail Catalin Marinas
2009-04-29 6:13 ` Karl Hasselström
2009-04-28 15:09 ` [StGit PATCH 4/9] Convert 'clone' to the use stgit.lib Catalin Marinas
2009-04-29 6:21 ` Karl Hasselström
2009-05-13 16:10 ` Catalin Marinas
2009-04-28 15:10 ` [StGit PATCH 5/9] Convert 'hide' to the lib infrastructure Catalin Marinas
2009-04-29 6:27 ` Karl Hasselström
2009-05-13 16:08 ` Catalin Marinas
2009-04-28 15:10 ` [StGit PATCH 6/9] Convert 'unhide' " Catalin Marinas
2009-04-29 6:29 ` Karl Hasselström
2009-04-28 15:10 ` [StGit PATCH 7/9] Reinstate the --annotate option for refresh Catalin Marinas
2009-04-29 6:33 ` Karl Hasselström
2009-04-28 15:10 ` [StGit PATCH 8/9] Add the log --clear option Catalin Marinas
2009-04-29 6:35 ` Karl Hasselström
2009-04-28 15:10 ` Catalin Marinas [this message]
2009-04-29 6:43 ` [StGit PATCH 9/9] Use the default git colouring scheme rather than specific scripts Karl Hasselström
2009-04-29 11:48 ` Samuel Tardieu
2009-04-29 11:56 ` Samuel Tardieu
2009-04-29 14:25 ` Karl Hasselström
2009-05-04 12:48 ` Shinya Kuribayashi
2009-05-29 12:22 ` Catalin Marinas
2009-05-30 0:36 ` Shinya Kuribayashi
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=20090428151025.27261.15964.stgit@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=kha@treskal.com \
/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).