def git_p4_init(options): p4w = p4_wrapper() #Login to workspace p4w.p4_login(options.port, options.user, options.client, options.passwd) #Read client spec (res, p4conf) = p4w.p4_client_read() p4w.save_state() if not res: return #Add client to config config_wrapper.new_branch_config(options.branch, p4conf) #change root & write client config to p4 & config file new_root = "" if options.root == None: new_root = git_wrapper.get_topdir()+"/.git/p4repo_"+options.branch os.mkdir(new_root) else: new_root = options.root p4conf._root = new_root p4w.p4_client_write(p4conf) p4conf._port = options.port p4conf._user = options.user p4conf._passwd = options.passwd config_wrapper.set_branch_config(options.branch, p4conf) if options.nosync != True: git_p4_sync(options) else: print "Initialized empty git-p4 repository" #TODO: set p4 head p4w.p4_logout()
def test_files(): p4w = p4_wrapper() res = p4w.p4_login(p4port, p4user, p4client, p4passwd) if not res: return False (res, files_all) = p4w.p4_files() if len(files_all) == 0: print "ERROR: Getting all files failed" return False (res, files_ch1) = p4w.p4_files(None, None, "1") if len(files_ch1) != 1: print "ERROR: Getting files from changelist no 1 failed" return False (res, files_ch2) = p4w.p4_files(None, "1", "2") if len(files_ch2) != 2: print "ERROR: Getting files from changelists no 1-2 failed" return False (res, files_ch3) = p4w.p4_files(None, "2", None) if len(files_ch3) != 3: print "ERROR: Getting files from changelists no 2-now failed" return False res = p4w.p4_logout() return res
def test_client_read_write(): p4w = p4_wrapper() res = p4w.p4_login(p4port, p4user, p4client, p4passwd) if not res: return res (res, p4conf) = p4w.p4_client_read() if res == False or p4conf == None: print "ERROR: p4_client_read failed" p4w.p4_logout() return False old_descr = p4conf._description p4conf._description = "New descr" p4w.p4_client_write(p4conf) (res, p4conf) = p4w.p4_client_read() if p4conf._description != "New descr\n": print "ERROR: Description has not changed (1st)" res = p4w.p4_logout() return False p4conf._description = old_descr p4w.p4_client_write(p4conf) (res, p4conf) = p4w.p4_client_read() if p4conf._description != old_descr: print "ERROR: Description has not changed (2st)" res = p4w.p4_logout() return False res = p4w.p4_logout() return res
def git_p4_init(options): p4w = p4_wrapper() #Login to workspace p4w.p4_login(options.port, options.user, options.client, options.passwd) #Read client spec (res, p4conf) = p4w.p4_client_read() p4w.save_state() if not res: return #Add client to config config_wrapper.new_branch_config(options.branch, p4conf) #change root & write client config to p4 & config file new_root = "" if options.root == None: new_root = git_wrapper.get_topdir() + "/.git/p4repo_" + options.branch os.mkdir(new_root) else: new_root = options.root p4conf._root = new_root p4w.p4_client_write(p4conf) p4conf._port = options.port p4conf._user = options.user p4conf._passwd = options.passwd config_wrapper.set_branch_config(options.branch, p4conf) if options.nosync != True: git_p4_sync(options) else: print "Initialized empty git-p4 repository" #TODO: set p4 head p4w.p4_logout()
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)
def test_sync(): p4w = p4_wrapper() res = p4w.p4_login(p4port, p4user, p4client, p4passwd) if not res: return False (res, file_list) = p4w.p4_sync(None, '1', True, True, 0) (res, file_list) = p4w.p4_sync(None, '2', True, True, 0) (res, file_list) = p4w.p4_sync(None, 2, True, True, 0) (res, file_list) = p4w.p4_sync(None, '#head', True, True, 0) return res
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()
def test_changelists(): p4w = p4_wrapper() res = p4w.p4_login(p4port, p4user, p4client, p4passwd) if not res: return False (res, changes_all) = p4w.p4_changelists() if len(changes_all) == 0: print "ERROR: Getting all changelists failed" return False #TODO: add more tests for various cases res = p4w.p4_logout() return res
def _git_p4_sync_one(path, changelist, file_count): p4w = p4_wrapper() p4w.load_state() if not p4w.is_logged(): return False #TODO: for now track_progress if false (res, filelist) = p4w.p4_sync(path, changelist._ch_no, True, False, file_count) if not res: return False command = "" git_topdir = git_wrapper.get_topdir() os.chdir(p4w._p4config._root) print os.getcwd() for synced_file in filelist: if synced_file._action == "add" or synced_file._action == "edit": command = "cp --parents -f " + p4w.strip_p4root( synced_file._real_path)[1:] + " " + git_topdir elif synced_file._action == "delete": command = "rm -f " + git_topdir + p4w.strip_p4root( synced_file._real_path) #TODO: add removing empty dirs after this cp_proc = subprocess.Popen(command, stdout=None, stderr=None, shell=True) print command cp_proc.communicate() #TODO: add cp process tracker os.chdir(git_topdir) ret = git_wrapper.add_all_changes() if ret != 0: return False ret = git_wrapper.commit(changelist) if ret != 0: return False ret = git_wrapper.tag_CL(path, changelist) return not bool(ret)
def _git_p4_sync_one(path, changelist, file_count): p4w = p4_wrapper() p4w.load_state() if not p4w.is_logged(): return False #TODO: for now track_progress if false (res, filelist) = p4w.p4_sync(path, changelist._ch_no, True, False, file_count) if not res: return False command = "" git_topdir = git_wrapper.get_topdir() os.chdir(p4w._p4config._root) print os.getcwd() for synced_file in filelist: if synced_file._action == "add" or synced_file._action == "edit": command = "cp --parents -f "+p4w.strip_p4root(synced_file._real_path)[1:]+" "+git_topdir elif synced_file._action == "delete": command = "rm -f "+git_topdir+p4w.strip_p4root(synced_file._real_path) #TODO: add removing empty dirs after this cp_proc = subprocess.Popen(command, stdout=None, stderr=None, shell=True) print command cp_proc.communicate() #TODO: add cp process tracker os.chdir(git_topdir) ret = git_wrapper.add_all_changes() if ret != 0: return False ret = git_wrapper.commit(changelist) if ret != 0: return False ret = git_wrapper.tag_CL(path, changelist) return not bool(ret)
def test_logging(): p4w = p4_wrapper() res = p4w.p4_login(p4port, p4user, p4client, p4passwd) if res: res = p4w.p4_logout() return res