Example #1
0
def git_p4_sync(options):

    head_tag = git_wrapper.check_head_CL_tag()

    if head_tag == None:
        last_tag = git_wrapper.check_last_CL_tag()
        if last_tag != None:
            print str(git_wrapper.get_commit_distance(last_tag, "HEAD"))+\
                " commits in this branch are not submitted to P4. Aborting p4 sync"
            return False

    p4w = p4_wrapper()
    p4w.load_state()

    #Login
    if not p4w.is_logged():
        (p4port, p4user,
         p4client) = config_wrapper.get_branch_credentials(options.branch)
        res = p4w.p4_login(p4port, p4user, p4client, None)
        if not res:
            print "FATAL: Problem during login. Aborting git p4 sync"
            return False
        else:
            p4w.p4_client_read()

    #parse workspace mapping
    paths = []
    #print p4w._p4config.get_all_properties()
    for depot_path in p4w._p4config._view.iterkeys():
        if depot_path[1] != '-':
            paths.append(depot_path)
    #TODO: map changelist_no -> ws_path must be created to support mulit path commits
    #commit from changelist no
    commit_from_no = None
    commit_to_no = None
    commit_from_val = None

    if options.sync == None:
        commit_from = p4_changelist()
        commit_from_val = git_wrapper.get_last_commit()._descr
        if commit_from_val != None:
            commit_from.from_commit_msg(commit_from_val)
            commit_from_no = commit_from._ch_no
    else:
        commit_from_no = options.sync[0]
        if len(options.sync) == 2:
            commit_to_no = options.sync[1]

    path_changelist_dict = dict()
    for path in paths:
        (res, changelists) = p4w.p4_changelists(path, commit_from_no,
                                                commit_to_no)
        if commit_from_val != None:
            changelists = changelists[1:]
        path_changelist_dict[path] = changelists

    return _git_p4_sync(path_changelist_dict)
Example #2
0
def git_p4_sync(options):
    
    head_tag = git_wrapper.check_head_CL_tag()
    
    if head_tag == None:
        last_tag = git_wrapper.check_last_CL_tag()
        if last_tag != None:
            print str(git_wrapper.get_commit_distance(last_tag, "HEAD"))+\
                " commits in this branch are not submitted to P4. Aborting p4 sync"
            return False
    
    p4w = p4_wrapper()
    p4w.load_state()
    
    #Login
    if not p4w.is_logged():
        (p4port, p4user, p4client) = config_wrapper.get_branch_credentials(options.branch)
        res = p4w.p4_login(p4port, p4user, p4client, None)        
        if not res:
            print "FATAL: Problem during login. Aborting git p4 sync"
            return False
        else:
            p4w.p4_client_read()
    
    #parse workspace mapping
    paths = []
    #print p4w._p4config.get_all_properties()
    for depot_path in p4w._p4config._view.iterkeys():
        if depot_path[1] != '-':
            paths.append(depot_path)
    #TODO: map changelist_no -> ws_path must be created to support mulit path commits
    #commit from changelist no
    commit_from_no = None
    commit_to_no = None
    commit_from_val = None
    
    if options.sync == None:        
        commit_from = p4_changelist()
        commit_from_val = git_wrapper.get_last_commit()._descr
        if commit_from_val != None:
            commit_from.from_commit_msg(commit_from_val)
            commit_from_no = commit_from._ch_no
    else:
        commit_from_no = options.sync[0]
        if len(options.sync) == 2:
            commit_to_no = options.sync[1]    
    
    path_changelist_dict = dict()
    for path in paths:        
        (res, changelists) = p4w.p4_changelists(path, commit_from_no, commit_to_no)
        if commit_from_val != None:
            changelists = changelists[1:]
        path_changelist_dict[path] = changelists
        
    return _git_p4_sync(path_changelist_dict)
Example #3
0
def git_p4_config_write(branch_name, p4config):
    p4w = p4_wrapper()
    
    (p4port, p4user, p4client) = config_wrapper.get_branch_credentials(branch_name)
    p4w.p4_login(p4port, p4user, p4client)
    
    p4config_old = p4w.p4_client_read()
    config_wrapper.set_branch_config(branch_name, p4config)
    p4config_new = config_wrapper.get_branch_config(branch_name)
    p4w.p4_client_write(p4config_new)
    #TODO: add restoring previous config if write was not successfull
    p4w.logout()