##// END OF EJS Templates
hg,git: change method of extracting last_change to use actualy date object...
marcink -
r1349:e7cd3f1f default
parent child Browse files
Show More
@@ -26,12 +26,12 b' import logging'
26 import os
26 import os
27 import re
27 import re
28 import shutil
28 import shutil
29 import time
30
29
31 from zope.cachedescriptors.property import Lazy as LazyProperty
30 from zope.cachedescriptors.property import Lazy as LazyProperty
32
31
33 from rhodecode.lib.compat import OrderedDict
32 from rhodecode.lib.compat import OrderedDict
34 from rhodecode.lib.datelib import makedate, utcdate_fromtimestamp
33 from rhodecode.lib.datelib import (
34 utcdate_fromtimestamp, makedate, date_astimestamp)
35 from rhodecode.lib.utils import safe_unicode, safe_str
35 from rhodecode.lib.utils import safe_unicode, safe_str
36 from rhodecode.lib.vcs import connection, path as vcspath
36 from rhodecode.lib.vcs import connection, path as vcspath
37 from rhodecode.lib.vcs.backends.base import (
37 from rhodecode.lib.vcs.backends.base import (
@@ -269,20 +269,21 b' class GitRepository(BaseRepository):'
269 Returns last change made on this repository as
269 Returns last change made on this repository as
270 `datetime.datetime` object.
270 `datetime.datetime` object.
271 """
271 """
272 return utcdate_fromtimestamp(self._get_mtime(), makedate()[1])
273
274 def _get_mtime(self):
275 try:
272 try:
276 return time.mktime(self.get_commit().date.timetuple())
273 return self.get_commit().date
277 except RepositoryError:
274 except RepositoryError:
278 idx_loc = '' if self.bare else '.git'
275 tzoffset = makedate()[1]
279 # fallback to filesystem
276 return utcdate_fromtimestamp(self._get_fs_mtime(), tzoffset)
280 in_path = os.path.join(self.path, idx_loc, "index")
277
281 he_path = os.path.join(self.path, idx_loc, "HEAD")
278 def _get_fs_mtime(self):
282 if os.path.exists(in_path):
279 idx_loc = '' if self.bare else '.git'
283 return os.stat(in_path).st_mtime
280 # fallback to filesystem
284 else:
281 in_path = os.path.join(self.path, idx_loc, "index")
285 return os.stat(he_path).st_mtime
282 he_path = os.path.join(self.path, idx_loc, "HEAD")
283 if os.path.exists(in_path):
284 return os.stat(in_path).st_mtime
285 else:
286 return os.stat(he_path).st_mtime
286
287
287 @LazyProperty
288 @LazyProperty
288 def description(self):
289 def description(self):
@@ -367,21 +367,22 b' class MercurialRepository(BaseRepository'
367 def last_change(self):
367 def last_change(self):
368 """
368 """
369 Returns last change made on this repository as
369 Returns last change made on this repository as
370 `datetime.datetime` object
370 `datetime.datetime` object.
371 """
371 """
372 return utcdate_fromtimestamp(self._get_mtime(), makedate()[1])
373
374 def _get_mtime(self):
375 try:
372 try:
376 return date_astimestamp(self.get_commit().date)
373 return self.get_commit().date
377 except RepositoryError:
374 except RepositoryError:
378 # fallback to filesystem
375 tzoffset = makedate()[1]
379 cl_path = os.path.join(self.path, '.hg', "00changelog.i")
376 return utcdate_fromtimestamp(self._get_fs_mtime(), tzoffset)
380 st_path = os.path.join(self.path, '.hg', "store")
377
381 if os.path.exists(cl_path):
378 def _get_fs_mtime(self):
382 return os.stat(cl_path).st_mtime
379 # fallback to filesystem
383 else:
380 cl_path = os.path.join(self.path, '.hg', "00changelog.i")
384 return os.stat(st_path).st_mtime
381 st_path = os.path.join(self.path, '.hg', "store")
382 if os.path.exists(cl_path):
383 return os.stat(cl_path).st_mtime
384 else:
385 return os.stat(st_path).st_mtime
385
386
386 def _sanitize_commit_idx(self, idx):
387 def _sanitize_commit_idx(self, idx):
387 # Note: Mercurial has ``int(-1)`` reserved as not existing id_or_idx
388 # Note: Mercurial has ``int(-1)`` reserved as not existing id_or_idx
General Comments 0
You need to be logged in to leave comments. Login now