##// END OF EJS Templates
keyword: support rollback by restoring expansion to previous values...
Christian Ebert -
r12498:4846e8cd default
parent child Browse files
Show More
@@ -92,8 +92,7 b" commands.optionalrepo += ' kwdemo'"
92 92
93 93 # hg commands that do not act on keywords
94 94 nokwcommands = ('add addremove annotate bundle copy export grep incoming init'
95 ' log outgoing push rename rollback tip verify'
96 ' convert email glog')
95 ' log outgoing push rename tip verify convert email glog')
97 96
98 97 # hg commands that trigger expansion only when writing to working dir,
99 98 # not when reading filelog, and unexpand when reading from working dir
@@ -192,19 +191,20 b' class kwtemplater(object):'
192 191 Caveat: localrepository._link fails on Windows.'''
193 192 return self.match(path) and not 'l' in flagfunc(path)
194 193
195 def overwrite(self, ctx, candidates, iswctx, expand):
194 def overwrite(self, ctx, candidates, iswctx, expand, cfiles):
196 195 '''Overwrites selected files expanding/shrinking keywords.'''
197 if self.record:
198 candidates = [f for f in ctx.files() if f in ctx]
196 if cfiles is not None:
197 candidates = [f for f in candidates if f in cfiles]
199 198 candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
200 199 if candidates:
201 200 restrict = self.restrict
202 201 self.restrict = True # do not expand when reading
202 rollback = kwtools['hgcmd'] == 'rollback'
203 203 mf = ctx.manifest()
204 204 msg = (expand and _('overwriting %s expanding keywords\n')
205 205 or _('overwriting %s shrinking keywords\n'))
206 206 for f in candidates:
207 if not self.record:
207 if not self.record and not rollback:
208 208 data = self.repo.file(f).read(mf[f])
209 209 else:
210 210 data = self.repo.wread(f)
@@ -220,7 +220,7 b' class kwtemplater(object):'
220 220 if found:
221 221 self.ui.note(msg % f)
222 222 self.repo.wwrite(f, data, mf.flags(f))
223 if iswctx:
223 if iswctx and not rollback:
224 224 self.repo.dirstate.normal(f)
225 225 elif self.record:
226 226 self.repo.dirstate.normallookup(f)
@@ -299,7 +299,7 b' def _kwfwrite(ui, repo, expand, *pats, *'
299 299 modified, added, removed, deleted, unknown, ignored, clean = status
300 300 if modified or added or removed or deleted:
301 301 raise util.Abort(_('outstanding uncommitted changes'))
302 kwt.overwrite(wctx, clean, True, expand)
302 kwt.overwrite(wctx, clean, True, expand, None)
303 303 finally:
304 304 wlock.release()
305 305
@@ -503,9 +503,24 b' def reposetup(ui, repo):'
503 503 # no lock needed, only called from repo.commit() which already locks
504 504 if not kwt.record:
505 505 kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()),
506 False, True)
506 False, True, None)
507 507 return n
508 508
509 def rollback(self, dryrun=False):
510 wlock = repo.wlock()
511 try:
512 if not dryrun:
513 cfiles = self['.'].files()
514 ret = super(kwrepo, self).rollback(dryrun)
515 if not dryrun:
516 ctx = self['.']
517 modified, added = super(kwrepo, self).status()[:2]
518 kwt.overwrite(ctx, added, True, False, cfiles)
519 kwt.overwrite(ctx, modified, True, True, cfiles)
520 return ret
521 finally:
522 wlock.release()
523
509 524 # monkeypatches
510 525 def kwpatchfile_init(orig, self, ui, fname, opener,
511 526 missing=False, eolmode=None):
@@ -536,7 +551,8 b' def reposetup(ui, repo):'
536 551 ret = orig(ui, repo, commitfunc, *pats, **opts)
537 552 recordctx = repo['.']
538 553 if ctx != recordctx:
539 kwt.overwrite(recordctx, None, False, True)
554 kwt.overwrite(recordctx, recordctx.files(),
555 False, True, recordctx)
540 556 return ret
541 557 finally:
542 558 wlock.release()
@@ -375,10 +375,48 b' File a should be clean'
375 375
376 376 $ hg status -A a
377 377 C a
378 $ rm msg
378 379
379 $ rm msg
380 $ hg rollback
380 rollback and revert expansion
381
382 $ cat a
383 expand $Id: a,v 59f969a3b52c 1970/01/01 00:00:01 test $
384 foo
385 do not process $Id:
386 xxx $
387 bar
388 $ hg --verbose rollback
381 389 rolling back to revision 2 (undo commit)
390 overwriting a expanding keywords
391 $ hg status a
392 M a
393 $ cat a
394 expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $
395 foo
396 do not process $Id:
397 xxx $
398 bar
399 $ echo '$Id$' > y
400 $ echo '$Id$' > z
401 $ hg add y
402 $ hg commit -Am "rollback only" z
403 $ cat z
404 $Id: z,v 45a5d3adce53 1970/01/01 00:00:00 test $
405 $ hg --verbose rollback
406 rolling back to revision 2 (undo commit)
407 overwriting z shrinking keywords
408
409 Only z should be overwritten
410
411 $ hg status a y z
412 M a
413 A y
414 A z
415 $ cat z
416 $Id$
417 $ hg forget y z
418 $ rm y z
419
382 420 $ hg update -C
383 421 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
384 422
General Comments 0
You need to be logged in to leave comments. Login now