comparison hglib/client.py @ 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
comparison
equal deleted inserted replaced
98:972d069051c5 99:2b36619ec0a0
1 import subprocess, os, struct, cStringIO, re 1 import subprocess, os, struct, cStringIO, re, datetime
2 import hglib, error, util, templates, merge, context 2 import hglib, error, util, templates, merge, context
3 3
4 from util import cmdbuilder 4 from util import cmdbuilder
5 5
6 class revision(tuple): 6 class revision(tuple):
7 def __new__(cls, rev, node, tags, branch, author, desc): 7 def __new__(cls, rev, node, tags, branch, author, desc, date):
8 return tuple.__new__(cls, (rev, node, tags, branch, author, desc)) 8 return tuple.__new__(cls, (rev, node, tags, branch, author, desc, date))
9 9
10 @property 10 @property
11 def rev(self): 11 def rev(self):
12 return self[0] 12 return self[0]
13 13
28 return self[4] 28 return self[4]
29 29
30 @property 30 @property
31 def desc(self): 31 def desc(self):
32 return self[5] 32 return self[5]
33
34 @property
35 def date(self):
36 return self[6]
33 37
34 class hgclient(object): 38 class hgclient(object):
35 inputfmt = '>I' 39 inputfmt = '>I'
36 outputfmt = '>cI' 40 outputfmt = '>cI'
37 outputfmtsize = struct.calcsize(outputfmt) 41 outputfmtsize = struct.calcsize(outputfmt)
93 return channel, self.server.stdout.read(length) 97 return channel, self.server.stdout.read(length)
94 98
95 def _parserevs(self, splitted): 99 def _parserevs(self, splitted):
96 ''' splitted is a list of fields according to our rev.style, where each 6 100 ''' splitted is a list of fields according to our rev.style, where each 6
97 fields compose one revision. ''' 101 fields compose one revision. '''
98 return [revision(*rev) for rev in util.grouper(6, splitted)] 102 revs = []
103 for rev in util.grouper(7, splitted):
104 # truncate the timezone and convert to a local datetime
105 posixtime = float(rev[6].split('.', 1)[0])
106 dt = datetime.datetime.fromtimestamp(posixtime)
107 revs.append(revision(rev[0], rev[1], rev[2], rev[3], rev[4], rev[5], dt))
108 return revs
99 109
100 def runcommand(self, args, inchannels, outchannels): 110 def runcommand(self, args, inchannels, outchannels):
101 def writeblock(data): 111 def writeblock(data):
102 self.server.stdin.write(struct.pack(self.inputfmt, len(data))) 112 self.server.stdin.write(struct.pack(self.inputfmt, len(data)))
103 self.server.stdin.write(data) 113 self.server.stdin.write(data)