git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [StGit PATCH 9/9] Use the default git colouring scheme rather than specific scripts

From
CMCatalin Marinas <catalin.marinas@gmail.com>
Date
May 29, 2009, 12:22 UTC
Message-ID
<b0943d9e0905290522l377c8f35h7f442b183cb7c7d2@mail.gmail.com>
In-Reply-To
<49FEE41F.4010006@ruby.dti.ne.jp>
2009/5/4 Shinya Kuribayashi <skuribay@ruby.dti.ne.jp>:
Show 17 quoted lines
> Catalin Marinas wrote:
>>  +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'
>
> Junio introduces `color.ui=auto' as one of base settings in his recent
> Japanese article for Git newbies:

That's probably a better option. I changed the patch to this (only showing the relevant parts):

--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -97,6 +97,15 @@ 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."""
+    stdout_is_tty = (sys.stdout.isatty() and 'true') or 'false'
+    if config.get_colorbool('color.diff', stdout_is_tty) == 'true':
+        return ['--color']
+    else:
+        return []
+
 def check_local_changes():
     if git.local_changes():
         raise CmdException('local changes in the tree. Use "refresh" or'

--- a/stgit/config.py
+++ b/stgit/config.py
@@ -109,16 +110,18 @@ class GitConfig:
             if m:
                 result.append(m.group(1))
         return result
+
+    def get_colorbool(self, name, stdout_is_tty):
+        """Invoke 'git config --get-colorbool' and return the result."""
+        return Run('git', 'config', '--get-colorbool', name,
+                   stdout_is_tty).output_one_line()

 config=GitConfig()

>> 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={}
>
> Wrong indentation? :-)

The indentation is right, only that in the past there was a tab left
which I removed with this occasion.
-- 
Catalin
Previous: Shinya KuribayashiNext: Shinya Kuribayashi
Message 26 of 27 in “Various StGit updates”
  1. 0/9 Various StGit updatesCatalin Marinas, Apr 28, 2009
  2. 1/9 Show "Pushing <patch>...done" when pushing a patchCatalin Marinas, Apr 28, 2009
  3. Karl HasselströmApr 29, 2009
  4. 2/9 Show some progress information when checking for upstream merges.Catalin Marinas, Apr 28, 2009
  5. Karl HasselströmApr 29, 2009
  6. 3/9 Do not sleep after the last patch sent by e-mailCatalin Marinas, Apr 28, 2009
  7. Karl HasselströmApr 29, 2009
  8. 4/9 Convert 'clone' to the use stgit.libCatalin Marinas, Apr 28, 2009
  9. Karl HasselströmApr 29, 2009
  10. Catalin MarinasMay 13, 2009
  11. 5/9 Convert 'hide' to the lib infrastructureCatalin Marinas, Apr 28, 2009
  12. Karl HasselströmApr 29, 2009
  13. Catalin MarinasMay 13, 2009
  14. 6/9 Convert 'unhide' to the lib infrastructureCatalin Marinas, Apr 28, 2009
  15. Karl HasselströmApr 29, 2009
  16. 7/9 Reinstate the --annotate option for refreshCatalin Marinas, Apr 28, 2009
  17. Karl HasselströmApr 29, 2009
  18. 8/9 Add the log --clear optionCatalin Marinas, Apr 28, 2009
  19. Karl HasselströmApr 29, 2009
  20. 9/9 Use the default git colouring scheme rather than specific scriptsCatalin Marinas, Apr 28, 2009
  21. Karl HasselströmApr 29, 2009
  22. Samuel TardieuApr 29, 2009
  23. Samuel TardieuApr 29, 2009
  24. Karl HasselströmApr 29, 2009
  25. Shinya KuribayashiMay 4, 2009
  26. Catalin MarinasMay 29, 2009
  27. Shinya KuribayashiMay 30, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.