config: move default.d/mergetools.rc to code

Summary:
See the previous diff for motivation.

This diff moves the special builtin config to code so we no longer need
"data_path" for the "load_system" API.

Reviewed By: markbt

Differential Revision: D15307750

fbshipit-source-id: 15b729e6585ead5ead05ffd6ffe688387b8e0be9
This commit is contained in:
Jun Wu 2019-05-16 17:23:11 -07:00 committed by Facebook Github Bot
parent 0cc687df58
commit 302109a922
7 changed files with 171 additions and 208 deletions

View File

@ -1,146 +0,0 @@
# Some default global settings for common merge tools
[merge-tools]
kdiff3.args=--auto --L1 base --L2 local --L3 other $base $local $other -o $output
kdiff3.regkey=Software\KDiff3
kdiff3.regkeyalt=Software\Wow6432Node\KDiff3
kdiff3.regappend=\kdiff3.exe
kdiff3.fixeol=True
kdiff3.gui=True
kdiff3.diffargs=--L1 $plabel1 --L2 $clabel $parent $child
gvimdiff.args=--nofork -d -g -O $local $other $base
gvimdiff.regkey=Software\Vim\GVim
gvimdiff.regkeyalt=Software\Wow6432Node\Vim\GVim
gvimdiff.regname=path
gvimdiff.priority=-9
gvimdiff.diffargs=--nofork -d -g -O $parent $child
vimdiff.args=$local $other $base -c 'redraw | echomsg "hg merge conflict, type \":cq\" to abort vimdiff"'
vimdiff.check=changed
vimdiff.priority=-10
merge.check=conflicts
merge.priority=-100
gpyfm.gui=True
meld.gui=True
meld.args=--label='local' $local --label='merged' $base --label='other' $other -o $output
meld.check=changed
meld.diffargs=-a --label=$plabel1 $parent --label=$clabel $child
tkdiff.args=$local $other -a $base -o $output
tkdiff.gui=True
tkdiff.priority=-8
tkdiff.diffargs=-L $plabel1 $parent -L $clabel $child
xxdiff.args=--show-merged-pane --exit-with-merge-status --title1 local --title2 base --title3 other --merged-filename $output --merge $local $base $other
xxdiff.gui=True
xxdiff.priority=-8
xxdiff.diffargs=--title1 $plabel1 $parent --title2 $clabel $child
diffmerge.regkey=Software\SourceGear\SourceGear DiffMerge\
diffmerge.regkeyalt=Software\Wow6432Node\SourceGear\SourceGear DiffMerge\
diffmerge.regname=Location
diffmerge.priority=-7
diffmerge.args=-nosplash -merge -title1=local -title2=merged -title3=other $local $base $other -result=$output
diffmerge.check=changed
diffmerge.gui=True
diffmerge.diffargs=--nosplash --title1=$plabel1 --title2=$clabel $parent $child
p4merge.args=$base $local $other $output
p4merge.regkey=Software\Perforce\Environment
p4merge.regkeyalt=Software\Wow6432Node\Perforce\Environment
p4merge.regname=P4INSTROOT
p4merge.regappend=\p4merge.exe
p4merge.gui=True
p4merge.priority=-8
p4merge.diffargs=$parent $child
p4mergeosx.executable = /Applications/p4merge.app/Contents/MacOS/p4merge
p4mergeosx.args = $base $local $other $output
p4mergeosx.gui = True
p4mergeosx.priority=-8
p4mergeosx.diffargs=$parent $child
tortoisemerge.args=/base:$base /mine:$local /theirs:$other /merged:$output
tortoisemerge.regkey=Software\TortoiseSVN
tortoisemerge.regkeyalt=Software\Wow6432Node\TortoiseSVN
tortoisemerge.check=changed
tortoisemerge.gui=True
tortoisemerge.priority=-8
tortoisemerge.diffargs=/base:$parent /mine:$child /basename:$plabel1 /minename:$clabel
ecmerge.args=$base $local $other --mode=merge3 --title0=base --title1=local --title2=other --to=$output
ecmerge.regkey=Software\Elli\xc3\xa9 Computing\Merge
ecmerge.regkeyalt=Software\Wow6432Node\Elli\xc3\xa9 Computing\Merge
ecmerge.gui=True
ecmerge.diffargs=$parent $child --mode=diff2 --title1=$plabel1 --title2=$clabel
# editmerge is a small script shipped in contrib.
# It needs this config otherwise it behaves the same as internal:local
editmerge.args=$output
editmerge.check=changed
editmerge.premerge=keep
filemerge.executable=/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge
filemerge.args=-left $other -right $local -ancestor $base -merge $output
filemerge.gui=True
filemergexcode.executable=/Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge
filemergexcode.args=-left $other -right $local -ancestor $base -merge $output
filemergexcode.gui=True
; Windows version of Beyond Compare
beyondcompare3.args=$local $other $base $output /ro /lefttitle=local /centertitle=base /righttitle=other /automerge /reviewconflicts /solo
beyondcompare3.regkey=Software\Scooter Software\Beyond Compare 3
beyondcompare3.regname=ExePath
beyondcompare3.gui=True
beyondcompare3.priority=-2
beyondcompare3.diffargs=/lro /lefttitle=$plabel1 /righttitle=$clabel /solo /expandall $parent $child
; Linux version of Beyond Compare
bcompare.args=$local $other $base -mergeoutput=$output -ro -lefttitle=parent1 -centertitle=base -righttitle=parent2 -outputtitle=merged -automerge -reviewconflicts -solo
bcompare.gui=True
bcompare.priority=-1
bcompare.diffargs=-lro -lefttitle=$plabel1 -righttitle=$clabel -solo -expandall $parent $child
; OS X version of Beyond Compare
bcomposx.executable = /Applications/Beyond Compare.app/Contents/MacOS/bcomp
bcomposx.args=$local $other $base -mergeoutput=$output -ro -lefttitle=parent1 -centertitle=base -righttitle=parent2 -outputtitle=merged -automerge -reviewconflicts -solo
bcomposx.gui=True
bcomposx.priority=-1
bcomposx.diffargs=-lro -lefttitle=$plabel1 -righttitle=$clabel -solo -expandall $parent $child
winmerge.args=/e /x /wl /ub /dl other /dr local $other $local $output
winmerge.regkey=Software\Thingamahoochie\WinMerge
winmerge.regkeyalt=Software\Wow6432Node\Thingamahoochie\WinMerge\
winmerge.regname=Executable
winmerge.check=changed
winmerge.gui=True
winmerge.priority=-10
winmerge.diffargs=/r /e /x /ub /wl /dl $plabel1 /dr $clabel $parent $child
araxis.regkey=SOFTWARE\Classes\TypeLib\{46799e0a-7bd1-4330-911c-9660bb964ea2}\7.0\HELPDIR
araxis.regappend=\ConsoleCompare.exe
araxis.priority=-2
araxis.args=/3 /a2 /wait /merge /title1:"Other" /title2:"Base" /title3:"Local :"$local $other $base $local $output
araxis.checkconflict=True
araxis.binary=True
araxis.gui=True
araxis.diffargs=/2 /wait /title1:$plabel1 /title2:$clabel $parent $child
diffuse.priority=-3
diffuse.args=$local $base $other
diffuse.gui=True
diffuse.diffargs=$parent $child
UltraCompare.regkey=Software\Microsoft\Windows\CurrentVersion\App Paths\UC.exe
UltraCompare.regkeyalt=Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths\UC.exe
UltraCompare.args = $base $local $other -title1 base -title3 other
UltraCompare.priority = -2
UltraCompare.gui = True
UltraCompare.binary = True
UltraCompare.check = conflicts,changed
UltraCompare.diffargs=$child $parent -title1 $clabel -title2 $plabel1

