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 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 _valid_depots(self): '''Prohibit remote, spec, and other changelist-impaired depot types.''' # Fetch all known Perforce depots. depot_list = {depot['name']: depot for depot in self.p4.run('depots')} # Scan all configured branches for prohibited depots. # use merged config for this to pick up [@features] branch_dict = p4gf_branch.dict_from_config(self.config_merged, self.p4) valid = True for branch in branch_dict.values(): if not branch.view_p4map: continue v = self._view_valid_depots(depot_list, branch.branch_id, branch.view_p4map) valid = valid and v return valid
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 _valid_depots(self): '''Prohibit remote, spec, and other changelist-impaired depot types.''' # Fetch all known Perforce depots. depot_list = {depot['name']: depot for depot in self.p4.run('depots')} # Scan all configured branches for prohibited depots. # use merged config for this to pick up [@features] branch_dict = p4gf_branch.dict_from_config(self.config_merged, self.p4) valid = True for branch in branch_dict.values(): if not branch.view_p4map: continue v = self._view_valid_depots( depot_list , branch.branch_id , branch.view_p4map) valid = valid and v return valid
Dump test exec args. ''' usage = _( 'Usage: p4gf_branch_id.py <repo-config-file> <git-dir> [ref ...]' '\n' '\nRuns branch-id calculation on the branches defined in' '\nrepo-config-file within the given git directory.' '\nSee debug log for results.') print(usage) exit(1) if __name__ == '__main__': if len(sys.argv) < 3: _test_usage() with p4gf_log.ExceptionLogger(): p4gf_proc.init() _refs = sys.argv[3:] if not _refs: _refs = ['master'] LOG.debug('config={} dir={}\nrefs={}' .format(sys.argv[1], sys.argv[2], _refs)) _anon_branch_func = _counter _config = configparser.ConfigParser() _config.read(sys.argv[1]) _branch_dict = p4gf_branch.dict_from_config(_config) _branch_to_old_head_sha1 = _test_return_none _git_dir = sys.argv[2] _remote_refs = ['refs/heads/' + ref for ref in _refs] _test_dump_all_commits(_branch_dict, _git_dir, _remote_refs)