This repository was archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgitp4.py
More file actions
101 lines (70 loc) · 2.46 KB
/
gitp4.py
File metadata and controls
101 lines (70 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
from random import randint
def p4_client_path():
return "/d/s/"
def p4_resolve_path(name):
return os.path.normpath(p4_client_path() + name)
def strip_crlf(string):
""" Utility function to remove EOL """
return ''.join(string.splitlines())
def split_by_space(string):
""" Returns a string splitted by space as a tuple """
return tuple(string.split())
def get_commits_since(start_commit_hash, end_commit_hash="HEAD"):
"""
It returns commit hashes of series of commits which happened between
the two specified commits.
"""
command = "git log %s..%s --format=%%h" % \
(start_commit_hash, end_commit_hash)
commits = []
for commit_hash in os.popen(command):
commits.append(strip_crlf(commit_hash))
return commits[::-1]
def get_commits_name_status(commit_hash):
"""
"""
names_status = []
command = "git diff-tree --no-commit-id --name-status -r %s" % \
(commit_hash)
for ns in os.popen(command):
names_status.append(split_by_space(ns))
return names_status
def p4_start_changelist():
cl = randint(5681, 7898)
print "Starting a change list: %s " % cl
return cl
def p4_commit_changelist(change_list):
print "Commiting the changelist: %s" % change_list
pass
def p4_file_modified(name, change_list):
command = "p4 edit %s" % p4_resolve_path(name)
print "Checking out the file %s and copying it over" % name
print command
os.popen(command)
def p4_file_added(name, change_list):
print "Adding the file %s and copying it over" % name
pass
def p4_file_deleted(name, change_list):
print "Removing the file %s and copying it over" % name
pass
def process_by_status(status, name, cl):
if "M" == status.upper():
p4_file_modified(name, cl)
elif "A" == status.upper():
p4_file_added(name, cl)
elif "D" == status.upper():
p4_file_deleted(name, cl)
else:
raise Exception("Invalid Status: %s:%s" % (status, name))
def process_commits(start_commit_hash):
for commit in get_commits_since(start_commit_hash):
cl = p4_start_changelist()
for (status, name) in get_commits_name_status(commit):
process_by_status(status, name, cl)
print "Had the file: %s , %s" % (status, name)
p4_commit_changelist(cl)
# print get_commits_since("0817e51")
# print get_commits_name_status("0817e51")
# print get_commits_since("68b8a52")
process_commits("0817e51")