Class: MGit::Manifest
- Inherits:
-
Object
- Object
- MGit::Manifest
- Defined in:
- lib/m-git/manifest.rb,
lib/m-git/manifest/linter.rb,
lib/m-git/manifest/internal.rb,
lib/m-git/manifest/light_repo.rb,
lib/m-git/manifest/cache_manager.rb,
lib/m-git/manifest/light_repo_generator.rb
Overview
Sample: ‘m-git/manifest/manifest.sample’
Defined Under Namespace
Modules: Internal, Linter Classes: CacheManager, LightRepo, LightRepoGenerator
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
- String
-
缓存文件路径.
-
#config ⇒ Object
readonly
- Hash
-
配置内容.
-
#config_repo ⇒ Object
readonly
- LightRepo
-
包含配置表的配置仓库.
-
#hash_sha1 ⇒ Object
readonly
- String
-
配置表内容哈希 attr_reader :config_hash.
-
#light_repos ⇒ Object
readonly
- Array<LightRepo>
-
与config中‘repositories’字段对应的Manifest::LightRepo对象数组,包含git仓库和非git仓库.
-
#path ⇒ Object
readonly
- String
-
配置文件路径.
-
#previous_config ⇒ Object
readonly
- Hash
-
上次改动生成的配置缓存.
-
#previous_extra_light_repos ⇒ Object
readonly
- Array<LightRepo>
-
类型同light_repos,表示上次操作,但本次未操作的仓库.
Class Method Summary collapse
-
.generate_light_repos(root, mgit_managed_only: false, only_exist: false, exclude_dummy: false) ⇒ Array<LightRepo>
在mgit根目录中搜索配置文件并根据配置文件生成对应LightRepo对象。.
-
.parse(config_path, strict_mode: true) ⇒ Manifest
全流程校验,除了字段合法性校验外,还包含缓存生成/校验,local配置文件校验/合并.
-
.simple_parse(config_content, strict_mode: true) ⇒ Manifest
简单校验,仅校验配置内容,无缓存生成/校验,无local配置文件校验/合并.
Instance Method Summary collapse
-
#global_config(key) ⇒ Object
获取全局配置.
-
#repo_list(selection: nil, exclusion: nil, all: false) ⇒ Array<LightRepo>
返回所有git仓库列表.
- #terminate!(msg, type: nil) ⇒ Object
-
#update_cache_with_content(root, config_content) ⇒ Object
更新缓存.
-
#update_previous_extra_light_repos(root) ⇒ Object
更新(对比上次操作)冗余的轻量仓库对象.
Methods included from Internal
Methods included from Linter
#lint_light_repos!, #lint_local_manifest_path, #lint_manifest_path, #lint_raw_json!
Instance Attribute Details
#cache_path ⇒ Object (readonly)
- String
-
缓存文件路径
35 36 37 |
# File 'lib/m-git/manifest.rb', line 35 def cache_path @cache_path end |
#config ⇒ Object (readonly)
- Hash
-
配置内容
16 17 18 |
# File 'lib/m-git/manifest.rb', line 16 def config @config end |
#config_repo ⇒ Object (readonly)
- LightRepo
-
包含配置表的配置仓库
29 30 31 |
# File 'lib/m-git/manifest.rb', line 29 def config_repo @config_repo end |
#hash_sha1 ⇒ Object (readonly)
- String
-
配置表内容哈希
attr_reader :config_hash
20 21 22 |
# File 'lib/m-git/manifest.rb', line 20 def hash_sha1 @hash_sha1 end |
#light_repos ⇒ Object (readonly)
- Array<LightRepo>
-
与config中‘repositories’字段对应的Manifest::LightRepo对象数组,包含git仓库和非git仓库
23 24 25 |
# File 'lib/m-git/manifest.rb', line 23 def light_repos @light_repos end |
#path ⇒ Object (readonly)
- String
-
配置文件路径
32 33 34 |
# File 'lib/m-git/manifest.rb', line 32 def path @path end |
#previous_config ⇒ Object (readonly)
- Hash
-
上次改动生成的配置缓存
38 39 40 |
# File 'lib/m-git/manifest.rb', line 38 def previous_config @previous_config end |
#previous_extra_light_repos ⇒ Object (readonly)
- Array<LightRepo>
-
类型同light_repos,表示上次操作,但本次未操作的仓库
26 27 28 |
# File 'lib/m-git/manifest.rb', line 26 def previous_extra_light_repos @previous_extra_light_repos end |
Class Method Details
.generate_light_repos(root, mgit_managed_only: false, only_exist: false, exclude_dummy: false) ⇒ Array<LightRepo>
在mgit根目录中搜索配置文件并根据配置文件生成对应LightRepo对象。
- !!!!!
-
请勿随意修改该接口
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/m-git/manifest.rb', line 54 def self.generate_light_repos(root, mgit_managed_only: false, only_exist:false, exclude_dummy:false) config_path = File.join(root, Constants::PROJECT_DIR[:source_config]) config = self.parse(config_path) if mgit_managed_only repos = config.repo_list elsif exclude_dummy repos = config.light_repos.select { |repo| !repo.dummy } else repos = config.light_repos end if only_exist existing_repos = [] repos.each { |repo| abs_path = repo.abs_dest(root) # 被管理的仓库验证是否是git仓库,不被管理的仓库只验证文件夹是否存在 if (repo.mgit_excluded && Dir.exist?(abs_path)) || (!repo.mgit_excluded && Repo.is_git_repo?(abs_path)) existing_repos.push(repo) end } repos = existing_repos end return repos end |
.parse(config_path, strict_mode: true) ⇒ Manifest
全流程校验,除了字段合法性校验外,还包含缓存生成/校验,local配置文件校验/合并
89 90 91 92 93 |
# File 'lib/m-git/manifest.rb', line 89 def self.parse(config_path, strict_mode:true) config = Manifest.new config.__setup(config_path, strict_mode) return config end |
.simple_parse(config_content, strict_mode: true) ⇒ Manifest
简单校验,仅校验配置内容,无缓存生成/校验,无local配置文件校验/合并
103 104 105 106 107 |
# File 'lib/m-git/manifest.rb', line 103 def self.simple_parse(config_content, strict_mode:true) config = Manifest.new config.__simple_setup(config_content, strict_mode) return config end |
Instance Method Details
#global_config(key) ⇒ Object
获取全局配置
141 142 143 144 145 146 |
# File 'lib/m-git/manifest.rb', line 141 def global_config(key) key_str = Constants::CONFIG_KEY[key] value = config[key_str] terminate!("无法获取多仓库配置必需字段\"#{key}\"的值!") if value.nil? && Constants::REQUIRED_CONFIG_KEY.include?(key_str) value end |
#repo_list(selection: nil, exclusion: nil, all: false) ⇒ Array<LightRepo>
返回所有git仓库列表
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/m-git/manifest.rb', line 120 def repo_list(selection: nil, exclusion: nil, all:false) list = [] light_repos.each { |light_repo| if !light_repo.mgit_excluded || (all && !light_repo.url.nil?) # 选取指定仓库 if (selection.nil? && exclusion.nil?) || (!selection.nil? && selection.is_a?(Array) && selection.any? { |e| e.downcase == light_repo.name.downcase }) || (!exclusion.nil? && exclusion.is_a?(Array) && !exclusion.any? { |e| e.downcase == light_repo.name.downcase }) list.push(light_repo) end end } list end |
#terminate!(msg, type: nil) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/m-git/manifest.rb', line 170 def terminate!(msg, type:nil) if @strict_mode Foundation.help!(msg) else raise Error.new(msg, type:type) end end |
#update_cache_with_content(root, config_content) ⇒ Object
更新缓存
154 155 156 157 158 159 |
# File 'lib/m-git/manifest.rb', line 154 def update_cache_with_content(root, config_content) config_dir = File.join(root, Constants::PROJECT_DIR[:source_config]) cache_path = File.join(config_dir, Constants::CONFIG_FILE_NAME[:manifest_cache]) sha1 = __generate_hash_sha1(config_content.to_json) CacheManager.save_to_cache(cache_path, sha1, config_content) end |
#update_previous_extra_light_repos(root) ⇒ Object
更新(对比上次操作)冗余的轻量仓库对象
165 166 167 168 |
# File 'lib/m-git/manifest.rb', line 165 def update_previous_extra_light_repos(root) cache_path = File.join(root, Constants::PROJECT_DIR[:source_config], Constants::CONFIG_FILE_NAME[:manifest_cache]) __load_cache(cache_path) end |