##// END OF EJS Templates
configitems: move blackbox's config items to the new configitems.toml...
Raphaël Gomès -
r51658:7f8f6fe1 default
parent child Browse files
Show More
@@ -67,41 +67,6 b" testedwith = b'ships-with-hg-core'"
67 67 cmdtable = {}
68 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 70 _lastlogger = loggingutil.proxylogger()
106 71
107 72
@@ -59,6 +59,7 b' class configitem:'
59 59 priority=0,
60 60 experimental=False,
61 61 documentation="",
62 in_core_extension=None,
62 63 ):
63 64 self.section = section
64 65 self.name = name
@@ -69,6 +70,7 b' class configitem:'
69 70 self.priority = priority
70 71 self.experimental = experimental
71 72 self._re = None
73 self.in_core_extension = in_core_extension
72 74 if generic:
73 75 self._re = re.compile(self.name)
74 76
@@ -23,6 +23,7 b''
23 23 # - alias: list of 2-tuples of strings
24 24 # - experimental: boolean
25 25 # - documentation: string
26 # - in_core_extension: string
26 27 #
27 28 # ## Template
28 29 #
@@ -2695,6 +2696,8 b' default = true'
2695 2696 section = "worker"
2696 2697 name = "numcpus"
2697 2698
2699 # Templates and template applications
2700
2698 2701 [[template-applications]]
2699 2702 template = "diff-options"
2700 2703 section = "annotate"
@@ -2757,3 +2760,48 b' default = false'
2757 2760 suffix = "word-diff"
2758 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 47 configitems,
48 48 encoding,
49 49 error,
50 extensions,
50 51 formatter,
51 52 loggingutil,
52 53 progress,
@@ -659,6 +660,12 b' class ui:'
659 660 item = self._knownconfig.get(section, {}).get(name)
660 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 669 if item is not None:
663 670 alternates.extend(item.alias)
664 671 if callable(item.default):
@@ -40,6 +40,11 b' pub struct DefaultConfigItem {'
40 40 /// The (possibly empty) docstring for the item
41 41 #[serde(default)]
42 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 50 /// Corresponds to the raw (i.e. on disk) structure of config items. Used as
@@ -61,6 +66,8 b' struct RawDefaultConfigItem {'
61 66 experimental: bool,
62 67 #[serde(default)]
63 68 documentation: String,
69 #[serde(default)]
70 in_core_extension: Option<String>,
64 71 }
65 72
66 73 impl TryFrom<RawDefaultConfigItem> for DefaultConfigItem {
@@ -82,6 +89,7 b' impl TryFrom<RawDefaultConfigItem> for D'
82 89 alias: value.alias,
83 90 experimental: value.experimental,
84 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 98 fn is_generic(&self) -> bool {
91 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 111 impl<'a> TryFrom<&'a DefaultConfigItem> for Option<&'a str> {
@@ -302,6 +318,7 b' impl TemplateItem {'
302 318 alias: self.alias,
303 319 experimental: self.experimental,
304 320 documentation: self.documentation,
321 in_core_extension: None,
305 322 }
306 323 }
307 324 }
@@ -596,6 +613,7 b' suffix = "unified"'
596 613 alias: vec![],
597 614 experimental: true,
598 615 documentation: "".into(),
616 in_core_extension: None,
599 617 };
600 618 assert_eq!(config.get(b"censor", b"policy"), Some(&expected));
601 619
@@ -609,6 +627,7 b' suffix = "unified"'
609 627 alias: vec![],
610 628 experimental: false,
611 629 documentation: "".into(),
630 in_core_extension: None,
612 631 };
613 632 assert_eq!(config.get(b"alias", b"abcdsomething"), Some(&expected));
614 633
@@ -621,6 +640,7 b' suffix = "unified"'
621 640 alias: vec![],
622 641 experimental: false,
623 642 documentation: "".into(),
643 in_core_extension: None,
624 644 };
625 645 assert_eq!(config.get(b"alias", b"something"), Some(&expected));
626 646
@@ -632,6 +652,7 b' suffix = "unified"'
632 652 alias: vec![],
633 653 experimental: false,
634 654 documentation: "".into(),
655 in_core_extension: None,
635 656 };
636 657 assert_eq!(config.get(b"chgserver", b"idletimeout"), Some(&expected));
637 658
@@ -647,6 +668,7 b' suffix = "unified"'
647 668 alias: vec![],
648 669 experimental: false,
649 670 documentation: "".into(),
671 in_core_extension: None,
650 672 };
651 673 assert_eq!(config.get(b"cmdserver", b"track-log"), Some(&expected));
652 674
@@ -660,6 +682,7 b' suffix = "unified"'
660 682 documentation:
661 683 "This is a docstring.\nThis is another line but this is not."
662 684 .into(),
685 in_core_extension: None,
663 686 };
664 687 assert_eq!(
665 688 config.get(b"command-templates", b"graphnode"),
@@ -373,7 +373,17 b' impl Config {'
373 373 Some("`mercurial/configitems.toml` is not valid".into()),
374 374 )
375 375 })?;
376 Ok(default_config.get(section, item))
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 389 fn get_parse<'config, T: 'config>(
@@ -7,12 +7,6 b' use hg::repo::Repo;'
7 7 use hg::utils::{files::get_bytes_from_os_str, shell_quote};
8 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 10 // Python does not support %.3f, only %f
17 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 56 max_size: invocation
63 57 .config
64 58 .get_byte_size(b"blackbox", b"maxsize")?
65 .unwrap_or(DEFAULT_MAX_SIZE),
59 .expect(
60 "blackbox.maxsize should have a default value",
61 ),
66 62 max_files: invocation
67 63 .config
68 64 .get_u32(b"blackbox", b"maxfiles")?
69 .unwrap_or(DEFAULT_MAX_FILES),
65 .expect(
66 "blackbox.maxfiles should have a default value",
67 ),
70 68 date_format: invocation
71 69 .config
72 70 .get_str(b"blackbox", b"date-format")?
73 .unwrap_or(DEFAULT_DATE_FORMAT),
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 83 } else {
General Comments 0
You need to be logged in to leave comments. Login now