Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import time
import traceback

# 'import git' is performed during plugin initialization.
#
# The GitPython library has different APIs depending on the version installed.
# (0.1.x, 0.3.x supported)
GIT_API_VERSION = -1
Expand All @@ -67,6 +65,18 @@ def plural(count, singular, plural=None):
return singular[:-1] + 'ies'
return singular + 's'

try:
import git
except ImportError:
raise callbacks.Error("GitPython is not installed.")
if not git.__version__.startswith('0.'):
raise callbacks.Error("Unsupported GitPython version.")
GIT_API_VERSION = int(git.__version__[2])
if not GIT_API_VERSION in [1, 3]:
log_error('GitPython version %s unrecognized, using 0.3.x API.'
% git.__version__)
GIT_API_VERSION = 3

def synchronized(tlockname):
"""
Decorates a class method (with self as the first parameter) to acquire the
Expand Down Expand Up @@ -282,7 +292,6 @@ class Git(callbacks.PluginRegexp):
unaddressedRegexps = [ '_snarf' ]

def __init__(self, irc):
self.init_git_python()
self.__parent = super(Git, self)
self.__parent.__init__(irc)
# Workaround the fact that self.log already exists in plugins
Expand All @@ -299,20 +308,6 @@ def __init__(self, irc):
log_warning(str(e))
self._schedule_next_event()

def init_git_python(self):
global GIT_API_VERSION, git
try:
import git
except ImportError:
raise Exception("GitPython is not installed.")
if not git.__version__.startswith('0.'):
raise Exception("Unsupported GitPython version.")
GIT_API_VERSION = int(git.__version__[2])
if not GIT_API_VERSION in [1, 3]:
log_error('GitPython version %s unrecognized, using 0.3.x API.'
% git.__version__)
GIT_API_VERSION = 3

def die(self):
self._stop_polling()
self.__parent.die()
Expand Down