diff --git a/rhodecode/lib/vcs/backends/git/repository.py b/rhodecode/lib/vcs/backends/git/repository.py --- a/rhodecode/lib/vcs/backends/git/repository.py +++ b/rhodecode/lib/vcs/backends/git/repository.py @@ -26,12 +26,12 @@ import logging import os import re import shutil -import time from zope.cachedescriptors.property import Lazy as LazyProperty from rhodecode.lib.compat import OrderedDict -from rhodecode.lib.datelib import makedate, utcdate_fromtimestamp +from rhodecode.lib.datelib import ( + utcdate_fromtimestamp, makedate, date_astimestamp) from rhodecode.lib.utils import safe_unicode, safe_str from rhodecode.lib.vcs import connection, path as vcspath from rhodecode.lib.vcs.backends.base import ( @@ -269,20 +269,21 @@ class GitRepository(BaseRepository): Returns last change made on this repository as `datetime.datetime` object. """ - return utcdate_fromtimestamp(self._get_mtime(), makedate()[1]) - - def _get_mtime(self): try: - return time.mktime(self.get_commit().date.timetuple()) + return self.get_commit().date except RepositoryError: - idx_loc = '' if self.bare else '.git' - # fallback to filesystem - in_path = os.path.join(self.path, idx_loc, "index") - he_path = os.path.join(self.path, idx_loc, "HEAD") - if os.path.exists(in_path): - return os.stat(in_path).st_mtime - else: - return os.stat(he_path).st_mtime + tzoffset = makedate()[1] + return utcdate_fromtimestamp(self._get_fs_mtime(), tzoffset) + + def _get_fs_mtime(self): + idx_loc = '' if self.bare else '.git' + # fallback to filesystem + in_path = os.path.join(self.path, idx_loc, "index") + he_path = os.path.join(self.path, idx_loc, "HEAD") + if os.path.exists(in_path): + return os.stat(in_path).st_mtime + else: + return os.stat(he_path).st_mtime @LazyProperty def description(self): diff --git a/rhodecode/lib/vcs/backends/hg/repository.py b/rhodecode/lib/vcs/backends/hg/repository.py --- a/rhodecode/lib/vcs/backends/hg/repository.py +++ b/rhodecode/lib/vcs/backends/hg/repository.py @@ -367,21 +367,22 @@ class MercurialRepository(BaseRepository def last_change(self): """ Returns last change made on this repository as - `datetime.datetime` object + `datetime.datetime` object. """ - return utcdate_fromtimestamp(self._get_mtime(), makedate()[1]) - - def _get_mtime(self): try: - return date_astimestamp(self.get_commit().date) + return self.get_commit().date except RepositoryError: - # fallback to filesystem - cl_path = os.path.join(self.path, '.hg', "00changelog.i") - st_path = os.path.join(self.path, '.hg', "store") - if os.path.exists(cl_path): - return os.stat(cl_path).st_mtime - else: - return os.stat(st_path).st_mtime + tzoffset = makedate()[1] + return utcdate_fromtimestamp(self._get_fs_mtime(), tzoffset) + + def _get_fs_mtime(self): + # fallback to filesystem + cl_path = os.path.join(self.path, '.hg', "00changelog.i") + st_path = os.path.join(self.path, '.hg', "store") + if os.path.exists(cl_path): + return os.stat(cl_path).st_mtime + else: + return os.stat(st_path).st_mtime def _sanitize_commit_idx(self, idx): # Note: Mercurial has ``int(-1)`` reserved as not existing id_or_idx