equal
deleted
inserted
replaced
1 # util.py - Mercurial utility functions and platform specfic implementations |
1 # util.py - Mercurial utility functions and platform specific implementations |
2 # |
2 # |
3 # Copyright 2005 K. Thananchayan <thananck@yahoo.com> |
3 # Copyright 2005 K. Thananchayan <thananck@yahoo.com> |
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
6 # |
6 # |
7 # This software may be used and distributed according to the terms of the |
7 # This software may be used and distributed according to the terms of the |
8 # GNU General Public License version 2 or any later version. |
8 # GNU General Public License version 2 or any later version. |
9 |
9 |
10 """Mercurial utility functions and platform specfic implementations. |
10 """Mercurial utility functions and platform specific implementations. |
11 |
11 |
12 This contains helper routines that are independent of the SCM core and |
12 This contains helper routines that are independent of the SCM core and |
13 hide platform-specific details from the core. |
13 hide platform-specific details from the core. |
14 """ |
14 """ |
15 |
15 |
797 except OSError: pass |
797 except OSError: pass |
798 raise |
798 raise |
799 return temp |
799 return temp |
800 |
800 |
801 class atomictempfile(object): |
801 class atomictempfile(object): |
802 '''writeable file object that atomically updates a file |
802 '''writable file object that atomically updates a file |
803 |
803 |
804 All writes will go to a temporary copy of the original file. Call |
804 All writes will go to a temporary copy of the original file. Call |
805 close() when you are done writing, and atomictempfile will rename |
805 close() when you are done writing, and atomictempfile will rename |
806 the temporary copy to the original name, making the changes |
806 the temporary copy to the original name, making the changes |
807 visible. If the object is destroyed without being closed, all your |
807 visible. If the object is destroyed without being closed, all your |
1237 |
1237 |
1238 Original TextWrapper implementation uses built-in 'len()' directly, |
1238 Original TextWrapper implementation uses built-in 'len()' directly, |
1239 so overriding is needed to use width information of each characters. |
1239 so overriding is needed to use width information of each characters. |
1240 |
1240 |
1241 In addition, characters classified into 'ambiguous' width are |
1241 In addition, characters classified into 'ambiguous' width are |
1242 treated as wide in east asian area, but as narrow in other. |
1242 treated as wide in East Asian area, but as narrow in other. |
1243 |
1243 |
1244 This requires use decision to determine width of such characters. |
1244 This requires use decision to determine width of such characters. |
1245 """ |
1245 """ |
1246 def __init__(self, **kwargs): |
1246 def __init__(self, **kwargs): |
1247 textwrap.TextWrapper.__init__(self, **kwargs) |
1247 textwrap.TextWrapper.__init__(self, **kwargs) |
1298 |
1298 |
1299 # Maximum width for this line. |
1299 # Maximum width for this line. |
1300 width = self.width - len(indent) |
1300 width = self.width - len(indent) |
1301 |
1301 |
1302 # First chunk on line is whitespace -- drop it, unless this |
1302 # First chunk on line is whitespace -- drop it, unless this |
1303 # is the very beginning of the text (ie. no lines started yet). |
1303 # is the very beginning of the text (i.e. no lines started yet). |
1304 if self.drop_whitespace and chunks[-1].strip() == '' and lines: |
1304 if self.drop_whitespace and chunks[-1].strip() == '' and lines: |
1305 del chunks[-1] |
1305 del chunks[-1] |
1306 |
1306 |
1307 while chunks: |
1307 while chunks: |
1308 l = colwidth(chunks[-1]) |
1308 l = colwidth(chunks[-1]) |