View File

@ -312,12 +312,9 @@ ones.
- ``<repo>/.hg/hgrc`` (per-repository)
- ``$HOME/.hgrc`` (per-user)
- ``${XDG_CONFIG_HOME:-$HOME/.config}/hg/hgrc`` (per-user)
- ``<install-root>/etc/mercurial/hgrc`` (per-installation)
- ``<install-root>/etc/mercurial/hgrc.d/*.rc`` (per-installation)
- ``/etc/mercurial/hgrc`` (per-system)
- ``/etc/mercurial/hgrc.d/*.rc`` (per-system)
- ``<internal>/default.d/*.rc`` (defaults)
- ``$XDG_CONFIG_HOME/hg/hgrc`` (per-user)
- ``/etc/mercurial/system.rc`` (per-system)
- ``<builtin>`` (builtin)
.. container:: verbose.windows
@ -326,33 +323,8 @@ ones.
- ``<repo>/.hg/hgrc`` (per-repository)
- ``%USERPROFILE%\.hgrc`` (per-user)
- ``%USERPROFILE%\Mercurial.ini`` (per-user)
- ``%HOME%\.hgrc`` (per-user)
- ``%HOME%\Mercurial.ini`` (per-user)
- ``HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial`` (per-installation)
- ``<install-dir>\hgrc.d\*.rc`` (per-installation)
- ``<install-dir>\Mercurial.ini`` (per-installation)
- ``<internal>/default.d/*.rc`` (defaults)
.. note::
The registry key ``HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mercurial``
is used when running 32-bit Python on 64-bit Windows.
.. container:: windows
On Windows 9x, ``%HOME%`` is replaced by ``%APPDATA%``.
.. container:: verbose.plan9
On Plan9, the following files are consulted:
- ``<repo>/.hg/hgrc`` (per-repository)
- ``$home/lib/hgrc`` (per-user)
- ``<install-root>/lib/mercurial/hgrc`` (per-installation)
- ``<install-root>/lib/mercurial/hgrc.d/*.rc`` (per-installation)
- ``/lib/mercurial/hgrc`` (per-system)
- ``/lib/mercurial/hgrc.d/*.rc`` (per-system)
- ``<internal>/default.d/*.rc`` (defaults)
- ``%PROGRAMDATA%\Facebook\Mercurial`` (per-installation)
- ``<builtin>`` (builtin)
Per-repository configuration options only apply in a
particular repository. This file is not version-controlled, and

View File

@ -55,15 +55,6 @@ def envrcitems(env=None):
return result
def defaultrcpath():
"""return rc paths in default.d"""
path = []
defaultpath = os.path.join(util.datapath, "default.d")
if os.path.isdir(defaultpath):
path = _expandrcpath(defaultpath)
return path
def rccomponents():
"""return an ordered [(type, obj)] about where to load configs.
@ -88,7 +79,7 @@ def rccomponents():
_rccomponents.extend(("path", p) for p in _expandrcpath(p))
else:
normpaths = lambda paths: [("path", os.path.normpath(p)) for p in paths]
_rccomponents = normpaths(defaultrcpath() + systemrcpath())
_rccomponents = normpaths(systemrcpath())
_rccomponents.append(envrc)
_rccomponents.extend(normpaths(userrcpath()))
return _rccomponents

View File

@ -10,9 +10,9 @@ use std::{cell::RefCell, collections::HashMap};
use cpython::exc::UnicodeDecodeError;
use cpython::*;
use ::configparser::{
use configparser::{
config::{ConfigSet, Options},
hg::{parse_list, ConfigSetHgExt, OptionsHgExt},
hg::{parse_list, ConfigSetHgExt, OptionsHgExt, HGRCPATH},
};
use encoding::{local_bytes_to_path, path_to_local_bytes};
@ -139,12 +139,14 @@ py_class!(class config |py| {
}
@staticmethod
def load(datapath: PyBytes) -> PyResult<(config, Vec<PyBytes>)> {
let datapath = local_bytes_to_path(datapath.data(py))
.map_err(|_| encoding_error(py, &datapath))?;
def load() -> PyResult<(config, Vec<PyBytes>)> {
let mut cfg = ConfigSet::new();
let mut errors = Vec::new();
errors.append(&mut cfg.load_system(datapath));
// Only load builtin configs if HGRCPATH is not set.
if std::env::var(HGRCPATH).is_err() {
cfg.parse(MERGE_TOOLS_CONFIG, &"merge-tools.rc".into());
}
errors.append(&mut cfg.load_system());
errors.append(&mut cfg.load_user());
let errors = errors_to_pybytes_vec(py, errors);
config::create_instance(py, RefCell::new(cfg)).map(|cfg| (cfg, errors))
@ -172,3 +174,151 @@ fn errors_to_pybytes_vec(py: Python, errors: Vec<configparser::error::Error>) ->
.map(|err| PyBytes::new(py, format!("{}", err).as_bytes()))
.collect()
}
const MERGE_TOOLS_CONFIG: &str = r#"# Some default global settings for common merge tools
[merge-tools]
kdiff3.args=--auto --L1 base --L2 local --L3 other $base $local $other -o $output
kdiff3.regkey=Software\KDiff3
kdiff3.regkeyalt=Software\Wow6432Node\KDiff3
kdiff3.regappend=\kdiff3.exe
kdiff3.fixeol=True
kdiff3.gui=True
kdiff3.diffargs=--L1 $plabel1 --L2 $clabel $parent $child
gvimdiff.args=--nofork -d -g -O $local $other $base
gvimdiff.regkey=Software\Vim\GVim
gvimdiff.regkeyalt=Software\Wow6432Node\Vim\GVim
gvimdiff.regname=path
gvimdiff.priority=-9
gvimdiff.diffargs=--nofork -d -g -O $parent $child
vimdiff.args=$local $other $base -c 'redraw | echomsg "hg merge conflict, type \":cq\" to abort vimdiff"'
vimdiff.check=changed
vimdiff.priority=-10
merge.check=conflicts
merge.priority=-100
gpyfm.gui=True
meld.gui=True
meld.args=--label='local' $local --label='merged' $base --label='other' $other -o $output
meld.check=changed
meld.diffargs=-a --label=$plabel1 $parent --label=$clabel $child
tkdiff.args=$local $other -a $base -o $output
tkdiff.gui=True
tkdiff.priority=-8
tkdiff.diffargs=-L $plabel1 $parent -L $clabel $child
xxdiff.args=--show-merged-pane --exit-with-merge-status --title1 local --title2 base --title3 other --merged-filename $output --merge $local $base $other
xxdiff.gui=True
xxdiff.priority=-8
xxdiff.diffargs=--title1 $plabel1 $parent --title2 $clabel $child
diffmerge.regkey=Software\SourceGear\SourceGear DiffMerge\
diffmerge.regkeyalt=Software\Wow6432Node\SourceGear\SourceGear DiffMerge\
diffmerge.regname=Location
diffmerge.priority=-7
diffmerge.args=-nosplash -merge -title1=local -title2=merged -title3=other $local $base $other -result=$output
diffmerge.check=changed
diffmerge.gui=True
diffmerge.diffargs=--nosplash --title1=$plabel1 --title2=$clabel $parent $child
p4merge.args=$base $local $other $output
p4merge.regkey=Software\Perforce\Environment
p4merge.regkeyalt=Software\Wow6432Node\Perforce\Environment
p4merge.regname=P4INSTROOT
p4merge.regappend=\p4merge.exe
p4merge.gui=True
p4merge.priority=-8
p4merge.diffargs=$parent $child
p4mergeosx.executable = /Applications/p4merge.app/Contents/MacOS/p4merge
p4mergeosx.args = $base $local $other $output
p4mergeosx.gui = True
p4mergeosx.priority=-8
p4mergeosx.diffargs=$parent $child
tortoisemerge.args=/base:$base /mine:$local /theirs:$other /merged:$output
tortoisemerge.regkey=Software\TortoiseSVN
tortoisemerge.regkeyalt=Software\Wow6432Node\TortoiseSVN
tortoisemerge.check=changed
tortoisemerge.gui=True
tortoisemerge.priority=-8
tortoisemerge.diffargs=/base:$parent /mine:$child /basename:$plabel1 /minename:$clabel
ecmerge.args=$base $local $other --mode=merge3 --title0=base --title1=local --title2=other --to=$output
ecmerge.regkey=Software\Elli\xc3\xa9 Computing\Merge
ecmerge.regkeyalt=Software\Wow6432Node\Elli\xc3\xa9 Computing\Merge
ecmerge.gui=True
ecmerge.diffargs=$parent $child --mode=diff2 --title1=$plabel1 --title2=$clabel
# editmerge is a small script shipped in contrib.
# It needs this config otherwise it behaves the same as internal:local
editmerge.args=$output
editmerge.check=changed
editmerge.premerge=keep
filemerge.executable=/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge
filemerge.args=-left $other -right $local -ancestor $base -merge $output
filemerge.gui=True
filemergexcode.executable=/Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge
filemergexcode.args=-left $other -right $local -ancestor $base -merge $output
filemergexcode.gui=True
; Windows version of Beyond Compare
beyondcompare3.args=$local $other $base $output /ro /lefttitle=local /centertitle=base /righttitle=other /automerge /reviewconflicts /solo
beyondcompare3.regkey=Software\Scooter Software\Beyond Compare 3
beyondcompare3.regname=ExePath
beyondcompare3.gui=True
beyondcompare3.priority=-2
beyondcompare3.diffargs=/lro /lefttitle=$plabel1 /righttitle=$clabel /solo /expandall $parent $child
; Linux version of Beyond Compare
bcompare.args=$local $other $base -mergeoutput=$output -ro -lefttitle=parent1 -centertitle=base -righttitle=parent2 -outputtitle=merged -automerge -reviewconflicts -solo
bcompare.gui=True
bcompare.priority=-1
bcompare.diffargs=-lro -lefttitle=$plabel1 -righttitle=$clabel -solo -expandall $parent $child
; OS X version of Beyond Compare
bcomposx.executable = /Applications/Beyond Compare.app/Contents/MacOS/bcomp
bcomposx.args=$local $other $base -mergeoutput=$output -ro -lefttitle=parent1 -centertitle=base -righttitle=parent2 -outputtitle=merged -automerge -reviewconflicts -solo
bcomposx.gui=True
bcomposx.priority=-1
bcomposx.diffargs=-lro -lefttitle=$plabel1 -righttitle=$clabel -solo -expandall $parent $child
winmerge.args=/e /x /wl /ub /dl other /dr local $other $local $output
winmerge.regkey=Software\Thingamahoochie\WinMerge
winmerge.regkeyalt=Software\Wow6432Node\Thingamahoochie\WinMerge\
winmerge.regname=Executable
winmerge.check=changed
winmerge.gui=True
winmerge.priority=-10
winmerge.diffargs=/r /e /x /ub /wl /dl $plabel1 /dr $clabel $parent $child
araxis.regkey=SOFTWARE\Classes\TypeLib\{46799e0a-7bd1-4330-911c-9660bb964ea2}\7.0\HELPDIR
araxis.regappend=\ConsoleCompare.exe
araxis.priority=-2
araxis.args=/3 /a2 /wait /merge /title1:"Other" /title2:"Base" /title3:"Local :"$local $other $base $local $output
araxis.checkconflict=True
araxis.binary=True
araxis.gui=True
araxis.diffargs=/2 /wait /title1:$plabel1 /title2:$clabel $parent $child
diffuse.priority=-3
diffuse.args=$local $base $other
diffuse.gui=True
diffuse.diffargs=$parent $child
UltraCompare.regkey=Software\Microsoft\Windows\CurrentVersion\App Paths\UC.exe
UltraCompare.regkeyalt=Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths\UC.exe
UltraCompare.args = $base $local $other -title1 base -title3 other
UltraCompare.priority = -2
UltraCompare.gui = True
UltraCompare.binary = True
UltraCompare.check = conflicts,changed
UltraCompare.diffargs=$child $parent -title1 $clabel -title2 $plabel1
"#;

View File

@ -259,7 +259,7 @@ class ui(object):
def load(cls):
"""Create a ui and load global and user configs"""
u = cls()
u._rcfg, errors = configparser.config.load(util.datapath)
u._rcfg, errors = configparser.config.load()
if errors:
raise error.ParseError("\n\n".join(errors))
root = os.path.expanduser("~")

View File

@ -86,7 +86,7 @@ pub extern "C" fn hgrc_configset_load_system(cfg: *mut ConfigSet) -> *mut Bytes
// Forces datapath to be the empty string as it doesn't
// appear to play a useful role in simply resolving config
// settings for Eden.
errors_to_bytes(cfg.load_system(""))
errors_to_bytes(cfg.load_system())
}
/// Load user config files

View File

@ -9,7 +9,6 @@ use std::cmp::Eq;
use std::collections::{HashMap, HashSet};
use std::env;
use std::hash::Hash;
use std::path::Path;
use bytes::Bytes;
use dirs;
@ -17,9 +16,9 @@ use dirs;
use crate::config::{expand_path, ConfigSet, Options};
use crate::error::Error;
const HGPLAIN: &str = "HGPLAIN";
const HGPLAINEXCEPT: &str = "HGPLAINEXCEPT";
const HGRCPATH: &str = "HGRCPATH";
pub const HGPLAIN: &str = "HGPLAIN";
pub const HGPLAINEXCEPT: &str = "HGPLAINEXCEPT";
pub const HGRCPATH: &str = "HGRCPATH";
pub trait OptionsHgExt {
/// Drop configs according to `$HGPLAIN` and `$HGPLAINEXCEPT`.
@ -45,9 +44,8 @@ pub trait OptionsHgExt {
pub trait ConfigSetHgExt {
/// Load system config files if `$HGRCPATH` is not set.
/// `data_dir` is `mercurial.util.datapath`.
/// Return errors parsing files.
fn load_system<P: AsRef<Path>>(&mut self, data_dir: P) -> Vec<Error>;
fn load_system(&mut self) -> Vec<Error>;
/// Load user config files (and environment variables). If `$HGRCPATH` is
/// set, load files listed in that environment variable instead.
@ -179,15 +177,13 @@ impl OptionsHgExt for Options {
}
impl ConfigSetHgExt for ConfigSet {
fn load_system<P: AsRef<Path>>(&mut self, data_dir: P) -> Vec<Error> {
fn load_system(&mut self) -> Vec<Error> {
let opts = Options::new().source("system").process_hgplain();
let data_dir = data_dir.as_ref();
let mut errors = Vec::new();
if env::var(HGRCPATH).is_err() {
#[cfg(unix)]
{
errors.append(&mut self.load_path(data_dir.join("default.d/mergetools.rc"), &opts));
errors.append(&mut self.load_path("/etc/mercurial/system.rc", &opts));
// TODO(T40519286): Remove this after the tupperware overrides move out of hgrc.d
errors.append(
@ -199,8 +195,8 @@ impl ConfigSetHgExt for ConfigSet {
#[cfg(windows)]
{
errors.append(&mut self.load_path(data_dir.join("default.d/mergetools.rc"), &opts));
if let Ok(program_data_path) = env::var("PROGRAMDATA") {
use std::path::Path;
let hgrc_dir = Path::new(&program_data_path).join("Facebook\\Mercurial");
errors.append(&mut self.load_path(hgrc_dir.join("system.rc"), &opts));
// TODO(quark): Remove this after packages using system.rc are rolled out
@ -591,7 +587,7 @@ mod tests {
let mut cfg = ConfigSet::new();
cfg.load_system("");
cfg.load_system();
assert!(cfg.sections().is_empty());
cfg.load_user();