Ran update-copyright.
[update-copyright.git] / update_copyright / vcs / git.py
index e65acb2fd0687b0c48629159e94088734a6878c2..9a4f567b962f2c610802777ce9c2974588126de1 100644 (file)
@@ -1,20 +1,19 @@
-# Copyright (C) 2012 W. Trevor King
+# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of update-copyright.
 #
-# update-copyright 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.
+# update-copyright 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.
 #
-# update-copyright 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.
+# update-copyright 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 update-copyright.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU General Public License along with
+# update-copyright.  If not, see <http://www.gnu.org/licenses/>.
 
 from . import VCSBackend as _VCSBackend
 from . import utils as _utils
@@ -23,11 +22,6 @@ from . import utils as _utils
 class GitBackend (_VCSBackend):
     name = 'Git'
 
-    @staticmethod
-    def _git_cmd(*args):
-        status,stdout,stderr = _utils.invoke(['git'] + list(args))
-        return stdout.rstrip('\n')
-
     def __init__(self, **kwargs):
         super(GitBackend, self).__init__(**kwargs)
         self._version = self._git_cmd('--version').split(' ')[-1]
@@ -42,14 +36,23 @@ class GitBackend (_VCSBackend):
             self._year_format = ['--pretty=format:%ad',  # Author date
                                  '--date=short']         # YYYY-MM-DD
 
-    def _years(self, filename=None):
+    def _git_cmd(self, *args):
+        status,stdout,stderr = _utils.invoke(
+            ['git'] + list(args), cwd=self._root, unicode_output=True)
+        return stdout.rstrip('\n')
+
+    def _dates(self, filename=None):
         args = ['log'] + self._year_format
         if filename is not None:
             args.extend(['--follow'] + [filename])
         output = self._git_cmd(*args)
         if self._version.startswith('1.5.'):
             output = '\n'.join([x.split()[0] for x in output.splitlines()])
-        years = set(int(line.split('-', 1)[0]) for line in output.splitlines())
+        return output.splitlines()
+
+    def _years(self, filename=None):
+        dates = self._dates(filename=filename)
+        years = set(int(date.split('-', 1)[0]) for date in dates)
         return years
 
     def _authors(self, filename=None):