def repairvisibleheads(ui, metalog, cl): """Attempt to fix visibleheads by removing invalid commit hashes""" oldtext = decodeutf8(metalog.get("visibleheads") or b"") oldlines = oldtext.splitlines() # Only support v1 right now. if oldlines[0:1] != ["v1"]: ui.write_err(_("visibleheads: skipped\n")) return nodemap = cl.nodemap newlines = [oldlines[0]] + [ hexnode for hexnode in oldlines[1:] if len(hexnode) == 40 and bin(hexnode) in nodemap ] removedcount = len(oldlines) - len(newlines) if removedcount == 0: ui.write_err(_("visibleheads: looks okay\n")) else: # Also add the "tip" node. hextip = hex(cl.tip()) if hextip not in newlines: newlines.append(hextip) newtext = "".join(l + "\n" for l in newlines) metalog.set("visibleheads", encodeutf8(newtext)) metalog.commit("fix visibleheads") ui.write_err( _("visibleheads: removed %s heads, added tip\n") % removedcount)
def repairvisibleheads(ui, metalog, cl): """Attempt to fix visibleheads by removing invalid commit hashes""" oldtext = decodeutf8(metalog.get("visibleheads") or b"") oldlines = oldtext.splitlines() nodemap = cl.nodemap newlines = ["v1"] + [ hexnode for hexnode in oldlines[1:] if len(hexnode) == 40 and bin(hexnode) in nodemap ] removedcount = max(len(oldlines), 1) - len(newlines) if removedcount or oldlines[:1] != ["v1"]: # Also add the "tip" node. hextip = hex(cl.tip()) if hextip not in newlines: newlines.append(hextip) newtext = "".join(l + "\n" for l in newlines) metalog.set("visibleheads", encodeutf8(newtext)) metalog.commit("fix visibleheads") ui.write_err( _("visibleheads: removed %s heads, added tip\n") % removedcount)