OLD | NEW |
1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 command, self.scm_name)) | 108 command, self.scm_name)) |
109 | 109 |
110 return getattr(self, command)(options, args, file_list) | 110 return getattr(self, command)(options, args, file_list) |
111 | 111 |
112 | 112 |
113 class GitWrapper(SCMWrapper, scm.GIT): | 113 class GitWrapper(SCMWrapper, scm.GIT): |
114 """Wrapper for Git""" | 114 """Wrapper for Git""" |
115 | 115 |
116 def cleanup(self, options, args, file_list): | 116 def cleanup(self, options, args, file_list): |
117 """Cleanup working copy.""" | 117 """Cleanup working copy.""" |
118 __pychecker__ = 'unusednames=args,file_list,options' | 118 __pychecker__ = 'unusednames=options,args,file_list' |
119 self._Run(['prune'], redirect_stdout=False) | 119 self._Run(['prune'], redirect_stdout=False) |
120 self._Run(['fsck'], redirect_stdout=False) | 120 self._Run(['fsck'], redirect_stdout=False) |
121 self._Run(['gc'], redirect_stdout=False) | 121 self._Run(['gc'], redirect_stdout=False) |
122 | 122 |
123 def diff(self, options, args, file_list): | 123 def diff(self, options, args, file_list): |
124 __pychecker__ = 'unusednames=args,file_list,options' | 124 __pychecker__ = 'unusednames=options,args,file_list' |
125 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) | 125 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
126 self._Run(['diff', merge_base], redirect_stdout=False) | 126 self._Run(['diff', merge_base], redirect_stdout=False) |
127 | 127 |
128 def export(self, options, args, file_list): | 128 def export(self, options, args, file_list): |
129 """Export a clean directory tree into the given path. | 129 """Export a clean directory tree into the given path. |
130 | 130 |
131 Exports into the specified directory, creating the path if it does | 131 Exports into the specified directory, creating the path if it does |
132 already exist. | 132 already exist. |
133 """ | 133 """ |
134 __pychecker__ = 'unusednames=file_list,options' | 134 __pychecker__ = 'unusednames=options,file_list' |
135 assert len(args) == 1 | 135 assert len(args) == 1 |
136 export_path = os.path.abspath(os.path.join(args[0], self.relpath)) | 136 export_path = os.path.abspath(os.path.join(args[0], self.relpath)) |
137 if not os.path.exists(export_path): | 137 if not os.path.exists(export_path): |
138 os.makedirs(export_path) | 138 os.makedirs(export_path) |
139 self._Run(['checkout-index', '-a', '--prefix=%s/' % export_path], | 139 self._Run(['checkout-index', '-a', '--prefix=%s/' % export_path], |
140 redirect_stdout=False) | 140 redirect_stdout=False) |
141 | 141 |
142 def pack(self, options, args, file_list): | 142 def pack(self, options, args, file_list): |
143 """Generates a patch file which can be applied to the root of the | 143 """Generates a patch file which can be applied to the root of the |
144 repository. | 144 repository. |
145 | 145 |
146 The patch file is generated from a diff of the merge base of HEAD and | 146 The patch file is generated from a diff of the merge base of HEAD and |
147 its upstream branch. | 147 its upstream branch. |
148 """ | 148 """ |
149 __pychecker__ = 'unusednames=file_list,options' | 149 __pychecker__ = 'unusednames=options,file_list' |
150 path = os.path.join(self._root_dir, self.relpath) | 150 path = os.path.join(self._root_dir, self.relpath) |
151 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) | 151 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
152 command = ['diff', merge_base] | 152 command = ['diff', merge_base] |
153 filterer = DiffFilterer(self.relpath) | 153 filterer = DiffFilterer(self.relpath) |
154 self.RunAndFilterOutput(command, path, False, False, filterer.Filter) | 154 self.RunAndFilterOutput(command, path, False, False, filterer.Filter) |
155 | 155 |
156 def update(self, options, args, file_list): | 156 def update(self, options, args, file_list): |
157 """Runs git to update or transparently checkout the working copy. | 157 """Runs git to update or transparently checkout the working copy. |
158 | 158 |
159 All updated files will be appended to file_list. | 159 All updated files will be appended to file_list. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 print("\n_____ %s is missing, synching instead" % self.relpath) | 239 print("\n_____ %s is missing, synching instead" % self.relpath) |
240 # Don't reuse the args. | 240 # Don't reuse the args. |
241 return self.update(options, [], file_list) | 241 return self.update(options, [], file_list) |
242 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) | 242 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
243 files = self._Run(['diff', merge_base, '--name-only']).split() | 243 files = self._Run(['diff', merge_base, '--name-only']).split() |
244 self._Run(['reset', '--hard', merge_base], redirect_stdout=False) | 244 self._Run(['reset', '--hard', merge_base], redirect_stdout=False) |
245 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 245 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
246 | 246 |
247 def revinfo(self, options, args, file_list): | 247 def revinfo(self, options, args, file_list): |
248 """Display revision""" | 248 """Display revision""" |
249 __pychecker__ = 'unusednames=args,file_list,options' | 249 __pychecker__ = 'unusednames=options,args,file_list' |
250 return self._Run(['rev-parse', 'HEAD']) | 250 return self._Run(['rev-parse', 'HEAD']) |
251 | 251 |
252 def runhooks(self, options, args, file_list): | 252 def runhooks(self, options, args, file_list): |
253 self.status(options, args, file_list) | 253 self.status(options, args, file_list) |
254 | 254 |
255 def status(self, options, args, file_list): | 255 def status(self, options, args, file_list): |
256 """Display status information.""" | 256 """Display status information.""" |
257 __pychecker__ = 'unusednames=args,options' | 257 __pychecker__ = 'unusednames=options,args' |
258 if not os.path.isdir(self.checkout_path): | 258 if not os.path.isdir(self.checkout_path): |
259 print('\n________ couldn\'t run status in %s:\nThe directory ' | 259 print('\n________ couldn\'t run status in %s:\nThe directory ' |
260 'does not exist.' % self.checkout_path) | 260 'does not exist.' % self.checkout_path) |
261 else: | 261 else: |
262 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) | 262 merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
263 self._Run(['diff', '--name-status', merge_base], redirect_stdout=False) | 263 self._Run(['diff', '--name-status', merge_base], redirect_stdout=False) |
264 files = self._Run(['diff', '--name-only', merge_base]).split() | 264 files = self._Run(['diff', '--name-only', merge_base]).split() |
265 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 265 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
266 | 266 |
267 def FullUrlForRelativeUrl(self, url): | 267 def FullUrlForRelativeUrl(self, url): |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " | 547 print("\n________ couldn't run \'%s\' in \'%s\':\nThe directory " |
548 "does not exist." | 548 "does not exist." |
549 % (' '.join(command), path)) | 549 % (' '.join(command), path)) |
550 # There's no file list to retrieve. | 550 # There's no file list to retrieve. |
551 else: | 551 else: |
552 self.RunAndGetFileList(options, command, path, file_list) | 552 self.RunAndGetFileList(options, command, path, file_list) |
553 | 553 |
554 def FullUrlForRelativeUrl(self, url): | 554 def FullUrlForRelativeUrl(self, url): |
555 # Find the forth '/' and strip from there. A bit hackish. | 555 # Find the forth '/' and strip from there. A bit hackish. |
556 return '/'.join(self.url.split('/')[:4]) + url | 556 return '/'.join(self.url.split('/')[:4]) + url |
OLD | NEW |