OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2007 Google Inc. | 3 # Copyright 2007 Google Inc. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 if ":" in self.options.revision: | 1207 if ":" in self.options.revision: |
1208 extra_args = self.options.revision.split(":", 1) + extra_args | 1208 extra_args = self.options.revision.split(":", 1) + extra_args |
1209 else: | 1209 else: |
1210 extra_args = [self.options.revision] + extra_args | 1210 extra_args = [self.options.revision] + extra_args |
1211 | 1211 |
1212 # --no-ext-diff is broken in some versions of Git, so try to work around | 1212 # --no-ext-diff is broken in some versions of Git, so try to work around |
1213 # this by overriding the environment (but there is still a problem if the | 1213 # this by overriding the environment (but there is still a problem if the |
1214 # git config key "diff.external" is used). | 1214 # git config key "diff.external" is used). |
1215 env = os.environ.copy() | 1215 env = os.environ.copy() |
1216 if 'GIT_EXTERNAL_DIFF' in env: del env['GIT_EXTERNAL_DIFF'] | 1216 if 'GIT_EXTERNAL_DIFF' in env: del env['GIT_EXTERNAL_DIFF'] |
1217 return RunShell(["git", "diff", "--no-ext-diff", "--full-index", "-M"] | 1217 # -M/-C will not print the diff for the deleted file when a file is renamed. |
1218 + extra_args, env=env) | 1218 # This is confusing because the original file will not be shown on the |
| 1219 # review when a file is renamed. So first get the diff of all deleted files, |
| 1220 # then the diff of everything except deleted files with rename and copy |
| 1221 # support enabled. |
| 1222 cmd = ["git", "diff", "--no-ext-diff", "--full-index"] |
| 1223 diff = RunShell(cmd + ["--diff-filter=D"] + extra_args, env=env, |
| 1224 silent_ok=True) |
| 1225 diff += RunShell(cmd + ["-C", "--diff-filter=ACMRT"] + extra_args, env=env, |
| 1226 silent_ok=True) |
| 1227 if not diff: |
| 1228 ErrorExit("No output from %s" % (cmd + extra_args)) |
| 1229 return diff |
1219 | 1230 |
1220 def GetUnknownFiles(self): | 1231 def GetUnknownFiles(self): |
1221 status = RunShell(["git", "ls-files", "--exclude-standard", "--others"], | 1232 status = RunShell(["git", "ls-files", "--exclude-standard", "--others"], |
1222 silent_ok=True) | 1233 silent_ok=True) |
1223 return status.splitlines() | 1234 return status.splitlines() |
1224 | 1235 |
1225 def GetFileContent(self, file_hash, is_binary): | 1236 def GetFileContent(self, file_hash, is_binary): |
1226 """Returns the content of a file identified by its git hash.""" | 1237 """Returns the content of a file identified by its git hash.""" |
1227 data, retcode = RunShellWithReturnCode(["git", "show", file_hash], | 1238 data, retcode = RunShellWithReturnCode(["git", "show", file_hash], |
1228 universal_newlines=not is_binary) | 1239 universal_newlines=not is_binary) |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 except OSError, (errno, message): | 1875 except OSError, (errno, message): |
1865 if errno != 2: # ENOENT -- they don't have git installed. | 1876 if errno != 2: # ENOENT -- they don't have git installed. |
1866 raise | 1877 raise |
1867 | 1878 |
1868 # detect CVS repos use `cvs status && $? == 0` rules | 1879 # detect CVS repos use `cvs status && $? == 0` rules |
1869 try: | 1880 try: |
1870 out, returncode = RunShellWithReturnCode(["cvs", "status"]) | 1881 out, returncode = RunShellWithReturnCode(["cvs", "status"]) |
1871 if returncode == 0: | 1882 if returncode == 0: |
1872 return (VCS_CVS, None) | 1883 return (VCS_CVS, None) |
1873 except OSError, (errno, message): | 1884 except OSError, (errno, message): |
1874 if error != 2: | 1885 if errno != 2: |
1875 raise | 1886 raise |
1876 | 1887 |
1877 return (VCS_UNKNOWN, None) | 1888 return (VCS_UNKNOWN, None) |
1878 | 1889 |
1879 | 1890 |
1880 def GuessVCS(options): | 1891 def GuessVCS(options): |
1881 """Helper to guess the version control system. | 1892 """Helper to guess the version control system. |
1882 | 1893 |
1883 This verifies any user-specified VersionControlSystem (by command line | 1894 This verifies any user-specified VersionControlSystem (by command line |
1884 or environment variable). If the user didn't specify one, this examines | 1895 or environment variable). If the user didn't specify one, this examines |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 try: | 2212 try: |
2202 RealMain(sys.argv) | 2213 RealMain(sys.argv) |
2203 except KeyboardInterrupt: | 2214 except KeyboardInterrupt: |
2204 print | 2215 print |
2205 StatusUpdate("Interrupted.") | 2216 StatusUpdate("Interrupted.") |
2206 sys.exit(1) | 2217 sys.exit(1) |
2207 | 2218 |
2208 | 2219 |
2209 if __name__ == "__main__": | 2220 if __name__ == "__main__": |
2210 main() | 2221 main() |
OLD | NEW |