rust/rhg/src/commands/status.rs
changeset 47374 bd88b6bfd8da
parent 47322 1760de72a992
child 47674 ff97e793ed36
equal deleted inserted replaced
47373:d2fb8b4adcc3 47374:bd88b6bfd8da
     7 
     7 
     8 use crate::error::CommandError;
     8 use crate::error::CommandError;
     9 use crate::ui::Ui;
     9 use crate::ui::Ui;
    10 use clap::{Arg, SubCommand};
    10 use clap::{Arg, SubCommand};
    11 use hg;
    11 use hg;
       
    12 use hg::dirstate_tree::dirstate_map::DirstateMap;
    12 use hg::errors::HgResultExt;
    13 use hg::errors::HgResultExt;
    13 use hg::errors::IoResultExt;
    14 use hg::errors::IoResultExt;
    14 use hg::matchers::AlwaysMatcher;
    15 use hg::matchers::AlwaysMatcher;
    15 use hg::operations::cat;
    16 use hg::operations::cat;
    16 use hg::repo::Repo;
    17 use hg::repo::Repo;
    17 use hg::revlog::node::Node;
    18 use hg::revlog::node::Node;
    18 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
    19 use hg::utils::hg_path::{hg_path_to_os_string, HgPath};
    19 use hg::{DirstateMap, StatusError};
    20 use hg::StatusError;
    20 use hg::{HgPathCow, StatusOptions};
    21 use hg::{HgPathCow, StatusOptions};
    21 use log::{info, warn};
    22 use log::{info, warn};
    22 use std::convert::TryInto;
    23 use std::convert::TryInto;
    23 use std::fs;
    24 use std::fs;
    24 use std::io::BufReader;
    25 use std::io::BufReader;
   162             requested
   163             requested
   163         }
   164         }
   164     };
   165     };
   165 
   166 
   166     let repo = invocation.repo?;
   167     let repo = invocation.repo?;
   167     let mut dmap = DirstateMap::new();
       
   168     let dirstate_data =
   168     let dirstate_data =
   169         repo.hg_vfs().mmap_open("dirstate").io_not_found_as_none()?;
   169         repo.hg_vfs().mmap_open("dirstate").io_not_found_as_none()?;
   170     let dirstate_data = match &dirstate_data {
   170     let dirstate_data = match &dirstate_data {
   171         Some(mmap) => &**mmap,
   171         Some(mmap) => &**mmap,
   172         None => b"",
   172         None => b"",
   173     };
   173     };
   174     let parents = dmap.read(dirstate_data)?;
   174     let (mut dmap, parents) = if repo.has_dirstate_v2() {
       
   175         DirstateMap::new_v2(dirstate_data)?
       
   176     } else {
       
   177         DirstateMap::new_v1(dirstate_data)?
       
   178     };
   175     let options = StatusOptions {
   179     let options = StatusOptions {
   176         // TODO should be provided by the dirstate parsing and
   180         // TODO should be provided by the dirstate parsing and
   177         // hence be stored on dmap. Using a value that assumes we aren't
   181         // hence be stored on dmap. Using a value that assumes we aren't
   178         // below the time resolution granularity of the FS and the
   182         // below the time resolution granularity of the FS and the
   179         // dirstate.
   183         // dirstate.
   185         list_unknown: display_states.unknown,
   189         list_unknown: display_states.unknown,
   186         list_ignored: display_states.ignored,
   190         list_ignored: display_states.ignored,
   187         collect_traversed_dirs: false,
   191         collect_traversed_dirs: false,
   188     };
   192     };
   189     let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded
   193     let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded
   190     let (mut ds_status, pattern_warnings) = hg::status(
   194     let (mut ds_status, pattern_warnings) = hg::dirstate_tree::status::status(
   191         &dmap,
   195         &mut dmap,
   192         &AlwaysMatcher,
   196         &AlwaysMatcher,
   193         repo.working_directory_path().to_owned(),
   197         repo.working_directory_path().to_owned(),
   194         vec![ignore_file],
   198         vec![ignore_file],
   195         options,
   199         options,
   196     )?;
   200     )?;