Use gitconfig rather than stgirc
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 5 Dec 2006 22:07:22 +0000 (22:07 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 5 Dec 2006 22:07:22 +0000 (22:07 +0000)
This patch enables the use of gitconfig files (~/.gitconfig or
.git/config) rather than stgitrc. These files can have a [stgit]
section. Currently, the git config lines have to be stripped since the
options are prepended with spaces.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
examples/gitconfig [moved from examples/stgitrc with 57% similarity]
setup.py
stgit/config.py

similarity index 57%
rename from examples/stgitrc
rename to examples/gitconfig
index 9ed2988..9a5cd07 100644 (file)
@@ -1,62 +1,62 @@
-# StGIT configuration file. Copy it to any of /etc/stgitrc, ~/.stgitrc
-# or .git/stgitrc and modify as needed. Note that the latter overrides
-# the former.
+# StGIT configuration file. Copy it to any of ~/.gitconfig or
+# .git/gitconfig and modify as needed. Note that the latter overrides
+# the former. The "git repo-config" command can be used as well
 
 [stgit]
 # Default author/committer details
-#authname Your Name
-#authemail: your.name@yourcompany.com
-#commname Your Name
-#commemail: your.name@yourcompany.com
+#authname = Your Name
+#authemail = your.name@yourcompany.com
+#commname = Your Name
+#commemail = your.name@yourcompany.com
 
 # E-mail sender (added to the "From: " header)
-#sender: Your Name <your.name@yourcompany.com>
+#sender = Your Name <your.name@yourcompany.com>
 
 # Automatically Bcc the address below
-#autobcc: your.name@yourcompany.com
+#autobcc = your.name@yourcompany.com
 
 # Set to 'yes' if you don't want to use the 'resolved' command.
 # 'refresh' will automatically mark the conflicts as resolved
-#autoresolved: no
+#autoresolved = no
 
-#smtpserver: localhost:25
-#smtpuser: username
-#smtppassword: password
+#smtpserver = localhost:25
+#smtpuser = username
+#smtppassword = password
 
 # delay between messages in seconds (defaults to 5)
-#smtpdelay: 5
+#smtpdelay = 5
 
 # stg will look for this first, then look for the EDITOR environmental
 # variable, then default to using 'vi'
-#editor: /usr/bin/vi
+#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 = ~/share/stgit/contrib/diffcol.sh
+#pager = filterdiff --annotate | colordiff | less -FRX
 
 # GIT pull command (should take the same arguments as git-pull)
-#pullcmd: git-pull
+#pullcmd = git-pull
 
 # The three-way merge tool. Note that the 'output' file contains the
 # same data as 'branch1'. This is useful for tools that do not take an
 # output parameter
-#merger: diff3 -L current -L ancestor -L patched -m -E \
+#merger = diff3 -L current -L ancestor -L patched -m -E \
 #      "%(branch1)s" "%(ancestor)s" "%(branch2)s" > "%(output)s"
 
 # Interactive three-way merge tool. It is executed by the 'resolved
 # --interactive' command
-#imerger: xxdiff --title1 current --title2 ancestor --title3 patched \
+#imerger = xxdiff --title1 current --title2 ancestor --title3 patched \
 #      --show-merged-pane -m -E -O -X -M "%(output)s" \
 #      "%(branch1)s" "%(ancestor)s" "%(branch2)s"
-#imerger: emacs --eval '(ediff-merge-files-with-ancestor
+#imerger = emacs --eval '(ediff-merge-files-with-ancestor \
 #      "%(branch1)s" "%(branch2)s" "%(ancestor)s" nil "%(output)s")'
 
 # Leave the original files in the working tree in case of a merge conflict
-#keeporig: yes
+#keeporig = yes
 
 # Optimize (repack) the object store after every pull
-#keepoptimized: yes
+#keepoptimized = yes
 
 # Extensions for the files involved in a three-way merge (ancestor,
 # current, patched)
-#extensions: .ancestor .current .patched
+#extensions = .ancestor .current .patched
index e9030a8..dc25149 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ setup(name = 'stgit',
       packages = ['stgit', 'stgit.commands'],
       data_files = [('share/stgit/templates', glob.glob('templates/*.tmpl')),
                     ('share/stgit/examples', glob.glob('examples/*.tmpl')),
-                    ('share/stgit/examples', ['examples/stgitrc']),
+                    ('share/stgit/examples', ['examples/gitconfig']),
                     ('share/stgit/contrib', ['contrib/diffcol.sh',
                                              'contrib/stgbashprompt.sh',
                                              'contrib/stgit-completion.bash']),
index 6679668..b56ab1b 100644 (file)
@@ -19,12 +19,44 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import os, ConfigParser
-
+from StringIO import StringIO
 from stgit import basedir
 
-
 config = ConfigParser.RawConfigParser()
 
+def git_config(filename):
+    """Open a git config file and convert it to be understood by
+    Python."""
+    try:
+        f = file(filename)
+        cont = False
+        lines = []
+        for line in f:
+            line = line.strip()
+
+            if cont:
+                # continued line, add a space at the beginning
+                line = ' ' + line
+
+            if line and line[-1] == '\\':
+                line = line[:-1].rstrip()
+                cont = True
+            else:
+                line = line + '\n'
+                cont = False
+
+            lines.append(line)
+
+        f.close()
+        cfg_str = ''.join(lines)
+    except IOError:
+        cfg_str = ''
+
+    strio = StringIO(cfg_str)
+    strio.name = filename
+
+    return strio
+
 def config_setup():
     global config
 
@@ -42,10 +74,15 @@ def config_setup():
     config.set('stgit', 'extensions', '.ancestor .current .patched')
 
     # Read the configuration files (if any) and override the default settings
+    # stgitrc are read for backward compatibility
     config.read('/etc/stgitrc')
     config.read(os.path.expanduser('~/.stgitrc'))
     config.read(os.path.join(basedir.get(), 'stgitrc'))
 
+    # GIT configuration files can have a [stgit] section
+    config.readfp(git_config(os.path.expanduser('~/.gitconfig')))
+    config.readfp(git_config(os.path.join(basedir.get(), 'config')))
+
     # Set the PAGER environment to the config value (if any)
     if config.has_option('stgit', 'pager'):
         os.environ['PAGER'] = config.get('stgit', 'pager')