Mercurial > python-hglib
changeset 99:2b36619ec0a0
client: add date field to revision
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Tue, 17 Jan 2012 22:36:48 +0200 |
parents | 972d069051c5 |
children | dd63d69a5ebf |
files | hglib/client.py hglib/context.py hglib/templates.py tests/test-commit.py |
diffstat | 4 files changed, 26 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/client.py Tue Jan 17 22:24:24 2012 +0200 +++ b/hglib/client.py Tue Jan 17 22:36:48 2012 +0200 @@ -1,11 +1,11 @@ -import subprocess, os, struct, cStringIO, re +import subprocess, os, struct, cStringIO, re, datetime import hglib, error, util, templates, merge, context from util import cmdbuilder class revision(tuple): - def __new__(cls, rev, node, tags, branch, author, desc): - return tuple.__new__(cls, (rev, node, tags, branch, author, desc)) + def __new__(cls, rev, node, tags, branch, author, desc, date): + return tuple.__new__(cls, (rev, node, tags, branch, author, desc, date)) @property def rev(self): @@ -31,6 +31,10 @@ def desc(self): return self[5] + @property + def date(self): + return self[6] + class hgclient(object): inputfmt = '>I' outputfmt = '>cI' @@ -95,7 +99,13 @@ def _parserevs(self, splitted): ''' splitted is a list of fields according to our rev.style, where each 6 fields compose one revision. ''' - return [revision(*rev) for rev in util.grouper(6, splitted)] + revs = [] + for rev in util.grouper(7, splitted): + # truncate the timezone and convert to a local datetime + posixtime = float(rev[6].split('.', 1)[0]) + dt = datetime.datetime.fromtimestamp(posixtime) + revs.append(revision(rev[0], rev[1], rev[2], rev[3], rev[4], rev[5], dt)) + return revs def runcommand(self, args, inchannels, outchannels): def writeblock(data):
--- a/hglib/context.py Tue Jan 17 22:24:24 2012 +0200 +++ b/hglib/context.py Tue Jan 17 22:36:48 2012 +0200 @@ -1,6 +1,6 @@ import client, util, templates -_nullcset = ['-1', '000000000000000000000000000000000000000', '', '', '', ''] +_nullcset = ['-1', '000000000000000000000000000000000000000', '', '', '', '', ''] class changectx(object): """A changecontext object makes access to data related to a particular @@ -26,7 +26,7 @@ cset = cset[0] self._rev, self._node, self._tags = cset[:3] - self._branch, self._author, self._description = cset[3:] + self._branch, self._author, self._description, self._date = cset[3:] self._rev = int(self._rev)
--- a/hglib/templates.py Tue Jan 17 22:24:24 2012 +0200 +++ b/hglib/templates.py Tue Jan 17 22:36:48 2012 +0200 @@ -1,1 +1,1 @@ -changeset = '{rev}\\0{node}\\0{tags}\\0{branch}\\0{author}\\0{desc}\\0' +changeset = '{rev}\\0{node}\\0{tags}\\0{branch}\\0{author}\\0{desc}\\0{date}\\0'
--- a/tests/test-commit.py Tue Jan 17 22:24:24 2012 +0200 +++ b/tests/test-commit.py Tue Jan 17 22:36:48 2012 +0200 @@ -1,4 +1,4 @@ -import common, hglib +import common, hglib, datetime class test_commit(common.basetest): def test_user(self): @@ -30,3 +30,11 @@ def test_message_logfile(self): self.assertRaises(ValueError, self.client.commit, 'foo', logfile='bar') self.assertRaises(ValueError, self.client.commit) + + def test_date(self): + self.append('a', 'a') + now = datetime.datetime.now().replace(microsecond=0) + rev0, node0 = self.client.commit('first', addremove=True, + date=now.isoformat(' ')) + + self.assertEquals(now, self.client.tip().date)