treestate: add a debug command to list treestate content

Summary: This is to replace `debugstate -v`. The latter does ont list untracked files.

Reviewed By: DurhamG

Differential Revision: D12906649

fbshipit-source-id: b84f41dfadff4932c0ddd48480a4aa03db88cab0
This commit is contained in:
Jun Wu 2018-11-03 11:10:55 -07:00 committed by Facebook Github Bot
parent 3c85a515b1
commit 9719d371db
3 changed files with 37 additions and 23 deletions

View File

@ -804,8 +804,6 @@ def debugdeltachain(ui, repo, file_=None, **opts):
def debugstate(ui, repo, **opts):
"""show the contents of the current dirstate"""
from .rust import treestate
nodates = opts.get(r"nodates")
datesort = opts.get(r"datesort")
@ -830,17 +828,8 @@ def debugstate(ui, repo, **opts):
mode = "%3o" % (ent[1] & 0o777 & ~util.umask)
msg = "%c %s %10d %s%s" % (ent[0], mode, ent[2], timestr, path)
if ui.verbose and ds._istreestate:
state = dmap._tree.get(path, None)[0]
for name in (
"EXIST_P1",
"EXIST_P2",
"EXIST_NEXT",
"COPIED",
"NEED_CHECK",
"IGNORED",
):
if state & getattr(treestate, name):
msg += " %s" % name
flags = dmap._tree.get(path, None)[0]
msg += " %s" % treestate.reprflags(flags)
ui.write("%s\n" % (msg,))
for dst, src in ds.copies().items():
ui.write(_("copy: %s -> %s\n") % (src, dst))
@ -3180,7 +3169,7 @@ def debugcheckcasecollisions(ui, repo, *testfiles, **opts):
@command(
"debugtreestate|debugtreedirstate",
[],
"hg debugtreestate [on|off|status|repack|cleanup|v0|v1|v2]",
"hg debugtreestate [on|off|status|repack|cleanup|v0|v1|v2|list]",
)
def debugtreestate(ui, repo, cmd="status", **opts):
"""manage treestate
@ -3218,5 +3207,21 @@ def debugtreestate(ui, repo, cmd="status", **opts):
)
else:
ui.status(_("dirstate v0 (flat dirstate, %s files tracked)\n") % len(dmap))
elif cmd == "list":
if "treestate" not in repo.requirements:
raise error.Abort(_("list only supports treestate"))
dmap = repo.dirstate._map
tree = dmap._tree
tget = tree.get
for path in tree.walk(0, 0):
flags, mode, size, mtime, copied = tget(path, None)
flags = treestate.reprflags(flags)
if not ui.verbose:
if mtime >= 1:
mtime = "+"
ui.write(
("%s: 0%o %d %s %s %s\n")
% (path, mode, size, mtime, flags, copied or "")
)
else:
raise error.Abort("unrecognised command: %s" % cmd)

View File

@ -689,6 +689,15 @@ def repack(ui, repo):
return
def reprflags(flags):
"""Turn flags into human-readable string"""
return " ".join(
name
for name in ("EXIST_P1", "EXIST_P2", "EXIST_NEXT", "COPIED", "NEED_CHECK")
if flags & getattr(treestate, name)
)
def onpull(ui, repo):
if "eden" in repo.requirements:
return

View File

@ -15,9 +15,9 @@ Write mtime to treestate
$ hg status
$ hg debugstate -v
* A EXIST_P1 EXIST_NEXT (glob)
* B EXIST_P1 EXIST_NEXT (glob)
$ hg debugtree list
A: 0100644 1 + EXIST_P1 EXIST_NEXT
B: 0100644 1 + EXIST_P1 EXIST_NEXT
Force the files to have NEED_CHECK bits
@ -28,14 +28,14 @@ Force the files to have NEED_CHECK bits
> d.needcheck('B')
> d.write(tr)
> "
$ hg debugstate -v
* A EXIST_P1 EXIST_NEXT NEED_CHECK (glob)
* B EXIST_P1 EXIST_NEXT NEED_CHECK (glob)
$ hg debugtree list
A: 0100644 1 + EXIST_P1 EXIST_NEXT NEED_CHECK
B: 0100644 1 + EXIST_P1 EXIST_NEXT NEED_CHECK
Run status again. NEED_CHECK will disappear.
$ hg status
$ hg debugstate -v
* A EXIST_P1 EXIST_NEXT (glob)
* B EXIST_P1 EXIST_NEXT (glob)
$ hg debugtree list
A: 0100644 1 + EXIST_P1 EXIST_NEXT
B: 0100644 1 + EXIST_P1 EXIST_NEXT