OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 the V8 project authors. All rights reserved. |
| 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are |
| 5 # met: |
| 6 # |
| 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following |
| 11 # disclaimer in the documentation and/or other materials provided |
| 12 # with the distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived |
| 15 # from this software without specific prior written permission. |
| 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 28 |
| 29 import re |
| 30 |
| 31 def Strip(f): |
| 32 def new_f(*args, **kwargs): |
| 33 return f(*args, **kwargs).strip() |
| 34 return new_f |
| 35 |
| 36 |
| 37 def MakeArgs(l): |
| 38 """['-a', '', 'abc', ''] -> '-a abc'""" |
| 39 return " ".join(filter(None, l)) |
| 40 |
| 41 |
| 42 def Quoted(s): |
| 43 return "\"%s\"" % s |
| 44 |
| 45 |
| 46 class GitRecipesMixin(object): |
| 47 def GitIsWorkdirClean(self): |
| 48 return self.Git("status -s -uno").strip() == "" |
| 49 |
| 50 @Strip |
| 51 def GitBranch(self): |
| 52 return self.Git("branch") |
| 53 |
| 54 def GitCreateBranch(self, name, branch=""): |
| 55 assert name |
| 56 self.Git(MakeArgs(["checkout -b", name, branch])) |
| 57 |
| 58 def GitDeleteBranch(self, name): |
| 59 assert name |
| 60 self.Git(MakeArgs(["branch -D", name])) |
| 61 |
| 62 def GitCheckout(self, name): |
| 63 assert name |
| 64 self.Git(MakeArgs(["checkout -f", name])) |
| 65 |
| 66 @Strip |
| 67 def GitCurrentBranch(self): |
| 68 for line in self.Git("status -s -b -uno").strip().splitlines(): |
| 69 match = re.match(r"^## (.+)", line) |
| 70 if match: return match.group(1) |
| 71 raise Exception("Couldn't find curent branch.") |
| 72 |
| 73 @Strip |
| 74 def GitLog(self, n=0, format="", grep="", git_hash="", parent_hash="", |
| 75 branch="", reverse=False, patch=False): |
| 76 assert not (git_hash and parent_hash) |
| 77 args = ["log"] |
| 78 if n > 0: |
| 79 args.append("-%d" % n) |
| 80 if format: |
| 81 args.append("--format=%s" % format) |
| 82 if grep: |
| 83 args.append("--grep=\"%s\"" % grep) |
| 84 if reverse: |
| 85 args.append("--reverse") |
| 86 if patch: |
| 87 args.append("-p") |
| 88 if git_hash: |
| 89 args.append(git_hash) |
| 90 if parent_hash: |
| 91 args.append("%s^" % parent_hash) |
| 92 args.append(branch) |
| 93 return self.Git(MakeArgs(args)) |
| 94 |
| 95 def GitAdd(self, name): |
| 96 assert name |
| 97 self.Git(MakeArgs(["add", Quoted(name)])) |
| 98 |
| 99 def GitApplyPatch(self, patch_file, reverse=False): |
| 100 assert patch_file |
| 101 args = ["apply --index --reject"] |
| 102 if reverse: |
| 103 args.append("--reverse") |
| 104 args.append(Quoted(patch_file)) |
| 105 self.Git(MakeArgs(args)) |
| 106 |
| 107 def GitUpload(self, reviewer="", author="", force=False): |
| 108 args = ["cl upload --send-mail"] |
| 109 if author: |
| 110 args += ["--email", Quoted(author)] |
| 111 if reviewer: |
| 112 args += ["-r", Quoted(reviewer)] |
| 113 if force: |
| 114 args.append("-f") |
| 115 # TODO(machenbach): Check output in forced mode. Verify that all required |
| 116 # base files were uploaded, if not retry. |
| 117 self.Git(MakeArgs(args), pipe=False) |
| 118 |
| 119 def GitCommit(self, message="", file_name=""): |
| 120 assert message or file_name |
| 121 args = ["commit"] |
| 122 if file_name: |
| 123 args += ["-aF", Quoted(file_name)] |
| 124 if message: |
| 125 args += ["-am", Quoted(message)] |
| 126 self.Git(MakeArgs(args)) |
| 127 |
| 128 def GitPresubmit(self): |
| 129 self.Git("cl presubmit", "PRESUBMIT_TREE_CHECK=\"skip\"") |
| 130 |
| 131 def GitDCommit(self): |
| 132 self.Git("cl dcommit -f --bypass-hooks", retry_on=lambda x: x is None) |
| 133 |
| 134 def GitDiff(self, loc1, loc2): |
| 135 return self.Git(MakeArgs(["diff", loc1, loc2])) |
| 136 |
| 137 def GitPull(self): |
| 138 self.Git("pull") |
| 139 |
| 140 def GitSVNFetch(self): |
| 141 self.Git("svn fetch") |
| 142 |
| 143 @Strip |
| 144 def GitSVNLog(self): |
| 145 return self.Git("svn log -1 --oneline") |
| 146 |
| 147 @Strip |
| 148 def GitSVNFindGitHash(self, revision, branch=""): |
| 149 assert revision |
| 150 return self.Git(MakeArgs(["svn find-rev", "r%s" % revision, branch])) |
| 151 |
| 152 @Strip |
| 153 def GitSVNFindSVNRev(self, git_hash, branch=""): |
| 154 return self.Git(MakeArgs(["svn find-rev", git_hash, branch])) |
| 155 |
| 156 def GitSVNDCommit(self): |
| 157 return self.Git("svn dcommit 2>&1", retry_on=lambda x: x is None) |
| 158 |
| 159 def GitSVNTag(self, version): |
| 160 self.Git(("svn tag %s -m \"Tagging version %s\"" % (version, version)), |
| 161 retry_on=lambda x: x is None) |
OLD | NEW |