Esempio n. 1
0
def _guid(_sha1_unused, p4):
    '''
    Branch ID generator that returns GUIDs.
    GUIDs never recur, even across multiple Git Fusion servers, so there's
    never a chance for a collision (which would be bad).
    '''
    return p4gf_util.uuid(p4)
def new_definition(ctx):
    '''
    Factory method to generate an return a new depot branch definition.
    '''
    dbi = DepotBranchInfo()
    dbi.depot_branch_id = p4gf_util.uuid(ctx.p4)
    dbi.root_depot_path = new_depot_branch_root( ctx
                                               , dbi.depot_branch_id )
    dbi.needs_p4add     = True
    return dbi
Esempio n. 3
0
def default_config_repo_for_view_plain(p4, gf_branch_name, view):
    """Construct a ConfigParser using the client-less view.

    Return a ConfigParser instance loaded with default values for a
    single repo, using single view as the view for a single for Git
    branch: master.

    """
    config = default_config_repo(p4, gf_branch_name)
    sec = p4gf_util.uuid(p4)
    config.add_section(sec)
    config.set(sec, KEY_GIT_BRANCH_NAME, VALUE_GIT_BRANCH_NAME)
    config.set(sec, KEY_VIEW, view)
    return config
Esempio n. 4
0
def default_config_repo_for_view_plain(p4, gf_branch_name, view):
    """Construct a ConfigParser using the client-less view.

    Return a ConfigParser instance loaded with default values for a
    single repo, using single view as the view for a single for Git
    branch: master.

    """
    config = default_config_repo(p4, gf_branch_name)
    sec = p4gf_util.uuid(p4)
    config.add_section(sec)
    config.set(sec, KEY_GIT_BRANCH_NAME, VALUE_GIT_BRANCH_NAME)
    config.set(sec, KEY_VIEW, view)
    return config
Esempio n. 5
0
def default_config_repo_for_stream(p4, gf_branch_name, stream_name):
    '''
    Return a ConfigParser instance loaded with default values for a
    single repo, using stream to define the view for a single for Git
    branch: master.
    '''
    config = default_config_repo(p4, gf_branch_name)

    sec = p4gf_util.uuid(p4)
    config.add_section(sec)

    config.set(sec, KEY_GIT_BRANCH_NAME, VALUE_GIT_BRANCH_NAME)
    config.set(sec, KEY_STREAM, stream_name)

    return config
def new_definition(repo_name, *, p4=None, dbid=None):
    """Factory method to generate an return a new depot branch definition.

    :param p4:   Used only for generating counter-driven sequential UUIDs.
                 Optional.

    :param dbid: If you already have a Depot Branch ID that you want to use,
                 supply it here. or leave None and we'll generate one for you.
                 Optional.
    """
    dbi = DepotBranchInfo(dbid or p4gf_util.uuid(p4))
    dbi.root_depot_path = new_depot_branch_root(
        depot_branch_id=dbi.depot_branch_id, repo_name=repo_name)
    dbi.needs_p4add = True
    return dbi
Esempio n. 7
0
def default_config_repo_for_stream(p4, gf_branch_name, stream_name):
    '''
    Return a ConfigParser instance loaded with default values for a
    single repo, using stream to define the view for a single for Git
    branch: master.
    '''
    config = default_config_repo(p4, gf_branch_name)

    sec = p4gf_util.uuid(p4)
    config.add_section(sec)

    config.set(sec, KEY_GIT_BRANCH_NAME, VALUE_GIT_BRANCH_NAME)
    config.set(sec, KEY_STREAM, stream_name)

    return config
Esempio n. 8
0
 def create_ctx(self):
     """
     Connect to Perforce using environment.
     """
     p4 = p4gf_create_p4.create_p4_temp_client(port=self.p4port,
                                               user=self.p4user)
     p4gf_branch.init_case_handling(p4)
     self.repo_name = 'estimate_repo_size_' + p4gf_util.uuid()
     self.repo_config = p4gf_config.RepoConfig.from_local_files(
         self.repo_name, p4, self.config_path, None)
     ctx = p4gf_context.create_context(self.repo_name)
     ctx.p4gf = p4
     ctx.repo_config = self.repo_config
     ctx.config.p4user = self.p4user
     ctx.config.p4port = self.p4port
     ctx.connect()
     return ctx
