comparison mercurial/repair.py @ 11197:4bb4895e1693

strip: be quiet about temporary internal bundle
author Matt Mackall <mpm@selenic.com>
date Wed, 19 May 2010 19:46:39 -0500
parents a685011ed38e
children 12e5149cafca
comparison
equal deleted inserted replaced
11196:573bef78763f 11197:4bb4895e1693
16 cg = repo.changegroupsubset(bases, heads, 'strip', extranodes) 16 cg = repo.changegroupsubset(bases, heads, 'strip', extranodes)
17 backupdir = repo.join("strip-backup") 17 backupdir = repo.join("strip-backup")
18 if not os.path.isdir(backupdir): 18 if not os.path.isdir(backupdir):
19 os.mkdir(backupdir) 19 os.mkdir(backupdir)
20 name = os.path.join(backupdir, "%s-%s" % (short(node), suffix)) 20 name = os.path.join(backupdir, "%s-%s" % (short(node), suffix))
21 repo.ui.warn(_("saving bundle to %s\n") % name)
22 return changegroup.writebundle(cg, name, "HG10BZ") 21 return changegroup.writebundle(cg, name, "HG10BZ")
23 22
24 def _collectfiles(repo, striprev): 23 def _collectfiles(repo, striprev):
25 """find out the filelogs affected by the strip""" 24 """find out the filelogs affected by the strip"""
26 files = set() 25 files = set()
104 files = _collectfiles(repo, striprev) 103 files = _collectfiles(repo, striprev)
105 104
106 extranodes = _collectextranodes(repo, files, striprev) 105 extranodes = _collectextranodes(repo, files, striprev)
107 106
108 # create a changegroup for all the branches we need to keep 107 # create a changegroup for all the branches we need to keep
108 backupfile = None
109 if backup == "all": 109 if backup == "all":
110 _bundle(repo, [node], cl.heads(), node, 'backup') 110 backupfile = _bundle(repo, [node], cl.heads(), node, 'backup')
111 repo.ui.status(_("saving bundle to %s\n") % backupfile)
111 if saveheads or extranodes: 112 if saveheads or extranodes:
112 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp', 113 chgrpfile = _bundle(repo, savebases, saveheads, node, 'temp',
113 extranodes) 114 extranodes)
114 115
115 mfst = repo.manifest 116 mfst = repo.manifest
116 117
117 tr = repo.transaction("strip") 118 tr = repo.transaction("strip")
118 offset = len(tr.entries) 119 offset = len(tr.entries)
119 120
120 tr.startgroup() 121 try:
121 cl.strip(striprev, tr) 122 tr.startgroup()
122 mfst.strip(striprev, tr) 123 cl.strip(striprev, tr)
123 for fn in files: 124 mfst.strip(striprev, tr)
124 repo.file(fn).strip(striprev, tr) 125 for fn in files:
125 tr.endgroup() 126 repo.file(fn).strip(striprev, tr)
127 tr.endgroup()
126 128
127 try: 129 try:
128 for i in xrange(offset, len(tr.entries)): 130 for i in xrange(offset, len(tr.entries)):
129 file, troffset, ignore = tr.entries[i] 131 file, troffset, ignore = tr.entries[i]
130 repo.sopener(file, 'a').truncate(troffset) 132 repo.sopener(file, 'a').truncate(troffset)
131 tr.close() 133 tr.close()
134 except:
135 tr.abort()
136 raise
137
138 if saveheads or extranodes:
139 ui.status(_("adding branch\n"))
140 f = open(chgrpfile, "rb")
141 gen = changegroup.readbundle(f, chgrpfile)
142 repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True)
143 f.close()
144 if backup != "strip":
145 os.unlink(chgrpfile)
132 except: 146 except:
133 tr.abort() 147 if backupfile:
148 ui.warn("strip failed, full bundle stored in '%s'\n" % backupfile)
149 elif saveheads:
150 ui.warn("strip failed, partial bundle stored in '%s'\n"
151 % chgrpfile)
134 raise 152 raise
135 153
136 if saveheads or extranodes:
137 ui.status(_("adding branch\n"))
138 f = open(chgrpfile, "rb")
139 gen = changegroup.readbundle(f, chgrpfile)
140 repo.addchangegroup(gen, 'strip', 'bundle:' + chgrpfile, True)
141 f.close()
142 if backup != "strip":
143 os.unlink(chgrpfile)
144
145 repo.destroyed() 154 repo.destroyed()