OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 the V8 project authors. All rights reserved. | 2 # Copyright 2014 the V8 project authors. All rights reserved. |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following | 10 # copyright notice, this list of conditions and the following |
(...skipping 10 matching lines...) Expand all Loading... |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import re | 29 import re |
30 | 30 |
| 31 |
| 32 class GitFailedException(Exception): |
| 33 pass |
| 34 |
| 35 |
31 def Strip(f): | 36 def Strip(f): |
32 def new_f(*args, **kwargs): | 37 def new_f(*args, **kwargs): |
33 return f(*args, **kwargs).strip() | 38 return f(*args, **kwargs).strip() |
34 return new_f | 39 return new_f |
35 | 40 |
36 | 41 |
37 def MakeArgs(l): | 42 def MakeArgs(l): |
38 """['-a', '', 'abc', ''] -> '-a abc'""" | 43 """['-a', '', 'abc', ''] -> '-a abc'""" |
39 return " ".join(filter(None, l)) | 44 return " ".join(filter(None, l)) |
40 | 45 |
(...skipping 11 matching lines...) Expand all Loading... |
52 return self.Git("branch") | 57 return self.Git("branch") |
53 | 58 |
54 def GitCreateBranch(self, name, branch=""): | 59 def GitCreateBranch(self, name, branch=""): |
55 assert name | 60 assert name |
56 self.Git(MakeArgs(["checkout -b", name, branch])) | 61 self.Git(MakeArgs(["checkout -b", name, branch])) |
57 | 62 |
58 def GitDeleteBranch(self, name): | 63 def GitDeleteBranch(self, name): |
59 assert name | 64 assert name |
60 self.Git(MakeArgs(["branch -D", name])) | 65 self.Git(MakeArgs(["branch -D", name])) |
61 | 66 |
| 67 def GitReset(self, name): |
| 68 assert name |
| 69 self.Git(MakeArgs(["reset --hard", name])) |
| 70 |
| 71 def GitRemotes(self): |
| 72 return map(str.strip, self.Git(MakeArgs(["branch -r"])).splitlines()) |
| 73 |
62 def GitCheckout(self, name): | 74 def GitCheckout(self, name): |
63 assert name | 75 assert name |
64 self.Git(MakeArgs(["checkout -f", name])) | 76 self.Git(MakeArgs(["checkout -f", name])) |
65 | 77 |
66 def GitCheckoutFile(self, name, branch_or_hash): | 78 def GitCheckoutFile(self, name, branch_or_hash): |
67 assert name | 79 assert name |
68 assert branch_or_hash | 80 assert branch_or_hash |
69 self.Git(MakeArgs(["checkout -f", branch_or_hash, "--", name])) | 81 self.Git(MakeArgs(["checkout -f", branch_or_hash, "--", name])) |
70 | 82 |
| 83 def GitCheckoutFileSafe(self, name, branch_or_hash): |
| 84 try: |
| 85 self.GitCheckoutFile(name, branch_or_hash) |
| 86 except GitFailedException: # pragma: no cover |
| 87 # The file doesn't exist in that revision. |
| 88 return False |
| 89 return True |
| 90 |
| 91 def GitChangedFiles(self, git_hash): |
| 92 assert git_hash |
| 93 try: |
| 94 files = self.Git(MakeArgs(["diff --name-only", |
| 95 git_hash, |
| 96 "%s^" % git_hash])) |
| 97 return map(str.strip, files.splitlines()) |
| 98 except GitFailedException: # pragma: no cover |
| 99 # Git fails using "^" at branch roots. |
| 100 return [] |
| 101 |
| 102 |
71 @Strip | 103 @Strip |
72 def GitCurrentBranch(self): | 104 def GitCurrentBranch(self): |
73 for line in self.Git("status -s -b -uno").strip().splitlines(): | 105 for line in self.Git("status -s -b -uno").strip().splitlines(): |
74 match = re.match(r"^## (.+)", line) | 106 match = re.match(r"^## (.+)", line) |
75 if match: return match.group(1) | 107 if match: return match.group(1) |
76 raise Exception("Couldn't find curent branch.") # pragma: no cover | 108 raise Exception("Couldn't find curent branch.") # pragma: no cover |
77 | 109 |
78 @Strip | 110 @Strip |
79 def GitLog(self, n=0, format="", grep="", git_hash="", parent_hash="", | 111 def GitLog(self, n=0, format="", grep="", git_hash="", parent_hash="", |
80 branch="", reverse=False): | 112 branch="", reverse=False): |
(...skipping 11 matching lines...) Expand all Loading... |
92 args.append(git_hash) | 124 args.append(git_hash) |
93 if parent_hash: | 125 if parent_hash: |
94 args.append("%s^" % parent_hash) | 126 args.append("%s^" % parent_hash) |
95 args.append(branch) | 127 args.append(branch) |
96 return self.Git(MakeArgs(args)) | 128 return self.Git(MakeArgs(args)) |
97 | 129 |
98 def GitGetPatch(self, git_hash): | 130 def GitGetPatch(self, git_hash): |
99 assert git_hash | 131 assert git_hash |
100 return self.Git(MakeArgs(["log", "-1", "-p", git_hash])) | 132 return self.Git(MakeArgs(["log", "-1", "-p", git_hash])) |
101 | 133 |
| 134 # TODO(machenbach): Unused? Remove. |
102 def GitAdd(self, name): | 135 def GitAdd(self, name): |
103 assert name | 136 assert name |
104 self.Git(MakeArgs(["add", Quoted(name)])) | 137 self.Git(MakeArgs(["add", Quoted(name)])) |
105 | 138 |
106 def GitApplyPatch(self, patch_file, reverse=False): | 139 def GitApplyPatch(self, patch_file, reverse=False): |
107 assert patch_file | 140 assert patch_file |
108 args = ["apply --index --reject"] | 141 args = ["apply --index --reject"] |
109 if reverse: | 142 if reverse: |
110 args.append("--reverse") | 143 args.append("--reverse") |
111 args.append(Quoted(patch_file)) | 144 args.append(Quoted(patch_file)) |
(...skipping 28 matching lines...) Expand all Loading... |
140 | 173 |
141 def GitDiff(self, loc1, loc2): | 174 def GitDiff(self, loc1, loc2): |
142 return self.Git(MakeArgs(["diff", loc1, loc2])) | 175 return self.Git(MakeArgs(["diff", loc1, loc2])) |
143 | 176 |
144 def GitPull(self): | 177 def GitPull(self): |
145 self.Git("pull") | 178 self.Git("pull") |
146 | 179 |
147 def GitSVNFetch(self): | 180 def GitSVNFetch(self): |
148 self.Git("svn fetch") | 181 self.Git("svn fetch") |
149 | 182 |
| 183 # TODO(machenbach): Unused? Remove. |
150 @Strip | 184 @Strip |
151 def GitSVNLog(self): | 185 def GitSVNLog(self): |
152 return self.Git("svn log -1 --oneline") | 186 return self.Git("svn log -1 --oneline") |
153 | 187 |
154 @Strip | 188 @Strip |
155 def GitSVNFindGitHash(self, revision, branch=""): | 189 def GitSVNFindGitHash(self, revision, branch=""): |
156 assert revision | 190 assert revision |
157 return self.Git(MakeArgs(["svn find-rev", "r%s" % revision, branch])) | 191 return self.Git(MakeArgs(["svn find-rev", "r%s" % revision, branch])) |
158 | 192 |
159 @Strip | 193 @Strip |
160 def GitSVNFindSVNRev(self, git_hash, branch=""): | 194 def GitSVNFindSVNRev(self, git_hash, branch=""): |
161 return self.Git(MakeArgs(["svn find-rev", git_hash, branch])) | 195 return self.Git(MakeArgs(["svn find-rev", git_hash, branch])) |
162 | 196 |
163 def GitSVNDCommit(self): | 197 def GitSVNDCommit(self): |
164 return self.Git("svn dcommit 2>&1", retry_on=lambda x: x is None) | 198 return self.Git("svn dcommit 2>&1", retry_on=lambda x: x is None) |
165 | 199 |
166 def GitSVNTag(self, version): | 200 def GitSVNTag(self, version): |
167 self.Git(("svn tag %s -m \"Tagging version %s\"" % (version, version)), | 201 self.Git(("svn tag %s -m \"Tagging version %s\"" % (version, version)), |
168 retry_on=lambda x: x is None) | 202 retry_on=lambda x: x is None) |
OLD | NEW |