Show More
@@ -67,41 +67,6 b" testedwith = b'ships-with-hg-core'" | |||||
67 | cmdtable = {} |
|
67 | cmdtable = {} | |
68 | command = registrar.command(cmdtable) |
|
68 | command = registrar.command(cmdtable) | |
69 |
|
69 | |||
70 | configtable = {} |
|
|||
71 | configitem = registrar.configitem(configtable) |
|
|||
72 |
|
||||
73 | configitem( |
|
|||
74 | b'blackbox', |
|
|||
75 | b'dirty', |
|
|||
76 | default=False, |
|
|||
77 | ) |
|
|||
78 | configitem( |
|
|||
79 | b'blackbox', |
|
|||
80 | b'maxsize', |
|
|||
81 | default=b'1 MB', |
|
|||
82 | ) |
|
|||
83 | configitem( |
|
|||
84 | b'blackbox', |
|
|||
85 | b'logsource', |
|
|||
86 | default=False, |
|
|||
87 | ) |
|
|||
88 | configitem( |
|
|||
89 | b'blackbox', |
|
|||
90 | b'maxfiles', |
|
|||
91 | default=7, |
|
|||
92 | ) |
|
|||
93 | configitem( |
|
|||
94 | b'blackbox', |
|
|||
95 | b'track', |
|
|||
96 | default=lambda: [b'*'], |
|
|||
97 | ) |
|
|||
98 | configitem( |
|
|||
99 | b'blackbox', |
|
|||
100 | b'ignore', |
|
|||
101 | default=lambda: [b'chgserver', b'cmdserver', b'extension'], |
|
|||
102 | ) |
|
|||
103 | configitem(b'blackbox', b'date-format', default=b'') |
|
|||
104 |
|
||||
105 | _lastlogger = loggingutil.proxylogger() |
|
70 | _lastlogger = loggingutil.proxylogger() | |
106 |
|
71 | |||
107 |
|
72 |
@@ -59,6 +59,7 b' class configitem:' | |||||
59 | priority=0, |
|
59 | priority=0, | |
60 | experimental=False, |
|
60 | experimental=False, | |
61 | documentation="", |
|
61 | documentation="", | |
|
62 | in_core_extension=None, | |||
62 | ): |
|
63 | ): | |
63 | self.section = section |
|
64 | self.section = section | |
64 | self.name = name |
|
65 | self.name = name | |
@@ -69,6 +70,7 b' class configitem:' | |||||
69 | self.priority = priority |
|
70 | self.priority = priority | |
70 | self.experimental = experimental |
|
71 | self.experimental = experimental | |
71 | self._re = None |
|
72 | self._re = None | |
|
73 | self.in_core_extension = in_core_extension | |||
72 | if generic: |
|
74 | if generic: | |
73 | self._re = re.compile(self.name) |
|
75 | self._re = re.compile(self.name) | |
74 |
|
76 |
@@ -23,6 +23,7 b'' | |||||
23 | # - alias: list of 2-tuples of strings |
|
23 | # - alias: list of 2-tuples of strings | |
24 | # - experimental: boolean |
|
24 | # - experimental: boolean | |
25 | # - documentation: string |
|
25 | # - documentation: string | |
|
26 | # - in_core_extension: string | |||
26 | # |
|
27 | # | |
27 | # ## Template |
|
28 | # ## Template | |
28 | # |
|
29 | # | |
@@ -2695,6 +2696,8 b' default = true' | |||||
2695 | section = "worker" |
|
2696 | section = "worker" | |
2696 | name = "numcpus" |
|
2697 | name = "numcpus" | |
2697 |
|
2698 | |||
|
2699 | # Templates and template applications | |||
|
2700 | ||||
2698 | [[template-applications]] |
|
2701 | [[template-applications]] | |
2699 | template = "diff-options" |
|
2702 | template = "diff-options" | |
2700 | section = "annotate" |
|
2703 | section = "annotate" | |
@@ -2757,3 +2760,48 b' default = false' | |||||
2757 | suffix = "word-diff" |
|
2760 | suffix = "word-diff" | |
2758 | default = false |
|
2761 | default = false | |
2759 |
|
2762 | |||
|
2763 | # In-core extensions | |||
|
2764 | ||||
|
2765 | [[items]] | |||
|
2766 | section = "blackbox" | |||
|
2767 | name = "dirty" | |||
|
2768 | default = false | |||
|
2769 | in_core_extension = "blackbox" | |||
|
2770 | ||||
|
2771 | [[items]] | |||
|
2772 | section = "blackbox" | |||
|
2773 | name = "maxsize" | |||
|
2774 | default = "1 MB" | |||
|
2775 | in_core_extension = "blackbox" | |||
|
2776 | ||||
|
2777 | [[items]] | |||
|
2778 | section = "blackbox" | |||
|
2779 | name = "logsource" | |||
|
2780 | default = false | |||
|
2781 | in_core_extension = "blackbox" | |||
|
2782 | ||||
|
2783 | [[items]] | |||
|
2784 | section = "blackbox" | |||
|
2785 | name = "maxfiles" | |||
|
2786 | default = 7 | |||
|
2787 | in_core_extension = "blackbox" | |||
|
2788 | ||||
|
2789 | [[items]] | |||
|
2790 | section = "blackbox" | |||
|
2791 | name = "track" | |||
|
2792 | default-type = "lambda" | |||
|
2793 | default = ["*"] | |||
|
2794 | in_core_extension = "blackbox" | |||
|
2795 | ||||
|
2796 | [[items]] | |||
|
2797 | section = "blackbox" | |||
|
2798 | name = "ignore" | |||
|
2799 | default-type = "lambda" | |||
|
2800 | default = ["chgserver", "cmdserver", "extension"] | |||
|
2801 | in_core_extension = "blackbox" | |||
|
2802 | ||||
|
2803 | [[items]] | |||
|
2804 | section = "blackbox" | |||
|
2805 | name = "date-format" | |||
|
2806 | default = "" | |||
|
2807 | in_core_extension = "blackbox" |
@@ -47,6 +47,7 b' from . import (' | |||||
47 | configitems, |
|
47 | configitems, | |
48 | encoding, |
|
48 | encoding, | |
49 | error, |
|
49 | error, | |
|
50 | extensions, | |||
50 | formatter, |
|
51 | formatter, | |
51 | loggingutil, |
|
52 | loggingutil, | |
52 | progress, |
|
53 | progress, | |
@@ -659,6 +660,12 b' class ui:' | |||||
659 | item = self._knownconfig.get(section, {}).get(name) |
|
660 | item = self._knownconfig.get(section, {}).get(name) | |
660 | alternates = [(section, name)] |
|
661 | alternates = [(section, name)] | |
661 |
|
662 | |||
|
663 | if item is not None and item.in_core_extension is not None: | |||
|
664 | # Only return the default for an in-core extension item if said | |||
|
665 | # extension is enabled | |||
|
666 | if item.in_core_extension in extensions.extensions(self): | |||
|
667 | item = None | |||
|
668 | ||||
662 | if item is not None: |
|
669 | if item is not None: | |
663 | alternates.extend(item.alias) |
|
670 | alternates.extend(item.alias) | |
664 | if callable(item.default): |
|
671 | if callable(item.default): |
@@ -40,6 +40,11 b' pub struct DefaultConfigItem {' | |||||
40 | /// The (possibly empty) docstring for the item |
|
40 | /// The (possibly empty) docstring for the item | |
41 | #[serde(default)] |
|
41 | #[serde(default)] | |
42 | documentation: String, |
|
42 | documentation: String, | |
|
43 | /// Whether the item is part of an in-core extension. This allows us to | |||
|
44 | /// hide them if the extension is not enabled, to preserve legacy | |||
|
45 | /// behavior. | |||
|
46 | #[serde(default)] | |||
|
47 | in_core_extension: Option<String>, | |||
43 | } |
|
48 | } | |
44 |
|
49 | |||
45 | /// Corresponds to the raw (i.e. on disk) structure of config items. Used as |
|
50 | /// Corresponds to the raw (i.e. on disk) structure of config items. Used as | |
@@ -61,6 +66,8 b' struct RawDefaultConfigItem {' | |||||
61 | experimental: bool, |
|
66 | experimental: bool, | |
62 | #[serde(default)] |
|
67 | #[serde(default)] | |
63 | documentation: String, |
|
68 | documentation: String, | |
|
69 | #[serde(default)] | |||
|
70 | in_core_extension: Option<String>, | |||
64 | } |
|
71 | } | |
65 |
|
72 | |||
66 | impl TryFrom<RawDefaultConfigItem> for DefaultConfigItem { |
|
73 | impl TryFrom<RawDefaultConfigItem> for DefaultConfigItem { | |
@@ -82,6 +89,7 b' impl TryFrom<RawDefaultConfigItem> for D' | |||||
82 | alias: value.alias, |
|
89 | alias: value.alias, | |
83 | experimental: value.experimental, |
|
90 | experimental: value.experimental, | |
84 | documentation: value.documentation, |
|
91 | documentation: value.documentation, | |
|
92 | in_core_extension: value.in_core_extension, | |||
85 | }) |
|
93 | }) | |
86 | } |
|
94 | } | |
87 | } |
|
95 | } | |
@@ -90,6 +98,14 b' impl DefaultConfigItem {' | |||||
90 | fn is_generic(&self) -> bool { |
|
98 | fn is_generic(&self) -> bool { | |
91 | self.priority.is_some() |
|
99 | self.priority.is_some() | |
92 | } |
|
100 | } | |
|
101 | ||||
|
102 | pub fn in_core_extension(&self) -> Option<&str> { | |||
|
103 | self.in_core_extension.as_deref() | |||
|
104 | } | |||
|
105 | ||||
|
106 | pub fn section(&self) -> &str { | |||
|
107 | self.section.as_ref() | |||
|
108 | } | |||
93 | } |
|
109 | } | |
94 |
|
110 | |||
95 | impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a str> { |
|
111 | impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a str> { | |
@@ -302,6 +318,7 b' impl TemplateItem {' | |||||
302 | alias: self.alias, |
|
318 | alias: self.alias, | |
303 | experimental: self.experimental, |
|
319 | experimental: self.experimental, | |
304 | documentation: self.documentation, |
|
320 | documentation: self.documentation, | |
|
321 | in_core_extension: None, | |||
305 | } |
|
322 | } | |
306 | } |
|
323 | } | |
307 | } |
|
324 | } | |
@@ -596,6 +613,7 b' suffix = "unified"' | |||||
596 | alias: vec![], |
|
613 | alias: vec![], | |
597 | experimental: true, |
|
614 | experimental: true, | |
598 | documentation: "".into(), |
|
615 | documentation: "".into(), | |
|
616 | in_core_extension: None, | |||
599 | }; |
|
617 | }; | |
600 | assert_eq!(config.get(b"censor", b"policy"), Some(&expected)); |
|
618 | assert_eq!(config.get(b"censor", b"policy"), Some(&expected)); | |
601 |
|
619 | |||
@@ -609,6 +627,7 b' suffix = "unified"' | |||||
609 | alias: vec![], |
|
627 | alias: vec![], | |
610 | experimental: false, |
|
628 | experimental: false, | |
611 | documentation: "".into(), |
|
629 | documentation: "".into(), | |
|
630 | in_core_extension: None, | |||
612 | }; |
|
631 | }; | |
613 | assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected)); |
|
632 | assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected)); | |
614 |
|
633 | |||
@@ -621,6 +640,7 b' suffix = "unified"' | |||||
621 | alias: vec![], |
|
640 | alias: vec![], | |
622 | experimental: false, |
|
641 | experimental: false, | |
623 | documentation: "".into(), |
|
642 | documentation: "".into(), | |
|
643 | in_core_extension: None, | |||
624 | }; |
|
644 | }; | |
625 | assert_eq!(config.get(b"alias", b"something"), Some(&expected)); |
|
645 | assert_eq!(config.get(b"alias", b"something"), Some(&expected)); | |
626 |
|
646 | |||
@@ -632,6 +652,7 b' suffix = "unified"' | |||||
632 | alias: vec![], |
|
652 | alias: vec![], | |
633 | experimental: false, |
|
653 | experimental: false, | |
634 | documentation: "".into(), |
|
654 | documentation: "".into(), | |
|
655 | in_core_extension: None, | |||
635 | }; |
|
656 | }; | |
636 | assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected)); |
|
657 | assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected)); | |
637 |
|
658 | |||
@@ -647,6 +668,7 b' suffix = "unified"' | |||||
647 | alias: vec![], |
|
668 | alias: vec![], | |
648 | experimental: false, |
|
669 | experimental: false, | |
649 | documentation: "".into(), |
|
670 | documentation: "".into(), | |
|
671 | in_core_extension: None, | |||
650 | }; |
|
672 | }; | |
651 | assert_eq!(config.get(b"cmdserver", b"track-log"), Some(&expected)); |
|
673 | assert_eq!(config.get(b"cmdserver", b"track-log"), Some(&expected)); | |
652 |
|
674 | |||
@@ -660,6 +682,7 b' suffix = "unified"' | |||||
660 | documentation: |
|
682 | documentation: | |
661 | "This is a docstring.\nThis is another line but this is not." |
|
683 | "This is a docstring.\nThis is another line but this is not." | |
662 | .into(), |
|
684 | .into(), | |
|
685 | in_core_extension: None, | |||
663 | }; |
|
686 | }; | |
664 | assert_eq!( |
|
687 | assert_eq!( | |
665 | config.get(b"command-templates", b"graphnode"), |
|
688 | config.get(b"command-templates", b"graphnode"), |
@@ -373,7 +373,17 b' impl Config {' | |||||
373 | Some("`mercurial/configitems.toml` is not valid".into()), |
|
373 | Some("`mercurial/configitems.toml` is not valid".into()), | |
374 | ) |
|
374 | ) | |
375 | })?; |
|
375 | })?; | |
376 |
|
|
376 | let default_opt = default_config.get(section, item); | |
|
377 | Ok(default_opt.filter(|default| { | |||
|
378 | default | |||
|
379 | .in_core_extension() | |||
|
380 | .map(|extension| { | |||
|
381 | // Only return the default for an in-core extension item | |||
|
382 | // if said extension is enabled | |||
|
383 | self.is_extension_enabled(extension.as_bytes()) | |||
|
384 | }) | |||
|
385 | .unwrap_or(true) | |||
|
386 | })) | |||
377 | } |
|
387 | } | |
378 |
|
388 | |||
379 | fn get_parse<'config, T: 'config>( |
|
389 | fn get_parse<'config, T: 'config>( |
@@ -7,12 +7,6 b' use hg::repo::Repo;' | |||||
7 | use hg::utils::{files::get_bytes_from_os_str, shell_quote}; |
|
7 | use hg::utils::{files::get_bytes_from_os_str, shell_quote}; | |
8 | use std::ffi::OsString; |
|
8 | use std::ffi::OsString; | |
9 |
|
9 | |||
10 | const ONE_MEBIBYTE: u64 = 1 << 20; |
|
|||
11 |
|
||||
12 | // TODO: somehow keep defaults in sync with `configitem` in `hgext/blackbox.py` |
|
|||
13 | const DEFAULT_MAX_SIZE: u64 = ONE_MEBIBYTE; |
|
|||
14 | const DEFAULT_MAX_FILES: u32 = 7; |
|
|||
15 |
|
||||
16 | // Python does not support %.3f, only %f |
|
10 | // Python does not support %.3f, only %f | |
17 | const DEFAULT_DATE_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.3f"; |
|
11 | const DEFAULT_DATE_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.3f"; | |
18 |
|
12 | |||
@@ -62,15 +56,28 b" impl<'a> Blackbox<'a> {" | |||||
62 | max_size: invocation |
|
56 | max_size: invocation | |
63 | .config |
|
57 | .config | |
64 | .get_byte_size(b"blackbox", b"maxsize")? |
|
58 | .get_byte_size(b"blackbox", b"maxsize")? | |
65 |
. |
|
59 | .expect( | |
|
60 | "blackbox.maxsize should have a default value", | |||
|
61 | ), | |||
66 | max_files: invocation |
|
62 | max_files: invocation | |
67 | .config |
|
63 | .config | |
68 | .get_u32(b"blackbox", b"maxfiles")? |
|
64 | .get_u32(b"blackbox", b"maxfiles")? | |
69 |
. |
|
65 | .expect( | |
|
66 | "blackbox.maxfiles should have a default value", | |||
|
67 | ), | |||
70 | date_format: invocation |
|
68 | date_format: invocation | |
71 | .config |
|
69 | .config | |
72 | .get_str(b"blackbox", b"date-format")? |
|
70 | .get_str(b"blackbox", b"date-format")? | |
73 |
. |
|
71 | .map(|f| { | |
|
72 | if f.is_empty() { | |||
|
73 | DEFAULT_DATE_FORMAT | |||
|
74 | } else { | |||
|
75 | f | |||
|
76 | } | |||
|
77 | }) | |||
|
78 | .expect( | |||
|
79 | "blackbox.date-format should have a default value", | |||
|
80 | ), | |||
74 | }) |
|
81 | }) | |
75 | } |
|
82 | } | |
76 | } else { |
|
83 | } else { |
General Comments 0
You need to be logged in to leave comments.
Login now