Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: gclient_scm.py

Issue 362008: gclient: Make revinfo work on git. (Closed)
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2009 Google Inc. All Rights Reserved. 1 # Copyright 2009 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 def FullUrlForRelativeUrl(self, url): 72 def FullUrlForRelativeUrl(self, url):
73 # Find the forth '/' and strip from there. A bit hackish. 73 # Find the forth '/' and strip from there. A bit hackish.
74 return '/'.join(self.url.split('/')[:4]) + url 74 return '/'.join(self.url.split('/')[:4]) + url
75 75
76 def RunCommand(self, command, options, args, file_list=None): 76 def RunCommand(self, command, options, args, file_list=None):
77 # file_list will have all files that are modified appended to it. 77 # file_list will have all files that are modified appended to it.
78 if file_list is None: 78 if file_list is None:
79 file_list = [] 79 file_list = []
80 80
81 commands = ['cleanup', 'export', 'update', 'revert', 81 commands = ['cleanup', 'export', 'update', 'revert', 'revinfo',
82 'status', 'diff', 'pack', 'runhooks'] 82 'status', 'diff', 'pack', 'runhooks']
83 83
84 if not command in commands: 84 if not command in commands:
85 raise gclient_utils.Error('Unknown command %s' % command) 85 raise gclient_utils.Error('Unknown command %s' % command)
86 86
87 if not command in dir(self): 87 if not command in dir(self):
88 raise gclient_utils.Error('Command %s not implemnted in %s wrapper' % ( 88 raise gclient_utils.Error('Command %s not implemnted in %s wrapper' % (
89 command, self.scm_name)) 89 command, self.scm_name))
90 90
91 return getattr(self, command)(options, args, file_list) 91 return getattr(self, command)(options, args, file_list)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 # revert won't work if the directory doesn't exist. It needs to 160 # revert won't work if the directory doesn't exist. It needs to
161 # checkout instead. 161 # checkout instead.
162 print("\n_____ %s is missing, synching instead" % self.relpath) 162 print("\n_____ %s is missing, synching instead" % self.relpath)
163 # Don't reuse the args. 163 # Don't reuse the args.
164 return self.update(options, [], file_list) 164 return self.update(options, [], file_list)
165 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) 165 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin'])
166 files = self._RunGit(['diff', merge_base, '--name-only']).split() 166 files = self._RunGit(['diff', merge_base, '--name-only']).split()
167 self._RunGit(['reset', '--hard', merge_base], redirect_stdout=False) 167 self._RunGit(['reset', '--hard', merge_base], redirect_stdout=False)
168 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 168 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
169 169
170 def revinfo(self, options, args, file_list):
171 """Display revision"""
172 return self._RunGit(['rev-parse', 'HEAD'])
173
170 def runhooks(self, options, args, file_list): 174 def runhooks(self, options, args, file_list):
171 self.status(options, args, file_list) 175 self.status(options, args, file_list)
172 176
173 def status(self, options, args, file_list): 177 def status(self, options, args, file_list):
174 """Display status information.""" 178 """Display status information."""
175 if not os.path.isdir(self.checkout_path): 179 if not os.path.isdir(self.checkout_path):
176 print('\n________ couldn\'t run status in %s:\nThe directory ' 180 print('\n________ couldn\'t run status in %s:\nThe directory '
177 'does not exist.' % checkout_path) 181 'does not exist.' % checkout_path)
178 else: 182 else:
179 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) 183 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin'])
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 try: 392 try:
389 # svn revert is so broken we don't even use it. Using 393 # svn revert is so broken we don't even use it. Using
390 # "svn up --revision BASE" achieve the same effect. 394 # "svn up --revision BASE" achieve the same effect.
391 RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], path, 395 RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], path,
392 file_list) 396 file_list)
393 except OSError, e: 397 except OSError, e:
394 # Maybe the directory disapeared meanwhile. We don't want it to throw an 398 # Maybe the directory disapeared meanwhile. We don't want it to throw an
395 # exception. 399 # exception.
396 logging.error('Failed to update:\n%s' % str(e)) 400 logging.error('Failed to update:\n%s' % str(e))
397 401
402 def revinfo(self, options, args, file_list):
403 """Display revision"""
404 return CaptureSVNHeadRevision(self.url)
405
398 def runhooks(self, options, args, file_list): 406 def runhooks(self, options, args, file_list):
399 self.status(options, args, file_list) 407 self.status(options, args, file_list)
400 408
401 def status(self, options, args, file_list): 409 def status(self, options, args, file_list):
402 """Display status information.""" 410 """Display status information."""
403 path = os.path.join(self._root_dir, self.relpath) 411 path = os.path.join(self._root_dir, self.relpath)
404 command = ['status'] 412 command = ['status']
405 command.extend(args) 413 command.extend(args)
406 if not os.path.isdir(path): 414 if not os.path.isdir(path):
407 # svn status won't work if the directory doesn't exist. 415 # svn status won't work if the directory doesn't exist.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 # Col 3 777 # Col 3
770 if wc_status[0].getAttribute('copied') == 'true': 778 if wc_status[0].getAttribute('copied') == 'true':
771 statuses[3] = '+' 779 statuses[3] = '+'
772 # Col 4 780 # Col 4
773 if wc_status[0].getAttribute('switched') == 'true': 781 if wc_status[0].getAttribute('switched') == 'true':
774 statuses[4] = 'S' 782 statuses[4] = 'S'
775 # TODO(maruel): Col 5 and 6 783 # TODO(maruel): Col 5 and 6
776 item = (''.join(statuses), file) 784 item = (''.join(statuses), file)
777 results.append(item) 785 results.append(item)
778 return results 786 return results
OLDNEW
« gclient.py ('K') | « gclient.py ('k') | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698