Show More
@@ -3143,11 +3143,17 b' def revert(ui, repo, ctx, parents, *pats' | |||
|
3143 | 3143 | # All set to `discard` if `no-backup` is set do avoid checking |
|
3144 | 3144 | # no_backup lower in the code. |
|
3145 | 3145 | # These values are ordered for comparison purposes |
|
3146 | backupinteractive = 3 # do backup if interactively modified | |
|
3146 | 3147 | backup = 2 # unconditionally do backup |
|
3147 | 3148 | check = 1 # check if the existing file differs from target |
|
3148 | 3149 | discard = 0 # never do backup |
|
3149 | 3150 | if opts.get('no_backup'): |
|
3150 | backup = check = discard | |
|
3151 | backupinteractive = backup = check = discard | |
|
3152 | if interactive: | |
|
3153 | dsmodifiedbackup = backupinteractive | |
|
3154 | else: | |
|
3155 | dsmodifiedbackup = backup | |
|
3156 | tobackup = set() | |
|
3151 | 3157 | |
|
3152 | 3158 | backupanddel = actions['remove'] |
|
3153 | 3159 | if not opts.get('no_backup'): |
@@ -3165,7 +3171,7 b' def revert(ui, repo, ctx, parents, *pats' | |||
|
3165 | 3171 | # Modified compared to target, but local file is deleted |
|
3166 | 3172 | (deleted, actions['revert'], discard), |
|
3167 | 3173 | # Modified compared to target, local change |
|
3168 | (dsmodified, actions['revert'], backup), | |
|
3174 | (dsmodified, actions['revert'], dsmodifiedbackup), | |
|
3169 | 3175 | # Added since target |
|
3170 | 3176 | (added, actions['remove'], discard), |
|
3171 | 3177 | # Added in working directory |
@@ -3200,8 +3206,12 b' def revert(ui, repo, ctx, parents, *pats' | |||
|
3200 | 3206 | continue |
|
3201 | 3207 | if xlist is not None: |
|
3202 | 3208 | xlist.append(abs) |
|
3203 |
if dobackup |
|
|
3204 | or wctx[abs].cmp(ctx[abs])): | |
|
3209 | if dobackup: | |
|
3210 | # If in interactive mode, don't automatically create | |
|
3211 | # .orig files (issue4793) | |
|
3212 | if dobackup == backupinteractive: | |
|
3213 | tobackup.add(abs) | |
|
3214 | elif (backup <= dobackup or wctx[abs].cmp(ctx[abs])): | |
|
3205 | 3215 | bakname = scmutil.origpath(ui, repo, rel) |
|
3206 | 3216 | ui.note(_('saving current version of %s as %s\n') % |
|
3207 | 3217 | (rel, bakname)) |
@@ -3221,7 +3231,7 b' def revert(ui, repo, ctx, parents, *pats' | |||
|
3221 | 3231 | if not opts.get('dry_run'): |
|
3222 | 3232 | needdata = ('revert', 'add', 'undelete') |
|
3223 | 3233 | _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata]) |
|
3224 | _performrevert(repo, parents, ctx, actions, interactive) | |
|
3234 | _performrevert(repo, parents, ctx, actions, interactive, tobackup) | |
|
3225 | 3235 | |
|
3226 | 3236 | if targetsubs: |
|
3227 | 3237 | # Revert the subrepos on the revert list |
@@ -3236,7 +3246,8 b' def _revertprefetch(repo, ctx, *files):' | |||
|
3236 | 3246 | """Let extension changing the storage layer prefetch content""" |
|
3237 | 3247 | pass |
|
3238 | 3248 | |
|
3239 |
def _performrevert(repo, parents, ctx, actions, interactive=False |
|
|
3249 | def _performrevert(repo, parents, ctx, actions, interactive=False, | |
|
3250 | tobackup=None): | |
|
3240 | 3251 | """function that actually perform all the actions computed for revert |
|
3241 | 3252 | |
|
3242 | 3253 | This is an independent function to let extension to plug in and react to |
@@ -3316,9 +3327,18 b' def _performrevert(repo, parents, ctx, a' | |||
|
3316 | 3327 | raise error.Abort(_('error parsing patch: %s') % err) |
|
3317 | 3328 | |
|
3318 | 3329 | newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
|
3330 | if tobackup is None: | |
|
3331 | tobackup = set() | |
|
3319 | 3332 | # Apply changes |
|
3320 | 3333 | fp = stringio() |
|
3321 | 3334 | for c in chunks: |
|
3335 | # Create a backup file only if this hunk should be backed up | |
|
3336 | if ishunk(c) and c.header.filename() in tobackup: | |
|
3337 | abs = c.header.filename() | |
|
3338 | target = repo.wjoin(abs) | |
|
3339 | bakname = scmutil.origpath(repo.ui, repo, m.rel(abs)) | |
|
3340 | util.copyfile(target, bakname) | |
|
3341 | tobackup.remove(abs) | |
|
3322 | 3342 | c.write(fp) |
|
3323 | 3343 | dopatch = fp.tell() |
|
3324 | 3344 | fp.seek(0) |
@@ -134,7 +134,41 b' Test that --interactive lift the need fo' | |||
|
134 | 134 | |
|
135 | 135 | abort: user quit |
|
136 | 136 | [255] |
|
137 |
$ |
|
|
137 | $ ls folder1/ | |
|
138 | g | |
|
139 | ||
|
140 | Test that a noop revert doesn't do an unecessary backup | |
|
141 | $ (echo y; echo n) | hg revert -i -r 2 folder1/g | |
|
142 | diff --git a/folder1/g b/folder1/g | |
|
143 | 1 hunks, 1 lines changed | |
|
144 | examine changes to 'folder1/g'? [Ynesfdaq?] y | |
|
145 | ||
|
146 | @@ -3,3 +3,4 @@ | |
|
147 | 3 | |
|
148 | 4 | |
|
149 | 5 | |
|
150 | +d | |
|
151 | revert this change to 'folder1/g'? [Ynesfdaq?] n | |
|
152 | ||
|
153 | $ ls folder1/ | |
|
154 | g | |
|
155 | ||
|
156 | Test --no-backup | |
|
157 | $ (echo y; echo y) | hg revert -i -C -r 2 folder1/g | |
|
158 | diff --git a/folder1/g b/folder1/g | |
|
159 | 1 hunks, 1 lines changed | |
|
160 | examine changes to 'folder1/g'? [Ynesfdaq?] y | |
|
161 | ||
|
162 | @@ -3,3 +3,4 @@ | |
|
163 | 3 | |
|
164 | 4 | |
|
165 | 5 | |
|
166 | +d | |
|
167 | revert this change to 'folder1/g'? [Ynesfdaq?] y | |
|
168 | ||
|
169 | $ ls folder1/ | |
|
170 | g | |
|
171 | >>> open('folder1/g', 'wb').write("1\n2\n3\n4\n5\nd\n") | |
|
138 | 172 | |
|
139 | 173 | |
|
140 | 174 | $ hg update -C 6 |
General Comments 0
You need to be logged in to leave comments.
Login now