Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 27796:f7f3958d39c0
with: use context manager for I/O in changedfiles in patch
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Fri, 15 Jan 2016 13:14:50 -0800 |
parents | 60183975b5bc |
children | 27572a5cc409 |
comparison
equal
deleted
inserted
replaced
27795:3e0d27d298b7 | 27796:f7f3958d39c0 |
---|---|
2097 return internalpatch(ui, repo, patchname, strip, prefix, files, eolmode, | 2097 return internalpatch(ui, repo, patchname, strip, prefix, files, eolmode, |
2098 similarity) | 2098 similarity) |
2099 | 2099 |
2100 def changedfiles(ui, repo, patchpath, strip=1): | 2100 def changedfiles(ui, repo, patchpath, strip=1): |
2101 backend = fsbackend(ui, repo.root) | 2101 backend = fsbackend(ui, repo.root) |
2102 fp = open(patchpath, 'rb') | 2102 with open(patchpath, 'rb') as fp: |
2103 try: | |
2104 changed = set() | 2103 changed = set() |
2105 for state, values in iterhunks(fp): | 2104 for state, values in iterhunks(fp): |
2106 if state == 'file': | 2105 if state == 'file': |
2107 afile, bfile, first_hunk, gp = values | 2106 afile, bfile, first_hunk, gp = values |
2108 if gp: | 2107 if gp: |
2116 if gp.op == 'RENAME': | 2115 if gp.op == 'RENAME': |
2117 changed.add(gp.oldpath) | 2116 changed.add(gp.oldpath) |
2118 elif state not in ('hunk', 'git'): | 2117 elif state not in ('hunk', 'git'): |
2119 raise error.Abort(_('unsupported parser state: %s') % state) | 2118 raise error.Abort(_('unsupported parser state: %s') % state) |
2120 return changed | 2119 return changed |
2121 finally: | |
2122 fp.close() | |
2123 | 2120 |
2124 class GitDiffRequired(Exception): | 2121 class GitDiffRequired(Exception): |
2125 pass | 2122 pass |
2126 | 2123 |
2127 def diffallopts(ui, opts=None, untrusted=False, section='diff'): | 2124 def diffallopts(ui, opts=None, untrusted=False, section='diff'): |