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

Side by Side Diff: gclient_scm.py

Issue 353001: gclient: make git path more verbose (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
92 92
93 93
94 class GitWrapper(SCMWrapper): 94 class GitWrapper(SCMWrapper):
95 """Wrapper for Git""" 95 """Wrapper for Git"""
96 96
97 def cleanup(self, options, args, file_list): 97 def cleanup(self, options, args, file_list):
98 """Cleanup working copy.""" 98 """Cleanup working copy."""
99 self._RunGit(['prune']) 99 self._RunGit(['prune'], redirect_stdout=False)
100 self._RunGit(['fsck']) 100 self._RunGit(['fsck'], redirect_stdout=False)
101 self._RunGit(['gc']) 101 self._RunGit(['gc'], redirect_stdout=False)
102 102
103 def diff(self, options, args, file_list): 103 def diff(self, options, args, file_list):
104 # NOTE: This function does not currently modify file_list. 104 # NOTE: This function does not currently modify file_list.
105 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) 105 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin'])
106 print self._RunGit(['diff', merge_base]) 106 self._RunGit(['diff', merge_base], redirect_stdout=False)
107 107
108 def export(self, options, args, file_list): 108 def export(self, options, args, file_list):
109 assert len(args) == 1 109 assert len(args) == 1
110 export_path = os.path.abspath(os.path.join(args[0], self.relpath)) 110 export_path = os.path.abspath(os.path.join(args[0], self.relpath))
111 if not os.path.exists(export_path): 111 if not os.path.exists(export_path):
112 os.makedirs(export_path) 112 os.makedirs(export_path)
113 self._RunGit(['checkout-index', '-a', '--prefix=%s/' % export_path]) 113 self._RunGit(['checkout-index', '-a', '--prefix=%s/' % export_path],
114 redirect_stdout=False)
114 115
115 def update(self, options, args, file_list): 116 def update(self, options, args, file_list):
116 """Runs git to update or transparently checkout the working copy. 117 """Runs git to update or transparently checkout the working copy.
117 118
118 All updated files will be appended to file_list. 119 All updated files will be appended to file_list.
119 120
120 Raises: 121 Raises:
121 Error: if can't get URL for relative path. 122 Error: if can't get URL for relative path.
122 """ 123 """
123 124
124 if args: 125 if args:
125 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) 126 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args))
126 127
127 components = self.url.split("@") 128 components = self.url.split("@")
128 url = components[0] 129 url = components[0]
129 revision = None 130 revision = None
130 if options.revision: 131 if options.revision:
131 revision = options.revision 132 revision = options.revision
132 elif len(components) == 2: 133 elif len(components) == 2:
133 revision = components[1] 134 revision = components[1]
134 135
135 if not os.path.exists(self.checkout_path): 136 if not os.path.exists(self.checkout_path):
136 self._RunGit(['clone', '-q', url, self.checkout_path], cwd=self._root_dir) 137 self._RunGit(['clone', url, self.checkout_path],
138 cwd=self._root_dir, redirect_stdout=False)
137 if revision: 139 if revision:
138 self._RunGit(['reset', '--hard', revision]) 140 self._RunGit(['reset', '--hard', revision], redirect_stdout=False)
139 files = self._RunGit(['ls-files']).split() 141 files = self._RunGit(['ls-files']).split()
140 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 142 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
141 return 143 return
142 144
143 self._RunGit(['remote', 'update']) 145 self._RunGit(['remote', 'update'], redirect_stdout=False)
144 new_base = 'origin' 146 new_base = 'origin'
145 if revision: 147 if revision:
146 new_base = revision 148 new_base = revision
147 files = self._RunGit(['diff', new_base, '--name-only']).split() 149 files = self._RunGit(['diff', new_base, '--name-only']).split()
148 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 150 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
149 self._RunGit(['rebase', new_base]) 151 self._RunGit(['rebase', new_base], redirect_stdout=False)
150 152
151 def revert(self, options, args, file_list): 153 def revert(self, options, args, file_list):
152 """Reverts local modifications. 154 """Reverts local modifications.
153 155
154 All reverted files will be appended to file_list. 156 All reverted files will be appended to file_list.
155 """ 157 """
156 path = os.path.join(self._root_dir, self.relpath) 158 path = os.path.join(self._root_dir, self.relpath)
157 if not os.path.isdir(path): 159 if not os.path.isdir(path):
158 # 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
159 # checkout instead. 161 # checkout instead.
160 print("\n_____ %s is missing, synching instead" % self.relpath) 162 print("\n_____ %s is missing, synching instead" % self.relpath)
161 # Don't reuse the args. 163 # Don't reuse the args.
162 return self.update(options, [], file_list) 164 return self.update(options, [], file_list)
163 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) 165 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin'])
164 files = self._RunGit(['diff', merge_base, '--name-only']).split() 166 files = self._RunGit(['diff', merge_base, '--name-only']).split()
165 print self._RunGit(['reset', '--hard', merge_base]) 167 self._RunGit(['reset', '--hard', merge_base], redirect_stdout=False)
166 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])
167 169
168 def runhooks(self, options, args, file_list): 170 def runhooks(self, options, args, file_list):
169 self.status(options, args, file_list) 171 self.status(options, args, file_list)
170 172
171 def status(self, options, args, file_list): 173 def status(self, options, args, file_list):
172 """Display status information.""" 174 """Display status information."""
173 if not os.path.isdir(self.checkout_path): 175 if not os.path.isdir(self.checkout_path):
174 print('\n________ couldn\'t run status in %s:\nThe directory ' 176 print('\n________ couldn\'t run status in %s:\nThe directory '
175 'does not exist.' % checkout_path) 177 'does not exist.' % checkout_path)
176 else: 178 else:
177 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) 179 merge_base = self._RunGit(['merge-base', 'HEAD', 'origin'])
178 print self._RunGit(['diff', '--name-status', merge_base]) 180 self._RunGit(['diff', '--name-status', merge_base], redirect_stdout=False)
179 files = self._RunGit(['diff', '--name-only', merge_base]).split() 181 files = self._RunGit(['diff', '--name-only', merge_base]).split()
180 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 182 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
181 183
182 def _RunGit(self, args, cwd=None, checkrc=True): 184 def _RunGit(self, args, cwd=None, checkrc=True, redirect_stdout=True):
185 stdout=None
186 if redirect_stdout:
187 stdout=subprocess.PIPE
183 if cwd == None: 188 if cwd == None:
184 cwd = self.checkout_path 189 cwd = self.checkout_path
185 cmd = ['git'] 190 cmd = ['git']
186 cmd.extend(args) 191 cmd.extend(args)
187 sp = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE) 192 sp = subprocess.Popen(cmd, cwd=cwd, stdout=stdout)
188 if checkrc and sp.returncode: 193 if checkrc and sp.returncode:
189 raise gclient_utils.Error('git command %s returned %d' % 194 raise gclient_utils.Error('git command %s returned %d' %
190 (args[0], sp.returncode)) 195 (args[0], sp.returncode))
191 return sp.communicate()[0].strip() 196 output = sp.communicate()[0]
197 if output != None:
198 return output.strip()
192 199
193 200
194 class SVNWrapper(SCMWrapper): 201 class SVNWrapper(SCMWrapper):
195 """ Wrapper for SVN """ 202 """ Wrapper for SVN """
196 203
197 def cleanup(self, options, args, file_list): 204 def cleanup(self, options, args, file_list):
198 """Cleanup working copy.""" 205 """Cleanup working copy."""
199 command = ['cleanup'] 206 command = ['cleanup']
200 command.extend(args) 207 command.extend(args)
201 RunSVN(command, os.path.join(self._root_dir, self.relpath)) 208 RunSVN(command, os.path.join(self._root_dir, self.relpath))
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 # Col 3 769 # Col 3
763 if wc_status[0].getAttribute('copied') == 'true': 770 if wc_status[0].getAttribute('copied') == 'true':
764 statuses[3] = '+' 771 statuses[3] = '+'
765 # Col 4 772 # Col 4
766 if wc_status[0].getAttribute('switched') == 'true': 773 if wc_status[0].getAttribute('switched') == 'true':
767 statuses[4] = 'S' 774 statuses[4] = 'S'
768 # TODO(maruel): Col 5 and 6 775 # TODO(maruel): Col 5 and 6
769 item = (''.join(statuses), file) 776 item = (''.join(statuses), file)
770 results.append(item) 777 results.append(item)
771 return results 778 return results
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698