Introduce eden debug hg_get_dirstate_tuple.

Summary:
This is a convenient way to test the `hgGetDirstateTuple()` endpoint in
`eden.thrift`.

Reviewed By: quark-zju, wez

Differential Revision: D5654237

fbshipit-source-id: 0b285e056002d4556733a53293582345f36780b2
This commit is contained in:
Michael Bolin 2017-08-18 21:36:34 -07:00 committed by Facebook Github Bot
parent 5a2246acbf
commit 70050affcc
3 changed files with 61 additions and 0 deletions

View File

@ -29,6 +29,7 @@ python_library(
],
deps = [
":lib",
"@/eden/fs/inodes:hgdirstate-py",
"@/eden/fs/inodes:serialization-py",
],
)

View File

@ -15,6 +15,7 @@ import sys
from typing import List, Tuple
from facebook.eden.overlay.ttypes import OverlayDir
import facebook.hgdirstate.ttypes as hgdirstate
from . import cmd_util
@ -169,6 +170,26 @@ def _print_inode_info(inode_info):
print(line)
def do_hg_get_dirstate_tuple(args: argparse.Namespace):
config = cmd_util.create_config(args)
mount, rel_path = get_mount_path(args.path)
with config.get_thrift_client() as client:
dirstate_tuple = client.hgGetDirstateTuple(mount, rel_path)
status = hgdirstate.DirstateNonnormalFileStatus._VALUES_TO_NAMES[
dirstate_tuple.status
]
merge_state = hgdirstate.DirstateMergeState._VALUES_TO_NAMES[
dirstate_tuple.mergeState
]
print(f'''\
{rel_path}
status = {status}
mode = {oct(dirstate_tuple.mode)}
mergeState = {merge_state}\
''')
def do_inode(args: argparse.Namespace):
config = cmd_util.create_config(args)
mount, rel_path = get_mount_path(args.path)
@ -372,6 +393,13 @@ def setup_argparse(parser: argparse.ArgumentParser):
parser.add_argument('id', help='The blob ID')
parser.set_defaults(func=do_blobmeta)
parser = subparsers.add_parser(
'hg_get_dirstate_tuple', help='Dirstate status for file')
parser.add_argument(
'path',
help='The path to the file whose status should be queried.')
parser.set_defaults(func=do_hg_get_dirstate_tuple)
parser = subparsers.add_parser(
'inode', help='Show data about loaded inodes')
parser.add_argument(

View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from .lib import testcase
import os
from textwrap import dedent
@testcase.eden_repo_test
class DebugHgGetDirstateTupleTest:
def populate_repo(self):
self.repo.write_file('hello', 'hola\n')
self.repo.write_file(os.path.join('dir', 'file'), 'blah\n')
self.repo.commit('Initial commit.')
def test_get_dirstate_tuple_normal_file(self):
output = self.eden.run_cmd(
'debug', 'hg_get_dirstate_tuple', os.path.join(self.mount, 'hello')
)
expected = dedent('''\
hello
status = Normal
mode = 0o100644
mergeState = NotApplicable
''')
self.assertEqual(expected, output)