mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 07:49:11 +03:00
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:
parent
5a2246acbf
commit
70050affcc
@ -29,6 +29,7 @@ python_library(
|
||||
],
|
||||
deps = [
|
||||
":lib",
|
||||
"@/eden/fs/inodes:hgdirstate-py",
|
||||
"@/eden/fs/inodes:serialization-py",
|
||||
],
|
||||
)
|
||||
|
@ -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(
|
||||
|
32
eden/integration/debug_hg_get_dirstate_tuple_test.py
Normal file
32
eden/integration/debug_hg_get_dirstate_tuple_test.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user