Mercurial > hg
comparison hgext/mq.py @ 7400:409a9b442308
mq: use atomictempfiles during patch refresh
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 23 Nov 2008 16:07:47 -0800 |
parents | e71bda2d2087 |
children | 41e87b4d0c9d |
comparison
equal
deleted
inserted
replaced
7399:e71bda2d2087 | 7400:409a9b442308 |
---|---|
1091 raise util.Abort(_("cannot refresh a revision with children")) | 1091 raise util.Abort(_("cannot refresh a revision with children")) |
1092 cparents = repo.changelog.parents(top) | 1092 cparents = repo.changelog.parents(top) |
1093 patchparent = self.qparents(repo, top) | 1093 patchparent = self.qparents(repo, top) |
1094 ph = self.readheaders(patchfn) | 1094 ph = self.readheaders(patchfn) |
1095 | 1095 |
1096 patchf = self.opener(patchfn, 'r+') | 1096 patchf = self.opener(patchfn, 'r') |
1097 | 1097 |
1098 # if the patch was a git patch, refresh it as a git patch | 1098 # if the patch was a git patch, refresh it as a git patch |
1099 for line in patchf: | 1099 for line in patchf: |
1100 if line.startswith('diff --git'): | 1100 if line.startswith('diff --git'): |
1101 self.diffopts().git = True | 1101 self.diffopts().git = True |
1105 ph.setmessage(msg) | 1105 ph.setmessage(msg) |
1106 if newuser: | 1106 if newuser: |
1107 ph.setuser(newuser) | 1107 ph.setuser(newuser) |
1108 if newdate: | 1108 if newdate: |
1109 ph.setdate(newdate) | 1109 ph.setdate(newdate) |
1110 | |
1111 # only commit new patch when write is complete | |
1112 patchf = self.opener(patchfn, 'w', atomictemp=True) | |
1110 | 1113 |
1111 patchf.seek(0) | 1114 patchf.seek(0) |
1112 patchf.truncate() | 1115 patchf.truncate() |
1113 | 1116 |
1114 comments = str(ph) | 1117 comments = str(ph) |
1183 match = cmdutil.matchfiles(repo, util.unique(c[0] + c[1] + c[2])) | 1186 match = cmdutil.matchfiles(repo, util.unique(c[0] + c[1] + c[2])) |
1184 chunks = patch.diff(repo, patchparent, match=match, | 1187 chunks = patch.diff(repo, patchparent, match=match, |
1185 changes=c, opts=self.diffopts()) | 1188 changes=c, opts=self.diffopts()) |
1186 for chunk in chunks: | 1189 for chunk in chunks: |
1187 patchf.write(chunk) | 1190 patchf.write(chunk) |
1188 patchf.close() | 1191 patchf.rename() |
1189 | 1192 |
1190 repo.dirstate.setparents(*cparents) | 1193 repo.dirstate.setparents(*cparents) |
1191 copies = {} | 1194 copies = {} |
1192 for dst in a: | 1195 for dst in a: |
1193 src = repo.dirstate.copied(dst) | 1196 src = repo.dirstate.copied(dst) |
1244 match=match, force=1) | 1247 match=match, force=1) |
1245 self.applied.append(statusentry(revlog.hex(n), patchfn)) | 1248 self.applied.append(statusentry(revlog.hex(n), patchfn)) |
1246 self.removeundo(repo) | 1249 self.removeundo(repo) |
1247 else: | 1250 else: |
1248 self.printdiff(repo, patchparent, fp=patchf) | 1251 self.printdiff(repo, patchparent, fp=patchf) |
1249 patchf.close() | 1252 patchf.rename() |
1250 added = repo.status()[1] | 1253 added = repo.status()[1] |
1251 for a in added: | 1254 for a in added: |
1252 f = repo.wjoin(a) | 1255 f = repo.wjoin(a) |
1253 try: | 1256 try: |
1254 os.unlink(f) | 1257 os.unlink(f) |