From 6a233b6d2841fa7808dfd815dbf6f8350fe6dd57 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 1 Oct 2010 22:03:47 +0200 Subject: Added copyright and GNU GPL notice to gitnoti.py. --- gitnoti.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gitnoti.py b/gitnoti.py index 13bc6ae..7ee11a2 100755 --- a/gitnoti.py +++ b/gitnoti.py @@ -1,5 +1,21 @@ #!/usr/bin/env python +# gitnotipy - An IRC bot which announces changes to a collection of git repositories +# Copyright (C) 2009-2010 Jon Bergli Heier + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + import git, os, sys, time, pyinotify, netrc from optparse import OptionParser from twisted.words.protocols import irc -- cgit v1.2.3 From 65499d83aa2f1c30188db207094e0944c62672d5 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 19 Oct 2010 21:33:41 +0200 Subject: commit.sha is now commit.hexsha. --- gitnoti.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitnoti.py b/gitnoti.py index 7ee11a2..76a2930 100755 --- a/gitnoti.py +++ b/gitnoti.py @@ -60,7 +60,7 @@ class NotifyRepo(object): self.repo = git.Repo(path) flags = pyinotify.EventsCodes.ALL_FLAGS self.wdd = bot.wm.add_watch([os.path.join(path, 'refs/heads'), os.path.join(path, 'refs/tags')], flags['IN_MODIFY'] | flags['IN_CREATE']) - self.heads = dict([(h.name, h.commit.sha) for h in self.repo.heads]) + self.heads = dict([(h.name, h.commit.hexsha) for h in self.repo.heads]) self.tags = [t.name for t in self.repo.tags] def repo_commit_msg(repo, branch, commits): @@ -84,7 +84,7 @@ def repo_commit_msg(repo, branch, commits): msg = '\002%s%s\002 pushed to \002%s\002 by \002%s\002 (%s) %s' % ( reponame, ('/'+branch) if branch else '', - commit.sha[:7], + commit.hexsha[:7], commit.committer.name if commit.author.name == commit.committer.name else '%s/%s' % (commit.committer.name, commit.author.name), stat, commit.summary @@ -92,7 +92,7 @@ def repo_commit_msg(repo, branch, commits): if options.url: msg += ' | ' - url = options.url % {'repo': reponame, 'commit': commit.sha} + url = options.url % {'repo': reponame, 'commit': commit.hexsha} if have_bitly: short_url = None try: @@ -160,7 +160,7 @@ class ReposNotifyEvent(pyinotify.ProcessEvent): return for h in repo.heads: last = l.heads[h.name] if h.name in l.heads else None - if h.commit.sha != last: + if h.commit.hexsha != last: if last: # Check against last commit commits = list(repo.iter_commits('%s..%s' % (last, h.name))) elif len(h.commit.parents): # Check against parent commit @@ -173,11 +173,11 @@ class ReposNotifyEvent(pyinotify.ProcessEvent): msg = repo_commit_msg(repo, h.name, commits) self.bot.gitmsg(msg) - l.heads[h.name] = h.commit.sha + l.heads[h.name] = h.commit.hexsha for t in (t for t in repo.tags if t.name not in l.tags): reponame = os.path.splitext(os.path.basename(repo.working_dir))[0] - self.bot.gitmsg('New tag \002%s\002 for repo \002%s\002 points to \002%s\002' % (t.name, reponame, t.commit.sha[:7])) + self.bot.gitmsg('New tag \002%s\002 for repo \002%s\002 points to \002%s\002' % (t.name, reponame, t.commit.hexsha[:7])) l.tags.append(t.name) def process_IN_CREATE(self, event): -- cgit v1.2.3 From d73c968545efa0586a32f7aa6aae64214c270376 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 19 Oct 2010 21:35:39 +0200 Subject: Catch exception on invalid input to show(). --- gitnoti.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitnoti.py b/gitnoti.py index 76a2930..66ca98a 100755 --- a/gitnoti.py +++ b/gitnoti.py @@ -249,7 +249,9 @@ class Bot(irc.IRCClient): commits = [repo.commit(name)] except ValueError: return [] - except git.errors.GitCommandError: + except git.exc.BadObject: + return [] + except git.exc.GitCommandError: return [] return commits -- cgit v1.2.3 From 2b20521a9418aaa0e8e8323689387f59ac3ea34e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 20 Oct 2010 17:24:49 +0200 Subject: Remove unnecessary split in get_commits(). --- gitnoti.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitnoti.py b/gitnoti.py index 66ca98a..3324c21 100755 --- a/gitnoti.py +++ b/gitnoti.py @@ -243,8 +243,7 @@ class Bot(irc.IRCClient): def get_commits(self, repo, name): try: if '..' in name: - frm, to = name.split('..') - commits = list(repo.iter_commits('%s..%s' % (frm, to))) + commits = list(repo.iter_commits(name)) else: commits = [repo.commit(name)] except ValueError: -- cgit v1.2.3