From 93be01f2da848aadb9a2238d911187147a7f85f2 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 13 Apr 2010 18:43:31 +0200 Subject: Support branches, first part. --- gitnoti.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/gitnoti.py b/gitnoti.py index 6a5de5f..cc78c4b 100755 --- a/gitnoti.py +++ b/gitnoti.py @@ -37,8 +37,8 @@ if root[-1] == '/': repos = None -def repo_commit_msg(repo, commits): - reponame = os.path.splitext(os.path.basename(repo.path))[0] +def repo_commit_msg(repo, branch, commits): + reponame = os.path.splitext(os.path.basename(repo.working_dir))[0] deletions = insertions = 0 files = [] @@ -55,9 +55,10 @@ def repo_commit_msg(repo, commits): stat += ' \00303++%d\017' % insertions commit = commits[-1] - msg = '\002%s\002 pushed to \002%s\002 by \002%s\002 (%s) %s' % ( + msg = '\002%s/%s\002 pushed to \002%s\002 by \002%s\002 (%s) %s' % ( reponame, - commit.id_abbrev, + branch, + commit.sha[:7], commit.committer.name if commit.author.name == commit.committer.name else '%s/%s' % (commit.committer.name, commit.author.name), stat, commit.summary @@ -65,7 +66,7 @@ def repo_commit_msg(repo, commits): if options.url: msg += ' | ' - url = options.url % {'repo': reponame, 'commit': commit.id} + url = options.url % {'repo': reponame, 'commit': commit.sha} if have_bitly: short_url = None try: @@ -109,15 +110,19 @@ class ReposNotifyEvent(pyinotify.ProcessEvent): if not l[0]: l[0] = git.Repo(pathname) repo = l[0] - if not repo.heads: # No commits + if not repo.heads: # No branches return - last = l[1] - nlast = repo.heads[0].commit - if nlast.id != last: - commits = list(repo.commits_between(last, 'HEAD')) - msg = repo_commit_msg(repo, commits) - self.bot.gitmsg(msg) - l[1] = nlast.id + if not l[1]: + l[1] = dict([(h.name, h.commit.sha) for h in repo.heads]) + for h in repo.heads: + last = l[1][h.name] if h.name in l[1] else None + if h.commit.sha != last: + commits = list(repo.iter_commits('%s..%s' % (last, h.name))) + if not len(commits): # No commits + continue + msg = repo_commit_msg(repo, h.name, commits) + self.bot.gitmsg(msg) + l[1][h.name] = h.commit.sha def process_IN_CREATE(self, event): if os.path.dirname(event.pathname) == root: @@ -154,7 +159,7 @@ class Bot(irc.IRCClient): continue flags = pyinotify.EventsCodes.ALL_FLAGS wdd = self.wm.add_watch('%s/%s/refs/heads' % (root, path), flags['IN_MODIFY'] | flags['IN_CREATE']) - repos['%s/%s' % (root, path)] = [r, r.heads[0].commit.id if r.heads else None, wdd] + repos['%s/%s' % (root, path)] = [r, dict([(h.name, h.commit.sha) for h in r.heads]), wdd] def gitmsg(self, msg): self.say(options.channel, msg) @@ -220,7 +225,7 @@ class Bot(irc.IRCClient): if not repo: return - msg = repo_commit_msg(repo, [repo.heads[0].commit]) if repo.heads else ('No commits found for %s' % os.path.splitext(os.path.basename(repo.path))[0]) + msg = repo_commit_msg(repo, [repo.heads[0].commit]) if repo.heads else ('No commits found for %s' % os.path.splitext(os.path.basename(repo.working_dir))[0]) self.msg(target, msg) elif cmd == 'show': if not len(messagelist) == 4: -- cgit v1.2.3