Commit 13112e40 authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

git-cleanup: refactor, simplify, and make output more helpful

parent b6cf7e366f64
Pipeline #15778 passed with stages
in 10 minutes and 43 seconds
......@@ -264,19 +264,12 @@
@command(b'git-cleanup')
def git_cleanup(ui, repo):
'''clean up Git commit map after history editing'''
new_map = []
gh = repo.githandler
for line in gh.vfs(gh.map_file):
gitsha, hgsha = line.strip().split(b' ', 1)
if hgsha in repo:
new_map.append(b'%s %s\n' % (gitsha, hgsha))
wlock = repo.wlock()
try:
f = gh.vfs(gh.map_file, b'wb')
f.writelines(new_map)
finally:
wlock.release()
ui.status(_(b'git commit map cleaned\n'))
with repo.wlock():
gh = repo.githandler
ncleaned = gh.clean_map()
gh.save_map(gh.map_file)
ui.status(_(b'%d commits pruned from map\n') % ncleaned)
def findcommonoutgoing(orig, repo, other, *args, **kwargs):
......
......@@ -197,6 +197,15 @@
def map_git_get(self, hgsha):
return self._map_hg.get(hgsha)
def clean_map(self):
prior_size = len(self._map_hg)
for hgsha in list(self._map_hg):
if hgsha not in self.repo:
del self._map_git[self._map_hg.pop(hgsha)]
return prior_size - len(self._map_hg)
def load_map(self):
map_git_real = {}
map_hg_real = {}
......
......@@ -100,7 +100,7 @@
$ ls hgrepo-shared/.hg | grep git
[1]
$ hg -R hgrepo-shared git-cleanup
git commit map cleaned
0 commits pruned from map
$ rm -rf hgrepo-base hgrepo-shared
clone empty repo
......
......@@ -68,7 +68,7 @@
abort: you appear to have run strip - please run hg git-cleanup
[255]
$ hg git-cleanup
git commit map cleaned
1 commits pruned from map
pull works after 'hg git-cleanup'
"adding remote bookmark" message was added in Mercurial 2.3
$ hg pull -r beta | grep -v "adding remote bookmark"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment