contrib/phabricator.py
changeset 33264 266321579c68
parent 33263 ed61189763ef
child 33265 95f658b558a3
equal deleted inserted replaced
33263:ed61189763ef 33264:266321579c68
   194         'diff_id': diff[r'id'],
   194         'diff_id': diff[r'id'],
   195         'name': 'hg:meta',
   195         'name': 'hg:meta',
   196         'data': json.dumps({
   196         'data': json.dumps({
   197             'user': ctx.user(),
   197             'user': ctx.user(),
   198             'date': '%d %d' % ctx.date(),
   198             'date': '%d %d' % ctx.date(),
       
   199             'node': ctx.hex(),
       
   200             'parent': ctx.p1().hex(),
   199         }),
   201         }),
   200     }
   202     }
   201     callconduit(ctx.repo(), 'differential.setdiffproperty', params)
   203     callconduit(ctx.repo(), 'differential.setdiffproperty', params)
   202 
   204 
   203 def createdifferentialrevision(ctx, revid=None, parentrevid=None):
   205 def createdifferentialrevision(ctx, revid=None, parentrevid=None):
   290                                             ctx.description().split('\n')[0]))
   292                                             ctx.description().split('\n')[0]))
   291         lastrevid = newrevid
   293         lastrevid = newrevid
   292 
   294 
   293 _summaryre = re.compile('^Summary:\s*', re.M)
   295 _summaryre = re.compile('^Summary:\s*', re.M)
   294 
   296 
       
   297 # Map from "hg:meta" keys to header understood by "hg import". The order is
       
   298 # consistent with "hg export" output.
       
   299 _metanamemap = util.sortdict([(r'user', 'User'), (r'date', 'Date'),
       
   300                               (r'node', 'Node ID'), (r'parent', 'Parent ')])
       
   301 
   295 def readpatch(repo, params, recursive=False):
   302 def readpatch(repo, params, recursive=False):
   296     """generate plain-text patch readable by 'hg import'
   303     """generate plain-text patch readable by 'hg import'
   297 
   304 
   298     params is passed to "differential.query". If recursive is True, also return
   305     params is passed to "differential.query". If recursive is True, also return
   299     dependent patches.
   306     dependent patches.
   314     header = '# HG changeset patch\n'
   321     header = '# HG changeset patch\n'
   315 
   322 
   316     # Remove potential empty "Summary:"
   323     # Remove potential empty "Summary:"
   317     desc = _summaryre.sub('', desc)
   324     desc = _summaryre.sub('', desc)
   318 
   325 
   319     # Try to preserve metadata (user, date) from hg:meta property
   326     # Try to preserve metadata from hg:meta property. Write hg patch headers
       
   327     # that can be read by the "import" command. See patchheadermap and extract
       
   328     # in mercurial/patch.py for supported headers.
   320     diffs = callconduit(repo, 'differential.querydiffs', {'ids': [diffid]})
   329     diffs = callconduit(repo, 'differential.querydiffs', {'ids': [diffid]})
   321     props = diffs[str(diffid)][r'properties'] # could be empty list or dict
   330     props = diffs[str(diffid)][r'properties'] # could be empty list or dict
   322     if props and r'hg:meta' in props:
   331     if props and r'hg:meta' in props:
   323         meta = props[r'hg:meta']
   332         meta = props[r'hg:meta']
   324         for k, v in meta.items():
   333         for k in _metanamemap.keys():
   325             header += '# %s %s\n' % (k.capitalize(), v)
   334             if k in meta:
       
   335                 header += '# %s %s\n' % (_metanamemap[k], meta[k])
   326 
   336 
   327     patch = ('%s%s\n%s') % (header, desc, body)
   337     patch = ('%s%s\n%s') % (header, desc, body)
   328 
   338 
   329     # Check dependencies
   339     # Check dependencies
   330     if recursive:
   340     if recursive: