This should ideally be amended in 89323f85176e725234bb70b081bc46614ae27589.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
pulkit |
hg-reviewers |
This should ideally be amended in 89323f85176e725234bb70b081bc46614ae27589.
No Linters Available |
No Unit Test Coverage |
backup bundle. | backup bundle. | ||||
--recover takes a changeset hash and unbundles the first bundle that | --recover takes a changeset hash and unbundles the first bundle that | ||||
contains that hash, which puts that changeset back in your repository. | contains that hash, which puts that changeset back in your repository. | ||||
--verbose will print the entire commit message and the bundle path for that | --verbose will print the entire commit message and the bundle path for that | ||||
backup. | backup. | ||||
""" | """ | ||||
backups = filter( | backups = list( | ||||
os.path.isfile, glob.glob(repo.vfs.join("strip-backup") + "/*.hg") | filter( | ||||
os.path.isfile, glob.glob(repo.vfs.join(b"strip-backup") + b"/*.hg") | |||||
) | |||||
) | ) | ||||
backups.sort(key=lambda x: os.path.getmtime(x), reverse=True) | backups.sort(key=lambda x: os.path.getmtime(x), reverse=True) | ||||
opts["bundle"] = "" | opts = pycompat.byteskwargs(opts) | ||||
opts["force"] = None | opts[b"bundle"] = b"" | ||||
opts[b"force"] = None | |||||
limit = logcmdutil.getlimit(opts) | limit = logcmdutil.getlimit(opts) | ||||
def display(other, chlist, displayer): | def display(other, chlist, displayer): | ||||
if opts.get("newest_first"): | if opts.get(b"newest_first"): | ||||
chlist.reverse() | chlist.reverse() | ||||
count = 0 | count = 0 | ||||
for n in chlist: | for n in chlist: | ||||
if limit is not None and count >= limit: | if limit is not None and count >= limit: | ||||
break | break | ||||
parents = [True for p in other.changelog.parents(n) if p != nullid] | parents = [True for p in other.changelog.parents(n) if p != nullid] | ||||
if opts.get("no_merges") and len(parents) == 2: | if opts.get(b"no_merges") and len(parents) == 2: | ||||
continue | continue | ||||
count += 1 | count += 1 | ||||
displayer.show(other[n]) | displayer.show(other[n]) | ||||
recovernode = opts.get("recover") | recovernode = opts.get(b"recover") | ||||
if recovernode: | if recovernode: | ||||
if scmutil.isrevsymbol(repo, recovernode): | if scmutil.isrevsymbol(repo, recovernode): | ||||
ui.warn(_("%s already exists in the repo\n") % recovernode) | ui.warn(_(b"%s already exists in the repo\n") % recovernode) | ||||
return | return | ||||
elif backups: | elif backups: | ||||
msg = _( | msg = _( | ||||
"Recover changesets using: hg debugbackupbundle --recover " | b"Recover changesets using: hg debugbackupbundle --recover " | ||||
"<changeset hash>\n\nAvailable backup changesets:" | b"<changeset hash>\n\nAvailable backup changesets:" | ||||
) | ) | ||||
ui.status(msg, label="status.removed") | ui.status(msg, label=b"status.removed") | ||||
else: | else: | ||||
ui.status(_("no backup changesets found\n")) | ui.status(_(b"no backup changesets found\n")) | ||||
return | return | ||||
for backup in backups: | for backup in backups: | ||||
# Much of this is copied from the hg incoming logic | # Much of this is copied from the hg incoming logic | ||||
source = ui.expandpath(os.path.relpath(backup, encoding.getcwd())) | source = ui.expandpath(os.path.relpath(backup, encoding.getcwd())) | ||||
source, branches = hg.parseurl(source, opts.get("branch")) | source, branches = hg.parseurl(source, opts.get(b"branch")) | ||||
try: | try: | ||||
other = hg.peer(repo, opts, source) | other = hg.peer(repo, opts, source) | ||||
except error.LookupError as ex: | except error.LookupError as ex: | ||||
msg = _("\nwarning: unable to open bundle %s") % source | msg = _(b"\nwarning: unable to open bundle %s") % source | ||||
hint = _("\n(missing parent rev %s)\n") % short(ex.name) | hint = _(b"\n(missing parent rev %s)\n") % short(ex.name) | ||||
ui.warn(msg, hint=hint) | ui.warn(msg, hint=hint) | ||||
continue | continue | ||||
revs, checkout = hg.addbranchrevs( | revs, checkout = hg.addbranchrevs( | ||||
repo, other, branches, opts.get("rev") | repo, other, branches, opts.get(b"rev") | ||||
) | ) | ||||
if revs: | if revs: | ||||
revs = [other.lookup(rev) for rev in revs] | revs = [other.lookup(rev) for rev in revs] | ||||
quiet = ui.quiet | quiet = ui.quiet | ||||
try: | try: | ||||
ui.quiet = True | ui.quiet = True | ||||
other, chlist, cleanupfn = bundlerepo.getremotechanges( | other, chlist, cleanupfn = bundlerepo.getremotechanges( | ||||
ui, repo, other, revs, opts["bundle"], opts["force"] | ui, repo, other, revs, opts[b"bundle"], opts[b"force"] | ||||
) | ) | ||||
except error.LookupError: | except error.LookupError: | ||||
continue | continue | ||||
finally: | finally: | ||||
ui.quiet = quiet | ui.quiet = quiet | ||||
try: | try: | ||||
if not chlist: | if not chlist: | ||||
continue | continue | ||||
if recovernode: | if recovernode: | ||||
with repo.lock(), repo.transaction("unbundle") as tr: | with repo.lock(), repo.transaction(b"unbundle") as tr: | ||||
if scmutil.isrevsymbol(other, recovernode): | if scmutil.isrevsymbol(other, recovernode): | ||||
ui.status(_("Unbundling %s\n") % (recovernode)) | ui.status(_(b"Unbundling %s\n") % (recovernode)) | ||||
f = hg.openpath(ui, source) | f = hg.openpath(ui, source) | ||||
gen = exchange.readbundle(ui, f, source) | gen = exchange.readbundle(ui, f, source) | ||||
if isinstance(gen, bundle2.unbundle20): | if isinstance(gen, bundle2.unbundle20): | ||||
bundle2.applybundle( | bundle2.applybundle( | ||||
repo, | repo, | ||||
gen, | gen, | ||||
tr, | tr, | ||||
source="unbundle", | source=b"unbundle", | ||||
url="bundle:" + source, | url=b"bundle:" + source, | ||||
) | ) | ||||
else: | else: | ||||
gen.apply(repo, "unbundle", "bundle:" + source) | gen.apply(repo, b"unbundle", b"bundle:" + source) | ||||
break | break | ||||
else: | else: | ||||
backupdate = time.strftime( | backupdate = encoding.strtolocal( | ||||
time.strftime( | |||||
"%a %H:%M, %Y-%m-%d", | "%a %H:%M, %Y-%m-%d", | ||||
time.localtime(os.path.getmtime(source)), | time.localtime(os.path.getmtime(source)), | ||||
) | ) | ||||
ui.status("\n%s\n" % (backupdate.ljust(50))) | ) | ||||
ui.status(b"\n%s\n" % (backupdate.ljust(50))) | |||||
if ui.verbose: | if ui.verbose: | ||||
ui.status("%s%s\n" % ("bundle:".ljust(13), source)) | ui.status(b"%s%s\n" % (b"bundle:".ljust(13), source)) | ||||
else: | else: | ||||
opts[ | opts[ | ||||
"template" | b"template" | ||||
] = "{label('status.modified', node|short)} {desc|firstline}\n" | ] = b"{label('status.modified', node|short)} {desc|firstline}\n" | ||||
displayer = logcmdutil.changesetdisplayer( | displayer = logcmdutil.changesetdisplayer( | ||||
ui, other, opts, False | ui, other, opts, False | ||||
) | ) | ||||
display(other, chlist, displayer) | display(other, chlist, displayer) | ||||
displayer.close() | displayer.close() | ||||
finally: | finally: | ||||
cleanupfn() | cleanupfn() | ||||