3 # Copyright (c) 2007 Rocco Rutte <pdmef@gmx.net>
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
6 from mercurial
import repo
,hg
,cmdutil
,util
,ui
,revlog
,node
10 # git branch for hg's default 'HEAD' branch
12 # silly regex to see if user field has email address
13 user_re
=re
.compile('([^<]+) (<[^>]+>)$')
14 # silly regex to clean out user names
15 user_clean_re
=re
.compile('^["]([^"]+)["]$')
18 myui
=ui
.ui(interactive
=False)
19 return myui
,hg
.repository(myui
,url
)
21 def fixup_user(user
,authors
):
23 # if we have an authors table, try to get mapping
24 # by defaulting to the current value of 'user'
25 user
=authors
.get(user
,user
)
26 name
,mail
,m
='','',user_re
.match(user
)
28 # if we don't have 'Name <mail>' syntax, use 'user
29 # <devnull@localhost>' if use contains no at and
30 # 'user <user>' otherwise
33 mail
='<devnull@localhost>'
37 # if we have 'Name <mail>' syntax, everything is fine :)
38 name
,mail
=m
.group(1),m
.group(2)
40 # remove any silly quoting from username
41 m2
=user_clean_re
.match(name
)
44 return '%s %s' % (name
,mail
)
51 def get_changeset(ui
,repo
,revision
,authors
={}):
52 node
=repo
.lookup(revision
)
53 (manifest
,user
,(time
,timezone
),files
,desc
,extra
)=repo
.changelog
.read(node
)
54 tz
="%+03d%02d" % (-timezone
/ 3600, ((-timezone
% 3600) / 60))
55 branch
=get_branch(extra
.get('branch','master'))
56 return (node
,manifest
,fixup_user(user
,authors
),(time
,tz
),files
,desc
,branch
,extra
)
58 def load_cache(filename
):
60 if not os
.path
.exists(filename
):
64 for line
in f
.readlines():
66 fields
=line
.split(' ')
67 if fields
==None or not len(fields
)==2 or fields
[0][0]!=':':
68 sys
.stderr
.write('Invalid file format in [%s], line %d\n' % (filename
,l
))
70 # put key:value in cache, key without ^:
71 cache
[fields
[0][1:]]=fields
[1].split('\n')[0]
75 def save_cache(filename
,cache
):
77 map(lambda x
: f
.write(':%s %s\n' % (str(x
),str(cache
.get(x
)))),cache
.keys())
80 def get_git_sha1(name
,type='heads'):
82 f
=open(os
.getenv('GIT_DIR','/dev/null')+'/refs/'+type+'/'+name
)
83 sha1
=f
.readlines()[0].split('\n')[0]