5 use clap::AppSettings; |
5 use clap::AppSettings; |
6 use clap::Arg; |
6 use clap::Arg; |
7 use clap::ArgMatches; |
7 use clap::ArgMatches; |
8 use format_bytes::{format_bytes, join}; |
8 use format_bytes::{format_bytes, join}; |
9 use hg::config::{Config, ConfigSource}; |
9 use hg::config::{Config, ConfigSource}; |
10 use hg::exit_codes; |
|
11 use hg::repo::{Repo, RepoError}; |
10 use hg::repo::{Repo, RepoError}; |
12 use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes}; |
11 use hg::utils::files::{get_bytes_from_os_str, get_path_from_bytes}; |
13 use hg::utils::SliceExt; |
12 use hg::utils::SliceExt; |
|
13 use hg::{exit_codes, requirements}; |
14 use std::collections::HashSet; |
14 use std::collections::HashSet; |
15 use std::ffi::OsString; |
15 use std::ffi::OsString; |
16 use std::os::unix::prelude::CommandExt; |
16 use std::os::unix::prelude::CommandExt; |
17 use std::path::PathBuf; |
17 use std::path::PathBuf; |
18 use std::process::Command; |
18 use std::process::Command; |
722 ), |
722 ), |
723 }) |
723 }) |
724 } |
724 } |
725 } |
725 } |
726 |
726 |
|
727 /// Array of tuples of (auto upgrade conf, feature conf, local requirement) |
|
728 const AUTO_UPGRADES: &[((&str, &str), (&str, &str), &str)] = &[ |
|
729 ( |
|
730 ("format", "use-share-safe.automatic-upgrade-of-mismatching-repositories"), |
|
731 ("format", "use-share-safe"), |
|
732 requirements::SHARESAFE_REQUIREMENT, |
|
733 ), |
|
734 ]; |
|
735 |
|
736 /// Mercurial allows users to automatically upgrade their repository. |
|
737 /// `rhg` does not have the ability to upgrade yet, so fallback if an upgrade |
|
738 /// is needed. |
|
739 fn check_auto_upgrade( |
|
740 config: &Config, |
|
741 reqs: &HashSet<String>, |
|
742 ) -> Result<(), CommandError> { |
|
743 for (upgrade_conf, feature_conf, local_req) in AUTO_UPGRADES.iter() { |
|
744 let auto_upgrade = config |
|
745 .get_bool(upgrade_conf.0.as_bytes(), upgrade_conf.1.as_bytes())?; |
|
746 |
|
747 if auto_upgrade { |
|
748 let want_it = config.get_bool( |
|
749 feature_conf.0.as_bytes(), |
|
750 feature_conf.1.as_bytes(), |
|
751 )?; |
|
752 let have_it = reqs.contains(*local_req); |
|
753 |
|
754 let action = match (want_it, have_it) { |
|
755 (true, false) => Some("upgrade"), |
|
756 (false, true) => Some("downgrade"), |
|
757 _ => None, |
|
758 }; |
|
759 if let Some(action) = action { |
|
760 let message = format!( |
|
761 "automatic {} {}.{}", |
|
762 action, upgrade_conf.0, upgrade_conf.1 |
|
763 ); |
|
764 return Err(CommandError::unsupported(message)); |
|
765 } |
|
766 } |
|
767 } |
|
768 Ok(()) |
|
769 } |
|
770 |
727 fn check_unsupported( |
771 fn check_unsupported( |
728 config: &Config, |
772 config: &Config, |
729 repo: Result<&Repo, &NoRepoInCwdError>, |
773 repo: Result<&Repo, &NoRepoInCwdError>, |
730 ) -> Result<(), CommandError> { |
774 ) -> Result<(), CommandError> { |
731 check_extensions(config)?; |
775 check_extensions(config)?; |
738 |
782 |
739 if let Ok(repo) = repo { |
783 if let Ok(repo) = repo { |
740 if repo.has_subrepos()? { |
784 if repo.has_subrepos()? { |
741 Err(CommandError::unsupported("sub-repositories"))? |
785 Err(CommandError::unsupported("sub-repositories"))? |
742 } |
786 } |
|
787 check_auto_upgrade(config, repo.requirements())?; |
743 } |
788 } |
744 |
789 |
745 if config.has_non_empty_section(b"encode") { |
790 if config.has_non_empty_section(b"encode") { |
746 Err(CommandError::unsupported("[encode] config"))? |
791 Err(CommandError::unsupported("[encode] config"))? |
747 } |
792 } |