@@ -17,6 +17,7 @@ import os
17
17
import json
18
18
import shutil
19
19
import subprocess
20
+ import urllib
20
21
21
22
#
22
23
# If you want to switch to hg-git compatibility mode:
@@ -35,6 +36,7 @@ import subprocess
35
36
36
37
NAME_RE = re .compile ('^([^<>]+)' )
37
38
AUTHOR_RE = re .compile ('^([^<>]+?)? ?<([^<>]+)>$' )
39
+ AUTHOR_HG_RE = re .compile ('^(.*?) ?<(.+?)(?:>(.+)?)?$' )
38
40
RAW_AUTHOR_RE = re .compile ('^(\w+) (?:(.+)? )?<(.+)> (\d+) ([+-]\d+)' )
39
41
40
42
def die (msg , * args ):
@@ -152,19 +154,30 @@ class Parser:
152
154
return sys .stdin .read (size )
153
155
154
156
def get_author (self ):
157
+ global bad_mail
158
+
159
+ ex = None
155
160
m = RAW_AUTHOR_RE .match (self .line )
156
161
if not m :
157
162
return None
158
163
_ , name , email , date , tz = m .groups ()
164
+ if name and 'ext:' in name :
165
+ m = re .match ('^(.+?) ext:\((.+)\)$' , name )
166
+ if m :
167
+ name = m .group (1 )
168
+ ex = urllib .unquote (m .group (2 ))
159
169
160
- if email != 'unknown' :
170
+ if email != bad_mail :
161
171
if name :
162
172
user = '%s <%s>' % (name , email )
163
173
else :
164
174
user = '<%s>' % (email )
165
175
else :
166
176
user = name
167
177
178
+ if ex :
179
+ user += ex
180
+
168
181
tz = int (tz )
169
182
tz = ((tz / 100 ) * 3600 ) + ((tz % 100 ) * 60 )
170
183
return (user , int (date ), - tz )
@@ -194,9 +207,9 @@ def get_filechanges(repo, ctx, parent):
194
207
195
208
return added | modified , removed
196
209
197
- def fixup_user (user ):
198
- user = user .replace ('"' , '' )
210
+ def fixup_user_git (user ):
199
211
name = mail = None
212
+ user = user .replace ('"' , '' )
200
213
m = AUTHOR_RE .match (user )
201
214
if m :
202
215
name = m .group (1 )
@@ -205,11 +218,41 @@ def fixup_user(user):
205
218
m = NAME_RE .match (user )
206
219
if m :
207
220
name = m .group (1 ).strip ()
221
+ return (name , mail )
222
+
223
+ def fixup_user_hg (user ):
224
+ def sanitize (name ):
225
+ # stole this from hg-git
226
+ return re .sub ('[<>\n ]' , '?' , name .lstrip ('< ' ).rstrip ('> ' ))
227
+
228
+ m = AUTHOR_HG_RE .match (user )
229
+ if m :
230
+ name = sanitize (m .group (1 ))
231
+ mail = sanitize (m .group (2 ))
232
+ ex = m .group (3 )
233
+ if ex :
234
+ name += ' ext:(' + urllib .quote (ex ) + ')'
235
+ else :
236
+ name = sanitize (user )
237
+ if '@' in user :
238
+ mail = name
239
+ else :
240
+ mail = None
241
+
242
+ return (name , mail )
243
+
244
+ def fixup_user (user ):
245
+ global mode , bad_mail
246
+
247
+ if mode == 'git' :
248
+ name , mail = fixup_user_git (user )
249
+ else :
250
+ name , mail = fixup_user_hg (user )
208
251
209
252
if not name :
210
- name = 'Unknown'
253
+ name = bad_name
211
254
if not mail :
212
- mail = 'unknown'
255
+ mail = bad_mail
213
256
214
257
return '%s <%s>' % (name , mail )
215
258
@@ -660,7 +703,7 @@ def do_export(parser):
660
703
def main (args ):
661
704
global prefix , dirname , branches , bmarks
662
705
global marks , blob_marks , parsed_refs
663
- global peer , mode
706
+ global peer , mode , bad_mail , bad_name
664
707
665
708
alias = args [1 ]
666
709
url = args [2 ]
@@ -676,8 +719,12 @@ def main(args):
676
719
677
720
if hg_git_compat :
678
721
mode = 'hg'
722
+ bad_mail = 'none@none'
723
+ bad_name = ''
679
724
else :
680
725
mode = 'git'
726
+ bad_mail = 'unknown'
727
+ bad_name = 'Unknown'
681
728
682
729
if alias [4 :] == url :
683
730
is_tmp = True
0 commit comments