Add support for custom gitweb tabwidth
authorMagnus Hagander <magnus@hagander.net>
Wed, 22 Dec 2010 13:57:27 +0000 (14:57 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 22 Dec 2010 13:57:27 +0000 (14:57 +0100)
gitadmin/adm/models.py
gitdump.py

index e0a664679e230403d3ff55d94de3d0e5b8a54b3a..5825ffa843d4ec08a4114d3e6bcbb9ea04a5af9a 100644 (file)
@@ -37,6 +37,7 @@ class Repository(models.Model):
        anonymous = models.BooleanField(blank=False,verbose_name='Enable anonymous access')
        web = models.BooleanField(blank=False,verbose_name='Enable gitweb access')
        approved = models.BooleanField(blank=False)
+       tabwidth = models.IntegerField(default=8, null=False)
        initialclone = models.CharField(max_length=256, blank=True, null=True)
        remoterepository = models.ForeignKey(RemoteRepository, null=True, blank=True,
                        verbose_name='Remote repository')
index fac9f4b5e024b47dbe98f8d96ecd349b953c97b8..7fa202506459422a76d6a996bfc82bd91174cff1 100644 (file)
@@ -19,6 +19,18 @@ import ConfigParser
 import urllib
 from util.LockFile import LockFile
 
+class TabRemover(object):
+       """
+       Trivial class that removes leading tabs from each row of a file
+       being read.
+       """
+       def __init__(self, filename):
+               self.f = open(filename)
+
+       def readline(self):
+               return self.f.readline().lstrip("\t")
+
+
 class AuthorizedKeysDumper(object):
        def __init__(self, db, conf):
                self.db = db
@@ -45,7 +57,7 @@ class AuthorizedKeysDumper(object):
                allrepos = {}
                curs = self.db.cursor()
                curs.execute("""
-SELECT name,anonymous,web,description,initialclone,
+SELECT name,anonymous,web,description,initialclone,tabwidth,
                COALESCE(
                (SELECT min(first_name) FROM repository_permissions AS rp
                        LEFT JOIN auth_user AS au ON au.username=rp.userid
@@ -55,7 +67,7 @@ SELECT name,anonymous,web,description,initialclone,
                 THEN 1 ELSE 0 END
 FROM repositories AS r WHERE approved ORDER BY name""")
                f = open("%s.tmp" % self.conf.get("paths", "gitweblist"), "w")
-               for name, anon, web, description, initialclone, owner, remoterepo in curs:
+               for name, anon, web, description, initialclone, tabwidth, owner, remoterepo in curs:
                        allrepos[name] = 1
                        repopath = "%s/repos/%s.git" % (self.conf.get("paths", "githome"), name)
 
@@ -100,6 +112,23 @@ FROM repositories AS r WHERE approved ORDER BY name""")
                                df = open("%s/description" % repopath, "w")
                                df.write(description)
                                df.close()
+                               # Check if we need to change the tab width (default is 8)
+                               repoconf = ConfigParser.ConfigParser()
+                               repoconf.readfp(TabRemover("%s/config" % repopath))
+                               tabwidth_mod = False
+                               if repoconf.has_option('gitweb', 'tabwidth'):
+                                       if tabwidth != int(repoconf.get('gitweb', 'tabwidth')):
+                                               tabwidth_mod = True
+                               else:
+                                       # Not specified, so it's 8...
+                                       if tabwidth != 8:
+                                               tabwidth_mod = True
+                               if tabwidth_mod:
+                                       if not repoconf.has_section('gitweb'):
+                                               repoconf.add_section('gitweb')
+                                       repoconf.set('gitweb', 'tabwidth', tabwidth)
+                                       with open("%s/config" % repopath, "wb") as cf:
+                                               repoconf.write(cf)
 
                        anonfile = "%s/git-daemon-export-ok" % repopath
                        htafile = "%s/.htaccess" % repopath