hgext/phabricator.py
changeset 43184 99ee4afd352f
parent 43183 73d4bc60e389
child 43185 75e7628b488f
equal deleted inserted replaced
43183:73d4bc60e389 43184:99ee4afd352f
   477     newLength = attr.ib(default=0)  # camelcase-required
   477     newLength = attr.ib(default=0)  # camelcase-required
   478     corpus = attr.ib(default='')
   478     corpus = attr.ib(default='')
   479     # These get added to the phabchange's equivalents
   479     # These get added to the phabchange's equivalents
   480     addLines = attr.ib(default=0)  # camelcase-required
   480     addLines = attr.ib(default=0)  # camelcase-required
   481     delLines = attr.ib(default=0)  # camelcase-required
   481     delLines = attr.ib(default=0)  # camelcase-required
       
   482 
       
   483 
       
   484 @attr.s
       
   485 class phabchange(object):
       
   486     """Represents a Differential change, owns Differential hunks and owned by a
       
   487     Differential diff.  Each one represents one file in a diff.
       
   488     """
       
   489 
       
   490     currentPath = attr.ib(default=None)  # camelcase-required
       
   491     oldPath = attr.ib(default=None)  # camelcase-required
       
   492     awayPaths = attr.ib(default=attr.Factory(list))  # camelcase-required
       
   493     metadata = attr.ib(default=attr.Factory(dict))
       
   494     oldProperties = attr.ib(default=attr.Factory(dict))  # camelcase-required
       
   495     newProperties = attr.ib(default=attr.Factory(dict))  # camelcase-required
       
   496     type = attr.ib(default=DiffChangeType.CHANGE)
       
   497     fileType = attr.ib(default=DiffFileType.TEXT)  # camelcase-required
       
   498     commitHash = attr.ib(default=None)  # camelcase-required
       
   499     addLines = attr.ib(default=0)  # camelcase-required
       
   500     delLines = attr.ib(default=0)  # camelcase-required
       
   501     hunks = attr.ib(default=attr.Factory(list))
       
   502 
       
   503     def copynewmetadatatoold(self):
       
   504         for key in list(self.metadata.keys()):
       
   505             newkey = key.replace(b'new:', b'old:')
       
   506             self.metadata[newkey] = self.metadata[key]
       
   507 
       
   508     def addoldmode(self, value):
       
   509         self.oldProperties[b'unix:filemode'] = value
       
   510 
       
   511     def addnewmode(self, value):
       
   512         self.newProperties[b'unix:filemode'] = value
       
   513 
       
   514     def addhunk(self, hunk):
       
   515         if not isinstance(hunk, phabhunk):
       
   516             raise error.Abort(b'phabchange.addhunk only takes phabhunks')
       
   517         self.hunks.append(hunk)
       
   518         # It's useful to include these stats since the Phab web UI shows them,
       
   519         # and uses them to estimate how large a change a Revision is. Also used
       
   520         # in email subjects for the [+++--] bit.
       
   521         self.addLines += hunk.addLines
       
   522         self.delLines += hunk.delLines
   482 
   523 
   483 
   524 
   484 def creatediff(ctx):
   525 def creatediff(ctx):
   485     """create a Differential Diff"""
   526     """create a Differential Diff"""
   486     repo = ctx.repo()
   527     repo = ctx.repo()