comparison mercurial/crecord.py @ 29076:36d3535c6a47

crecord: add/remove blank lines (coding style)
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 05 May 2016 11:19:52 +0800
parents 0411b7998d9b
children 6ecd1a00977e
comparison
equal deleted inserted replaced
29075:3f0177d2b8fb 29076:36d3535c6a47
89 raise NotImplementedError("method must be implemented by subclass") 89 raise NotImplementedError("method must be implemented by subclass")
90 90
91 def allchildren(self): 91 def allchildren(self):
92 "Return a list of all of the direct children of this node" 92 "Return a list of all of the direct children of this node"
93 raise NotImplementedError("method must be implemented by subclass") 93 raise NotImplementedError("method must be implemented by subclass")
94
94 def nextsibling(self): 95 def nextsibling(self):
95 """ 96 """
96 Return the closest next item of the same type where there are no items 97 Return the closest next item of the same type where there are no items
97 of different types between the current item and this closest item. 98 of different types between the current item and this closest item.
98 If no such item exists, return None. 99 If no such item exists, return None.
107 """ 108 """
108 raise NotImplementedError("method must be implemented by subclass") 109 raise NotImplementedError("method must be implemented by subclass")
109 110
110 def parentitem(self): 111 def parentitem(self):
111 raise NotImplementedError("method must be implemented by subclass") 112 raise NotImplementedError("method must be implemented by subclass")
112
113 113
114 def nextitem(self, constrainlevel=True, skipfolded=True): 114 def nextitem(self, constrainlevel=True, skipfolded=True):
115 """ 115 """
116 If constrainLevel == True, return the closest next item 116 If constrainLevel == True, return the closest next item
117 of the same type where there are no items of different types between 117 of the same type where there are no items of different types between
234 234
235 # flag is False if this header was ever unfolded from initial state 235 # flag is False if this header was ever unfolded from initial state
236 self.neverunfolded = True 236 self.neverunfolded = True
237 self.hunks = [uihunk(h, self) for h in self.hunks] 237 self.hunks = [uihunk(h, self) for h in self.hunks]
238 238
239
240 def prettystr(self): 239 def prettystr(self):
241 x = stringio() 240 x = stringio()
242 self.pretty(x) 241 self.pretty(x)
243 return x.getvalue() 242 return x.getvalue()
244 243
390 return None 389 return None
391 390
392 def allchildren(self): 391 def allchildren(self):
393 "return a list of all of the direct children of this node" 392 "return a list of all of the direct children of this node"
394 return self.changedlines 393 return self.changedlines
394
395 def countchanges(self): 395 def countchanges(self):
396 """changedlines -> (n+,n-)""" 396 """changedlines -> (n+,n-)"""
397 add = len([l for l in self.changedlines if l.applied 397 add = len([l for l in self.changedlines if l.applied
398 and l.prettystr()[0] == '+']) 398 and l.prettystr()[0] == '+'])
399 rem = len([l for l in self.changedlines if l.applied 399 rem = len([l for l in self.changedlines if l.applied
453 self.pretty(x) 453 self.pretty(x)
454 return x.getvalue() 454 return x.getvalue()
455 455
456 def __getattr__(self, name): 456 def __getattr__(self, name):
457 return getattr(self._hunk, name) 457 return getattr(self._hunk, name)
458
458 def __repr__(self): 459 def __repr__(self):
459 return '<hunk %r@%d>' % (self.filename(), self.fromline) 460 return '<hunk %r@%d>' % (self.filename(), self.fromline)
460 461
461 def filterpatch(ui, chunks, chunkselector, operation=None): 462 def filterpatch(ui, chunks, chunkselector, operation=None):
462 """interactively filter patch chunks into applied-only chunks""" 463 """interactively filter patch chunks into applied-only chunks"""
764 self.scrolllines(selend - padendbuffered) 765 self.scrolllines(selend - padendbuffered)
765 elif selstart < padstartbuffered: 766 elif selstart < padstartbuffered:
766 # negative values scroll in pgup direction 767 # negative values scroll in pgup direction
767 self.scrolllines(selstart - padstartbuffered) 768 self.scrolllines(selstart - padstartbuffered)
768 769
769
770 def scrolllines(self, numlines): 770 def scrolllines(self, numlines):
771 "scroll the screen up (down) by numlines when numlines >0 (<0)." 771 "scroll the screen up (down) by numlines when numlines >0 (<0)."
772 self.firstlineofpadtoprint += numlines 772 self.firstlineofpadtoprint += numlines
773 if self.firstlineofpadtoprint < 0: 773 if self.firstlineofpadtoprint < 0:
774 self.firstlineofpadtoprint = 0 774 self.firstlineofpadtoprint = 0
892 child.folded = not item.folded 892 child.folded = not item.folded
893 893
894 if isinstance(item, (uiheader, uihunk)): 894 if isinstance(item, (uiheader, uihunk)):
895 item.folded = not item.folded 895 item.folded = not item.folded
896 896
897
898 def alignstring(self, instr, window): 897 def alignstring(self, instr, window):
899 """ 898 """
900 add whitespace to the end of a string in order to make it fill 899 add whitespace to the end of a string in order to make it fill
901 the screen in the x direction. the current cursor position is 900 the screen in the x direction. the current cursor position is
902 taken into account when making this calculation. the string can span 901 taken into account when making this calculation. the string can span
1130 # print out from-to line with checkbox 1129 # print out from-to line with checkbox
1131 checkbox = self.getstatusprefixstring(hunk) 1130 checkbox = self.getstatusprefixstring(hunk)
1132 1131
1133 lineprefix = " "*self.hunkindentnumchars + checkbox 1132 lineprefix = " "*self.hunkindentnumchars + checkbox
1134 frtoline = " " + hunk.getfromtoline().strip("\n") 1133 frtoline = " " + hunk.getfromtoline().strip("\n")
1135
1136 1134
1137 outstr += self.printstring(self.chunkpad, lineprefix, towin=towin, 1135 outstr += self.printstring(self.chunkpad, lineprefix, towin=towin,
1138 align=False) # add uncolored checkbox/indent 1136 align=False) # add uncolored checkbox/indent
1139 outstr += self.printstring(self.chunkpad, frtoline, pair=colorpair, 1137 outstr += self.printstring(self.chunkpad, frtoline, pair=colorpair,
1140 towin=towin) 1138 towin=towin)