Git

Static git hosting with stagit

I like hosting my own services when possible. But I don’t like maintaining complex systems, so instead of setting up my own GitLab, Gitea, or Gogs service I decided to follow the same path I took with this blog and host some of my git repos as static html pages using stagit .

One of the neat features of git is that you can actually clone from one of these static repos so they aren’t just html pages but are full copies of the git repo, complete with history.

Nice %changelog entries

When updating a rpm package it is nice to include a summary of the changes made since the last time. anaconda does this with a nifty script written by dcantrell called makebumpver which also enforces some RHEL rules and handles changing the version. I only needed the changelog part of this so I modified the script a bit to remove the extras:

#!/usr/bin/python
#
# git-changelog - Output a rpm changelog
#
# Copyright (C) 2009-2010  Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: David Cantrell <dcantrell@redhat.com>
# Author: Brian C. Lane <bcl@redhat.com>

import os
import re
import subprocess
import sys
import textwrap
from optparse import OptionParser

class ChangeLog:
    def __init__(self, tag):
        self.tag = tag
        self.ignore = None

    def _getCommitDetail(self, commit, field):
        proc = subprocess.Popen(['git', 'log', '-1',
                                 "--pretty=format:%s" % field, commit],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE).communicate()

        ret = proc[0].strip('\n').split('\n')

        if len(ret) == 1 and ret[0].find('@') != -1:
            ret = ret[0].split('@')[0]
        elif len(ret) == 1:
            ret = ret[0]
        else:
            ret = filter(lambda x: x != '', ret)

        return ret

    def getLog(self):
        range = "%s.." % (self.tag)
        proc = subprocess.Popen(['git', 'log', '--pretty=oneline', range],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE).communicate()
        lines = filter(lambda x: x.find('l10n: ') != 41 and \
                                 x.find('Merge commit') != 41 and \
                                 x.find('Merge branch') != 41,
                       proc[0].strip('\n').split('\n'))

        if self.ignore and self.ignore != '':
            for commit in self.ignore.split(','):
                lines = filter(lambda x: not x.startswith(commit), lines)

        log = []
        for line in lines:
            fields = line.split(' ')
            commit = fields[0]

            summary = self._getCommitDetail(commit, "%s")
            long = self._getCommitDetail(commit, "%b")
            author = self._getCommitDetail(commit, "%aE")

            log.append(("%s (%s)" % (summary.strip(), author)))

        return log

    def formatLog(self):
        s = ""
        for msg in self.getLog():
            sublines = textwrap.wrap(msg, 77)
            s = s + "- %s\n" % sublines[0]

            if len(sublines) > 1:
                for subline in sublines[1:]:
                    s = s + "  %s\n" % subline

        return s

def main():
    parser = OptionParser()
    parser.add_option("-t", "--tag", dest="tag",
                      help="Last tag, changelog is commits after this tag")
    (options, args) = parser.parse_args()

    cl = ChangeLog(options.tag)
    print cl.formatLog()

if __name__ == "__main__":
    main()

I've copied my version of this here for easy downloading. Run it like this - git-changelog -t livecd-tools-15.0 and the output is:

color output from git log -p on OSX

By default git on OSX wasn't colorizing its output. Two things needed to be setup - setting the color.ui to auto and setting the pager (less) to allow raw characters. Add this to ~/.gitconfig

[color]
ui = auto
[core]
pager = less -R

Presto! Nice colorized output from git!