comparison mercurial/repair.py @ 22057:445472225ccd

strip: remove -b/--backup codepaths cset ba3bc6474bbf has removed this option. This commit just tidies the code that was associated to it. It also fixes the internal calls to the strip() function. Before this change, any function that thought it would want as a final safety to keep a partial backup bundle (bundling changes not linearly related to the current change being stripped), had to explicitly pass a backup="strip" option. With this change, these backups are always kept in case of an exception and always removed if there is no exception. Only full backups can be specified with backup=True or no full backups with backup=False.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 24 Jul 2014 15:06:08 -0400
parents 4d9d490d7bbe
children d7b114493315
comparison
equal deleted inserted replaced
22056:83df50a8d61c 22057:445472225ccd
45 for fname in files: 45 for fname in files:
46 collectone(repo.file(fname)) 46 collectone(repo.file(fname))
47 47
48 return s 48 return s
49 49
50 def strip(ui, repo, nodelist, backup="all", topic='backup'): 50 def strip(ui, repo, nodelist, backup=True, topic='backup'):
51
52 # Simple way to maintain backwards compatibility for this
53 # argument.
54 if backup in ['none', 'strip']:
55 backup = False
56
51 repo = repo.unfiltered() 57 repo = repo.unfiltered()
52 repo.destroying() 58 repo.destroying()
53 59
54 cl = repo.changelog 60 cl = repo.changelog
55 # TODO handle undo of merge sets 61 # TODO handle undo of merge sets
56 if isinstance(nodelist, str): 62 if isinstance(nodelist, str):
57 nodelist = [nodelist] 63 nodelist = [nodelist]
58 striplist = [cl.rev(node) for node in nodelist] 64 striplist = [cl.rev(node) for node in nodelist]
59 striprev = min(striplist) 65 striprev = min(striplist)
60
61 keeppartialbundle = backup == 'strip'
62 66
63 # Some revisions with rev > striprev may not be descendants of striprev. 67 # Some revisions with rev > striprev may not be descendants of striprev.
64 # We have to find these revisions and put them in a bundle, so that 68 # We have to find these revisions and put them in a bundle, so that
65 # we can restore them after the truncations. 69 # we can restore them after the truncations.
66 # To create the bundle we use repo.changegroupsubset which requires 70 # To create the bundle we use repo.changegroupsubset which requires
107 updatebm.append(m) 111 updatebm.append(m)
108 112
109 # create a changegroup for all the branches we need to keep 113 # create a changegroup for all the branches we need to keep
110 backupfile = None 114 backupfile = None
111 vfs = repo.vfs 115 vfs = repo.vfs
112 if backup == "all": 116 if backup:
113 backupfile = _bundle(repo, stripbases, cl.heads(), node, topic) 117 backupfile = _bundle(repo, stripbases, cl.heads(), node, topic)
114 repo.ui.status(_("saved backup bundle to %s\n") % 118 repo.ui.status(_("saved backup bundle to %s\n") %
115 vfs.join(backupfile)) 119 vfs.join(backupfile))
116 repo.ui.log("backupbundle", "saved backup bundle to %s\n", 120 repo.ui.log("backupbundle", "saved backup bundle to %s\n",
117 vfs.join(backupfile)) 121 vfs.join(backupfile))
118 if saveheads or savebases: 122 if saveheads or savebases:
119 # do not compress partial bundle if we remove it from disk later 123 # do not compress partial bundle if we remove it from disk later
120 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', 124 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp',
121 compress=keeppartialbundle) 125 compress=False)
122 126
123 mfst = repo.manifest 127 mfst = repo.manifest
124 128
125 tr = repo.transaction("strip") 129 tr = repo.transaction("strip")
126 offset = len(tr.entries) 130 offset = len(tr.entries)
154 changegroup.addchangegroup(repo, gen, 'strip', 158 changegroup.addchangegroup(repo, gen, 'strip',
155 'bundle:' + vfs.join(chgrpfile), True) 159 'bundle:' + vfs.join(chgrpfile), True)
156 if not repo.ui.verbose: 160 if not repo.ui.verbose:
157 repo.ui.popbuffer() 161 repo.ui.popbuffer()
158 f.close() 162 f.close()
159 if not keeppartialbundle:
160 vfs.unlink(chgrpfile)
161 163
162 # remove undo files 164 # remove undo files
163 for undovfs, undofile in repo.undofiles(): 165 for undovfs, undofile in repo.undofiles():
164 try: 166 try:
165 undovfs.unlink(undofile) 167 undovfs.unlink(undofile)
177 % vfs.join(backupfile)) 179 % vfs.join(backupfile))
178 elif saveheads: 180 elif saveheads:
179 ui.warn(_("strip failed, partial bundle stored in '%s'\n") 181 ui.warn(_("strip failed, partial bundle stored in '%s'\n")
180 % vfs.join(chgrpfile)) 182 % vfs.join(chgrpfile))
181 raise 183 raise
184 else:
185 if saveheads or savebases:
186 # Remove partial backup only if there were no exceptions
187 vfs.unlink(chgrpfile)
182 188
183 repo.destroyed() 189 repo.destroyed()