Esempio n. 9
0
def define_branch_views_for(ctx, depot_branch):
    '''
    Given a depot branch that is not yet mapped into any known Branch view,
    create zero or more Branch views that map this depot_branch into the repo.

    Returns up to one Branch view per fully populated branch. Typically returns
    only one Branch view total unless you have overlapping fully populated
    branch views, or the Depot branch's first changelist holds files that
    straddle multiple locations in the depot.

    Can return empty list if unable to map this Depot branch into the repo,  in
    which case you should shun this Depot branch. Shun this depot branch. Shun
    the mapping of this depot branch. Shun everything, and then shun shunning.

    Returns with any new Branches already assigned branch_ids and inserted into
    ctx.branch_dict().
    '''

    # What files does this branch hold? We'll use them
    # to find intersecting fully populated branches.
    depot_root = depot_branch.root_depot_path
    r = ctx.p4run(['files', '{}/...'.format(depot_root)])
    depot_file_list = [
        x['depotFile'] for x in r if isinstance(x, dict) and 'depotFile' in x
    ]

    fully_populated_branch_list = [
        br for br in ctx.branch_dict().values() if not br.is_lightweight
    ]

    result_list = []
    for br in fully_populated_branch_list:
        br_rerooted = br.copy_rerooted(depot_branch)
        if br_rerooted.intersects_depot_file_list(depot_file_list):
            br_rerooted.branch_id = p4gf_util.uuid(ctx.p4gf)
            br_rerooted.git_branch_name = None
            br_rerooted.is_lightweight = True
            br_rerooted.populated = True
            br_rerooted.depot_branch = depot_branch
            ctx.branch_dict()[br_rerooted.branch_id] = br_rerooted
            result_list.append(br_rerooted)

    return result_list
Esempio n. 10
0
def define_branch_views_for(ctx, depot_branch):
    '''
    Given a depot branch that is not yet mapped into any known Branch view,
    create zero or more Branch views that map this depot_branch into the repo.

    Returns up to one Branch view per fully populated branch. Typically returns
    only one Branch view total unless you have overlapping fully populated
    branch views, or the Depot branch's first changelist holds files that
    straddle multiple locations in the depot.

    Can return empty list if unable to map this Depot branch into the repo,  in
    which case you should shun this Depot branch. Shun this depot branch. Shun
    the mapping of this depot branch. Shun everything, and then shun shunning.

    Returns with any new Branches already assigned branch_ids and inserted into
    ctx.branch_dict().
    '''

    # What files does this branch hold? We'll use them
    # to find intersecting fully populated branches.
    depot_root = depot_branch.root_depot_path
    r = ctx.p4run(['files', '{}/...'.format(depot_root)])
    depot_file_list = [x['depotFile'] for x in r
                       if isinstance(x, dict) and 'depotFile' in x]

    fully_populated_branch_list = [br for br in ctx.branch_dict().values()
                                   if not br.is_lightweight]

    result_list = []
    for br in fully_populated_branch_list:
        br_rerooted = br.copy_rerooted(depot_branch)
        if br_rerooted.intersects_depot_file_list(depot_file_list):
            br_rerooted.branch_id        = p4gf_util.uuid(ctx.p4gf)
            br_rerooted.git_branch_name  = None
            br_rerooted.is_lightweight   = True
            br_rerooted.populated        = True
            br_rerooted.depot_branch     = depot_branch
            ctx.branch_dict()[br_rerooted.branch_id] = br_rerooted
            result_list.append(br_rerooted)

    return result_list
Esempio n. 11
0
 def __init__(self):
     self.name = p4gf_const.P4GF_BRANCH_TEMP_N.format(
         p4gf_util.uuid(p4=None))
     self.written = False
 def __init__(self):
     self.name    = p4gf_const.P4GF_BRANCH_TEMP_N.format(p4gf_util.uuid(p4=None))
     self.written = False
 def __init__(self, p4=None):
     self.name = p4gf_const.P4GF_BRANCH_TEMP_N.format(
         p4gf_util.uuid(p4=p4, namespace="TempP4BranchMapping"))
     self.written = False