[PATCH 3 of 3 hglib] client: add date field to revision
Idan Kamara
idankk86 at gmail.com
Tue Jan 17 14:38:56 CST 2012
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1326832608 -7200
# Node ID 8568e81a06bbd59c64bab9e4ec291c72842315a8
# Parent 71da73423f0066c088d18aa23c628eb3b1a418c1
client: add date field to revision
diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -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'
@@ -96,7 +100,13 @@
def _parserevs(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):
diff --git a/hglib/context.py b/hglib/context.py
--- a/hglib/context.py
+++ b/hglib/context.py
@@ -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)
diff --git a/hglib/templates.py b/hglib/templates.py
--- a/hglib/templates.py
+++ b/hglib/templates.py
@@ -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'
diff --git a/tests/test-commit.py b/tests/test-commit.py
--- a/tests/test-commit.py
+++ b/tests/test-commit.py
@@ -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)
More information about the Mercurial-devel
mailing list