Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 9586:d08099e74b81
patch: handle symlink updates/replacements (issue1785)
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 15 Oct 2009 23:15:30 +0200 |
parents | ea1935e2020a |
children | a981ddb16b80 |
comparison
equal
deleted
inserted
replaced
9585:ea1935e2020a | 9586:d08099e74b81 |
---|---|
299 return list(linereader(fp, self.eol is not None)) | 299 return list(linereader(fp, self.eol is not None)) |
300 finally: | 300 finally: |
301 fp.close() | 301 fp.close() |
302 | 302 |
303 def writelines(self, fname, lines): | 303 def writelines(self, fname, lines): |
304 fp = self.opener(fname, 'w') | 304 # Ensure supplied data ends in fname, being a regular file or |
305 # a symlink. updatedir() will -too magically- take care of | |
306 # setting it to the proper type afterwards. | |
307 islink = os.path.islink(fname) | |
308 if islink: | |
309 fp = cStringIO.StringIO() | |
310 else: | |
311 fp = self.opener(fname, 'w') | |
305 try: | 312 try: |
306 if self.eol and self.eol != '\n': | 313 if self.eol and self.eol != '\n': |
307 for l in lines: | 314 for l in lines: |
308 if l and l[-1] == '\n': | 315 if l and l[-1] == '\n': |
309 l = l[:-1] + self.eol | 316 l = l[:-1] + self.eol |
310 fp.write(l) | 317 fp.write(l) |
311 else: | 318 else: |
312 fp.writelines(lines) | 319 fp.writelines(lines) |
320 if islink: | |
321 self.opener.symlink(fp.getvalue(), fname) | |
313 finally: | 322 finally: |
314 fp.close() | 323 fp.close() |
315 | 324 |
316 def unlink(self, fname): | 325 def unlink(self, fname): |
317 os.unlink(fname) | 326 os.unlink(fname) |