def list_for_user(p4, user): '''build list of repos visible to user''' result = RepoList() for view in p4gf_util.view_list(p4): #check user permissions for view # PERM_PUSH will avoid checking the repo config file for read-permission-check = user view_perm = p4gf_group.ViewPerm.for_user_and_view( p4, user, view, p4gf_group.PERM_PUSH) #sys.stderr.write("view: {}, user: {}, perm: {}".format(view, user, view_perm)) if view_perm.can_push(): perm = NTR('push') elif view_perm.can_pull(): perm = NTR('pull') else: continue config = p4gf_config.get_repo(p4, view) charset = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_CHARSET, fallback='') desc = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_DESCRIPTION, fallback='') result.repos.append((view, perm, charset, desc)) result.repos.sort(key=lambda tup: tup[0]) return result
def __set_branch_creation(self): """Configure branch creation""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self.branch_creation = config.getboolean( p4gf_config.SECTION_REPO, p4gf_config.KEY_ENABLE_BRANCH_CREATION) LOG.debug('Enable repo branch creation = {0}'.format( self.branch_creation))
def is_feature_enabled(self, feature): ''' Return whether feature is enabled for this repo. Looks in @features section of config, repo first then global. If a feature is not set in config it defaults to not enabled. ''' config = p4gf_config.get_repo(self.p4gf, self.config.view_name) return p4gf_config.is_feature_enabled(config, feature)
def __set_change_owner(self): """Configure change ownership setting""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) value = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_CHANGE_OWNER) value = str(value).lower() if value not in [p4gf_config.VALUE_AUTHOR, p4gf_config.VALUE_PUSHER]: LOG.warn("change-owner config setting has invalid value, defaulting to author") value = p4gf_config.VALUE_AUTHOR self.owner_is_author = True if value == 'author' else False LOG.debug('Set change owner to {0}'.format(value))
def __wrangle_charset(self): """figure out if server is unicode and if it is, set charset""" if not self.p4.server_unicode: return # we have a unicode server # first, always use utf8 for the gf connection # use that connection to fetch the config for the repo self.p4gf.charset = 'utf8' config = p4gf_config.get_repo(self.p4gf, self.config.view_name) # then set the repo-specific charset for their connection self.p4.charset = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_CHARSET) LOG.debug('repo charset will be: '+self.p4.charset)
def _repo_from_stream(p4, view_name, stream_name, client_name, client_root, enable_mismatched_rhs, handle_imports=True): """Create a new client from the named stream. Create a new Perforce client spec <client_name> using existing Perforce stream spec <stream_name> as a template (just use its View). Returns one of the INIT_REPO_* constants. """ # stream_name is the name of a stream, e.g. '//depot/stream' # view_name is the gfinternal repo name if not p4gf_util.spec_exists(p4, 'stream', stream_name): return INIT_REPO_NOVIEW with Validator.from_stream(view_name, p4, stream_name) as validator: if not validator.is_valid(enable_mismatched_rhs): return INIT_REPO_CONFIG_FILE_BAD # Seed a new client using the stream's view as a template. LOG.info("Git Fusion client %s does not exist, creating from existing Perforce stream %s", client_name, stream_name) # Create virtual stream with excluded paths, use that for client. stream = p4.fetch_stream(stream_name) if handle_imports: config = p4gf_config.get_repo(p4, view_name) imports_enabled = p4gf_config.is_feature_enabled(config, p4gf_config.FEATURE_IMPORTS) else: imports_enabled = False if imports_enabled: stream_paths = p4gf_streams.stream_import_exclude(stream['Paths']) else: stream_paths = stream['Paths'] desc = (_("Created by Perforce Git Fusion for work in '{view}'.") .format(view=p4gf_translate.TranslateReponame.repo_to_git(view_name))) spec_values = { 'Owner': p4gf_const.P4GF_USER, 'Parent': stream_name, 'Type': 'virtual', 'Description': desc, 'Options': 'notoparent nofromparent', 'Paths': stream_paths, 'Remapped': ['.gitmodules-{} .gitmodules'.format(view_name)] } if imports_enabled: stream_name += '_p4gfv' p4gf_util.set_spec(p4, 'stream', spec_id=stream_name, values=spec_values) LOG.debug('virtual stream {} created for {}'.format(stream_name, client_name)) create_repo_client(p4, view_name, client_name, client_root, None, stream_name) return INIT_REPO_OK
def _test_write_branch(repo_name, branch, key, value): ''' Unit test hook to see if we actually write the correct values to the correct files. ''' with p4gf_context.create_context(NTR('p4gf_repo'), None) as ctx: config = p4gf_config.get_repo(ctx.p4gf, repo_name) for section in config.sections(): if config.has_option(section, p4gf_config.KEY_GIT_BRANCH_NAME) and \ config.get(section, p4gf_config.KEY_GIT_BRANCH_NAME) == branch: _test_write(repo_name, section, key, value) return print(NTR('branch not found: {}').format(branch))
def __set_change_owner(self): """Configure change ownership setting""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) value = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_CHANGE_OWNER) value = str(value).lower() if value not in [p4gf_config.VALUE_AUTHOR, p4gf_config.VALUE_PUSHER]: LOG.warn( "change-owner config setting has invalid value, defaulting to author" ) value = p4gf_config.VALUE_AUTHOR self.owner_is_author = True if value == 'author' else False LOG.debug('Set change owner to {0}'.format(value))
def __wrangle_charset(self): """figure out if server is unicode and if it is, set charset""" if not self.p4.server_unicode: return # we have a unicode server # first, always use utf8 for the gf connection # use that connection to fetch the config for the repo self.p4gf.charset = 'utf8' config = p4gf_config.get_repo(self.p4gf, self.config.view_name) # then set the repo-specific charset for their connection self.p4.charset = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_CHARSET) LOG.debug('repo charset will be: ' + self.p4.charset)
def _test_write(repo_name, section, key, value): ''' Unit test hook to see if we actually write the correct values to the correct files. ''' if repo_name == 'global': print(NTR('write to global config not implemented.')) return with p4gf_context.create_context(NTR('p4gf_repo'), None) as ctx: config = p4gf_config.get_repo(ctx.p4gf, repo_name) if not config.has_section(section): config.add_section(section) config.set(section, key, value) p4gf_config.write_repo_if(ctx.p4gf, ctx.client_spec_gf, repo_name, config)
def branch_dict(self): """Return all known Git<->Perforce branch associations. Lazy-loaded from config file. Loads DepotBranchInfo dict as a side effect so that we can reconnect Branch.depot_branch pointers. """ if not self._branch_dict: # Load p4gf_config: the fully populated branches. config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self._branch_dict = p4gf_branch.dict_from_config(config, self.p4gf) # First branch listed in p4gf_config becomes our default HEAD. # This is usually 'master', but not required. bsl = p4gf_config.branch_section_list(config) if bsl: self._branch_dict[bsl[0]].more_equal = True # Load the lightweight and stream-based branch config data into the # branch_dict. This is stored in p4gf_config2. For lightweight # branches, the full branch def is there. For stream-based branches # all we care about is the original-view, which gets merged with # any config stored in p4gf_config. config2 = p4gf_config.get_repo2(self.p4gf, self.config.view_name) if config2: branch_dict2 = p4gf_branch.dict_from_config(config2, self.p4gf) lwb_dict = {} for branch in branch_dict2.values(): if branch.stream_name: if branch.branch_id in self._branch_dict: self._branch_dict[branch.branch_id].original_view_lines = \ branch.original_view_lines else: branch.is_lightweight = True if ( branch.depot_branch and isinstance(branch.depot_branch, str)): branch.depot_branch = self.depot_branch_info_index() \ .find_depot_branch_id(branch.depot_branch) lwb_dict[branch.branch_id] = branch self._branch_dict.update(lwb_dict) for b in self._branch_dict.values(): b.set_rhs_client(self.config.p4client) LOG.debug('branch_dict() lazy-loaded ct={}' .format(len(self._branch_dict))) if LOG.isEnabledFor(logging.DEBUG2): for b in self._branch_dict.values(): LOG.debug2('\n' + b.to_log(LOG)) return self._branch_dict
def get_branch_dict(self): """Get a branch dictionary for this repo. If the p4gf_config exists, use that. Else if the p4 client exists create a branch dict containing a branch from the client views. Else return None """ LOG.debug("get_branch_dict for {0}".format(self.view_name)) # Repo config file already checked into Perforce? # Use that. config_path = p4gf_config.depot_path_repo(self.view_name) config_exists = p4gf_util.depot_file_exists(self.p4, config_path) if config_exists: self.config = p4gf_config.get_repo(self.p4, self.view_name) if self.config: return p4gf_branch.dict_from_config(self.config, self.p4) else: return None else: LOG.debug("checking if client {0} exists.".format(self.view_name)) if not p4gf_util.spec_exists(self.p4, 'client', self.view_name): LOG.debug(" client {0} NOT exists.".format( self.view_name)) return None view_lines = p4gf_util.first_value_for_key( self.p4.run('client', '-o', '-t', self.view_name, self.p4client), 'View') if not view_lines: return None else: # create a Branch object to manage this client view if isinstance(view_lines, str): view_lines = view_lines.splitlines() LOG.debug( "create branch from client views: {0}".format(view_lines)) branch = p4gf_branch.Branch() branch.branch_id = 'master' branch.git_branch_name = 'master' branch.view_p4map = P4.Map(view_lines) branch.view_lines = view_lines LOG.debug( "create branch from client branch view_p4map: {0}".format( branch.view_p4map)) LOG.debug( "create branch from client branch view_lines: {0}".format( branch.view_lines)) branch_dict = {} branch_dict[branch.branch_id] = branch return branch_dict
def branch_dict(self): """Return all known Git<->Perforce branch associations. Lazy-loaded from config file. Loads DepotBranchInfo dict as a side effect so that we can reconnect Branch.depot_branch pointers. """ if not self._branch_dict: # Load p4gf_config: the fully populated branches. config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self._branch_dict = p4gf_branch.dict_from_config(config, self.p4gf) # First branch listed in p4gf_config becomes our default HEAD. # This is usually 'master', but not required. bsl = p4gf_config.branch_section_list(config) if bsl: self._branch_dict[bsl[0]].more_equal = True # Load the lightweight and stream-based branch config data into the # branch_dict. This is stored in p4gf_config2. For lightweight # branches, the full branch def is there. For stream-based branches # all we care about is the original-view, which gets merged with # any config stored in p4gf_config. config2 = p4gf_config.get_repo2(self.p4gf, self.config.view_name) if config2: branch_dict2 = p4gf_branch.dict_from_config(config2, self.p4gf) lwb_dict = {} for branch in branch_dict2.values(): if branch.stream_name: if branch.branch_id in self._branch_dict: self._branch_dict[branch.branch_id].original_view_lines = \ branch.original_view_lines else: branch.is_lightweight = True if (branch.depot_branch and isinstance(branch.depot_branch, str)): branch.depot_branch = self.depot_branch_info_index() \ .find_depot_branch_id(branch.depot_branch) lwb_dict[branch.branch_id] = branch self._branch_dict.update(lwb_dict) for b in self._branch_dict.values(): b.set_rhs_client(self.config.p4client) LOG.debug('branch_dict() lazy-loaded ct={}'.format( len(self._branch_dict))) if LOG.isEnabledFor(logging.DEBUG2): for b in self._branch_dict.values(): LOG.debug2('\n' + b.to_log(LOG)) return self._branch_dict
def get_branch_dict(self): """Get a branch dictionary for this repo. If the p4gf_config exists, use that. Else if the p4 client exists create a branch dict containing a branch from the client views. Else return None """ LOG.debug("get_branch_dict for {0}".format(self.view_name)) # Repo config file already checked into Perforce? # Use that. config_path = p4gf_config.depot_path_repo(self.view_name) config_exists = p4gf_util.depot_file_exists(self.p4, config_path) if config_exists: self.config = p4gf_config.get_repo(self.p4, self.view_name) if self.config: return p4gf_branch.dict_from_config(self.config, self.p4) else: return None else: LOG.debug("checking if client {0} exists.".format(self.view_name)) if not p4gf_util.spec_exists(self.p4, 'client', self.view_name): LOG.debug(" client {0} NOT exists.".format(self.view_name)) return None view_lines = p4gf_util.first_value_for_key( self.p4.run('client', '-o', '-t', self.view_name, self.p4client), 'View') if not view_lines: return None else: # create a Branch object to manage this client view if isinstance(view_lines, str): view_lines = view_lines.splitlines() LOG.debug("create branch from client views: {0}".format(view_lines)) branch = p4gf_branch.Branch() branch.branch_id = 'master' branch.git_branch_name = 'master' branch.view_p4map = P4.Map(view_lines) branch.view_lines = view_lines LOG.debug("create branch from client branch view_p4map: {0}". format(branch.view_p4map)) LOG.debug("create branch from client branch view_lines: {0}". format(branch.view_lines)) branch_dict = {} branch_dict[branch.branch_id] = branch return branch_dict
def _test_read(repo_name, section, key): ''' Unit test hook to see if we actually read the correct values from the correct files. ''' with p4gf_context.create_context(NTR('p4gf_repo'), None) as ctx: if repo_name == 'global': config = p4gf_config.get_global(ctx.p4gf) else: config = p4gf_config.get_repo(ctx.p4gf, repo_name) if not config.has_section(section): print(NTR('section not found: {}').format(section)) elif not config.has_option(section, key): print(NTR('option not found: [{section}] {key}') .format(section=section, key=key)) else: value = config.get(section, key) print(value)
def _test_read(repo_name, section, key): ''' Unit test hook to see if we actually read the correct values from the correct files. ''' with p4gf_context.create_context(NTR('p4gf_repo'), None) as ctx: if repo_name == 'global': config = p4gf_config.get_global(ctx.p4gf) else: config = p4gf_config.get_repo(ctx.p4gf, repo_name) if not config.has_section(section): print(NTR('section not found: {}').format(section)) elif not config.has_option(section, key): print( NTR('option not found: [{section}] {key}').format(section=section, key=key)) else: value = config.get(section, key) print(value)
def _submodule_url(ctx): """Retrieve the appropriate repo URL for the given context.""" # Check for a standard HTTP environment variable since I am unaware of # any equivalent for SSH (that is also set by our T4 test suite). using_http = 'REMOTE_ADDR' in os.environ key = p4gf_config.KEY_HTTP_URL if using_http else p4gf_config.KEY_SSH_URL config = p4gf_config.get_repo(ctx.p4gf, ctx.config.view_name) url = config.get(p4gf_config.SECTION_REPO, key, fallback=None) if url is None: LOG.error('Git Fusion configuration missing ssh_url/http_url values.') url = 'http://please/contact/your/perforce/administrator' else: args = {} args['user'] = '******' # fallback value for env_key in ['LOGNAME', 'USER', 'USERNAME']: if env_key in os.environ: args['user'] = os.environ[env_key] break args['host'] = socket.gethostname() args['repo'] = ctx.config.view_name url = url.format(**args) LOG.debug('_submodule_url([{}]/{}) -> {}'.format(p4gf_config.SECTION_REPO, key, url)) return url
def from_context(ctx): ''' Search for a preflight-hook configuration in the current config. Can be specified in repo config or inherited from global config. We neither know nor care. ''' hook = PreflightHook() config = p4gf_config.get_repo(ctx.p4gf, ctx.config.view_name) value = config.get( p4gf_config.SECTION_REPO , p4gf_config.KEY_PREFLIGHT_COMMIT , fallback = '') value_lower = str(value).strip().lower() LOG.debug2('from_context() config {} = {}' .format(p4gf_config.KEY_PREFLIGHT_COMMIT, value)) if re.search(r'none\b', value_lower) or not value_lower: hook.action = ACTION_NONE LOG.debug('from_context() none') return hook elif re.search(r'pass\b', value_lower): hook.action = ACTION_PASS hook.msg = value[4:].strip() LOG.debug('from_context() pass: {}'.format(hook.msg)) return hook elif re.search(r'fail\b', value_lower): hook.action = ACTION_FAIL hook.msg = value[4:].strip() LOG.debug('from_context() fail: {}'.format(hook.msg)) return hook else: hook.action = ACTION_RUN hook.cmd = shlex.split(value) LOG.debug('from_context() cmd : {}'.format(hook.cmd)) return hook
def from_context(ctx): ''' Search for a preflight-hook configuration in the current config. Can be specified in repo config or inherited from global config. We neither know nor care. ''' hook = PreflightHook() config = p4gf_config.get_repo(ctx.p4gf, ctx.config.view_name) value = config.get(p4gf_config.SECTION_REPO, p4gf_config.KEY_PREFLIGHT_COMMIT, fallback='') value_lower = str(value).strip().lower() LOG.debug2('from_context() config {} = {}'.format( p4gf_config.KEY_PREFLIGHT_COMMIT, value)) if re.search(r'none\b', value_lower) or not value_lower: hook.action = ACTION_NONE LOG.debug('from_context() none') return hook elif re.search(r'pass\b', value_lower): hook.action = ACTION_PASS hook.msg = value[4:].strip() LOG.debug('from_context() pass: {}'.format(hook.msg)) return hook elif re.search(r'fail\b', value_lower): hook.action = ACTION_FAIL hook.msg = value[4:].strip() LOG.debug('from_context() fail: {}'.format(hook.msg)) return hook else: hook.action = ACTION_RUN hook.cmd = shlex.split(value) LOG.debug('from_context() cmd : {}'.format(hook.cmd)) return hook
def __set_branch_creation(self): """Configure branch creation""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self.branch_creation = config.getboolean(p4gf_config.SECTION_REPO, p4gf_config.KEY_ENABLE_BRANCH_CREATION) LOG.debug('Enable repo branch creation = {0}'.format(self.branch_creation))
def run_special_command(view, p4, user): """If view is a special command run it and return True; otherwise return False""" # @help: dump contents of help.txt, if file exists if p4gf_const.P4GF_UNREPO_HELP == view: help_text = p4gf_util.read_bin_file('help.txt') if help_text == False: sys.stderr.write(_("file 'help.txt' not found\n")) else: sys.stderr.write(help_text) return True # @info: dump info to stderr if p4gf_const.P4GF_UNREPO_INFO == view: sys.stderr.write(p4gf_version.as_string()) sys.stderr.write(_('Server address: {}\n').format(p4.port)) return True # @list: dump list of repos to stderr if p4gf_const.P4GF_UNREPO_LIST == view: repos = RepoList.list_for_user(p4, user).repos if len(repos): width = max(len(r[0]) for r in repos) sys.stderr.write("\n".join([ "{name:<{width}} {perm} {charset:<10} {desc}".format( width=width, name=p4gf_translate.TranslateReponame.repo_to_git(r[0]), perm=r[1], charset=r[2], desc=r[3]) for r in repos ]) + "\n") else: sys.stderr.write(_('no repositories found\n')) return True if p4gf_const.P4GF_UNREPO_MIRROR_WAIT == view: while p4gf_gitmirror.copying_trees(): sys.stderr.write(_('waiting for mirror..\n')) sys.stderr.flush() time.sleep(1) sys.stderr.write(_('mirror up-to-date\n')) return True if p4gf_const.P4GF_UNREPO_MIRROR_STATUS == view: if p4gf_gitmirror.copying_trees(): sys.stderr.write(_('mirroring trees\n')) else: sys.stderr.write(_('mirror up-to-date\n')) return True # clone @features just gives list of all available features if p4gf_const.P4GF_UNREPO_FEATURES == view: sys.stderr.write(_('Available features:\n')) for k in p4gf_config.configurable_features(): sys.stderr.write("{} : {}\n".format(k, p4gf_config.FEATURE_KEYS[k])) return True # clone @features@repo tells which features are enabled for a repo if view.startswith(p4gf_const.P4GF_UNREPO_FEATURES + '@'): view = view[len(p4gf_const.P4GF_UNREPO_FEATURES) + 1:] sys.stderr.write(_("Enabled features for repo '{}':\n").format(view)) config = p4gf_config.get_repo(p4, view) for k in p4gf_config.configurable_features(): sys.stderr.write("{} : {}\n".format( k, p4gf_config.is_feature_enabled(config, k))) return True # If no previous match and view starts with '@' # then return list of special commands to client - no error if view.startswith('@'): special_cmds = ' '.join(p4gf_const.P4GF_UNREPO) sys.stderr.write( _('Git Fusion: unrecognized special command.\nValid commands are: {}' ) + '\n'.format(special_cmds)) return True return False
def _repo_from_stream(p4, view_name, stream_name, client_name, client_root, enable_mismatched_rhs, handle_imports=True): """Create a new client from the named stream. Create a new Perforce client spec <client_name> using existing Perforce stream spec <stream_name> as a template (just use its View). Returns one of the INIT_REPO_* constants. """ # stream_name is the name of a stream, e.g. '//depot/stream' # view_name is the gfinternal repo name if not p4gf_util.spec_exists(p4, 'stream', stream_name): return INIT_REPO_NOVIEW with Validator.from_stream(view_name, p4, stream_name) as validator: if not validator.is_valid(enable_mismatched_rhs): return INIT_REPO_CONFIG_FILE_BAD # Seed a new client using the stream's view as a template. LOG.info( "Git Fusion client %s does not exist, creating from existing Perforce stream %s", client_name, stream_name) # Create virtual stream with excluded paths, use that for client. stream = p4.fetch_stream(stream_name) if handle_imports: config = p4gf_config.get_repo(p4, view_name) imports_enabled = p4gf_config.is_feature_enabled( config, p4gf_config.FEATURE_IMPORTS) else: imports_enabled = False if imports_enabled: stream_paths = p4gf_streams.stream_import_exclude(stream['Paths']) else: stream_paths = stream['Paths'] desc = (_("Created by Perforce Git Fusion for work in '{view}'.").format( view=p4gf_translate.TranslateReponame.repo_to_git(view_name))) spec_values = { 'Owner': p4gf_const.P4GF_USER, 'Parent': stream_name, 'Type': 'virtual', 'Description': desc, 'Options': 'notoparent nofromparent', 'Paths': stream_paths, 'Remapped': ['.gitmodules-{} .gitmodules'.format(view_name)] } if imports_enabled: stream_name += '_p4gfv' p4gf_util.set_spec(p4, 'stream', spec_id=stream_name, values=spec_values) LOG.debug('virtual stream {} created for {}'.format( stream_name, client_name)) create_repo_client(p4, view_name, client_name, client_root, None, stream_name) return INIT_REPO_OK
def __set_submodules(self): """Configure submodule support""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self.submodules = config.getboolean(p4gf_config.SECTION_REPO, p4gf_config.KEY_ENABLE_SUBMODULES) LOG.debug('Enable repo submodules = {0}'.format(self.submodules))
def __set_merge_commits(self): """Configure merge commits""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self.merge_commits = config.getboolean( p4gf_config.SECTION_REPO, p4gf_config.KEY_ENABLE_MERGE_COMMITS) LOG.debug('Enable repo merge commits = {0}'.format(self.merge_commits))
def run_special_command(view, p4, user): """If view is a special command run it and return True; otherwise return False""" # @help: dump contents of help.txt, if file exists if p4gf_const.P4GF_UNREPO_HELP == view: help_text = p4gf_util.read_bin_file('help.txt') if help_text == False: sys.stderr.write(_("file 'help.txt' not found\n")) else: sys.stderr.write(help_text) return True # @info: dump info to stderr if p4gf_const.P4GF_UNREPO_INFO == view: sys.stderr.write(p4gf_version.as_string()) sys.stderr.write(_('Server address: {}\n').format(p4.port)) return True # @list: dump list of repos to stderr if p4gf_const.P4GF_UNREPO_LIST == view: repos = RepoList.list_for_user(p4, user).repos if len(repos): width = max(len(r[0]) for r in repos) sys.stderr.write("\n".join(["{name:<{width}} {perm} {charset:<10} {desc}".format( width=width, name=p4gf_translate.TranslateReponame.repo_to_git(r[0]), perm=r[1], charset=r[2], desc=r[3]) for r in repos]) + "\n") else: sys.stderr.write(_('no repositories found\n')) return True if p4gf_const.P4GF_UNREPO_MIRROR_WAIT == view: while p4gf_gitmirror.copying_trees(): sys.stderr.write(_('waiting for mirror..\n')) sys.stderr.flush() time.sleep(1) sys.stderr.write(_('mirror up-to-date\n')) return True if p4gf_const.P4GF_UNREPO_MIRROR_STATUS == view: if p4gf_gitmirror.copying_trees(): sys.stderr.write(_('mirroring trees\n')) else: sys.stderr.write(_('mirror up-to-date\n')) return True # clone @features just gives list of all available features if p4gf_const.P4GF_UNREPO_FEATURES == view: sys.stderr.write(_('Available features:\n')) for k in p4gf_config.configurable_features(): sys.stderr.write("{} : {}\n".format(k, p4gf_config.FEATURE_KEYS[k])) return True # clone @features@repo tells which features are enabled for a repo if view.startswith(p4gf_const.P4GF_UNREPO_FEATURES+'@'): view = view[len(p4gf_const.P4GF_UNREPO_FEATURES)+1:] sys.stderr.write(_("Enabled features for repo '{}':\n").format(view)) config = p4gf_config.get_repo(p4, view) for k in p4gf_config.configurable_features(): sys.stderr.write("{} : {}\n" .format(k, p4gf_config.is_feature_enabled(config, k))) return True # If no previous match and view starts with '@' # then return list of special commands to client - no error if view.startswith('@'): special_cmds = ' '.join(p4gf_const.P4GF_UNREPO) sys.stderr.write( _('Git Fusion: unrecognized special command.\nValid commands are: {}') + '\n'. format(special_cmds)) return True return False
def __set_merge_commits(self): """Configure merge commits""" config = p4gf_config.get_repo(self.p4gf, self.config.view_name) self.merge_commits = config.getboolean(p4gf_config.SECTION_REPO, p4gf_config.KEY_ENABLE_MERGE_COMMITS) LOG.debug('Enable repo merge commits = {0}'.format(self.merge_commits))