def history_scheduled_with_commit(self, changelist, include_files, exclude_patterns): """ Method to find if any file status has '+' in 4th column""" status_cmd = ['status', '-q', '--ignore-externals'] if changelist: status_cmd.extend(['--changelist', changelist]) if include_files: status_cmd.extend(include_files) for p in self._run_svn(status_cmd, split_lines=True, results_unicode=False): try: if p[3] == b'+': if exclude_patterns: # We found a file with history, but first we must make # sure that it is not being excluded. filename = p[8:].rstrip() should_exclude = filename_match_any_patterns( filename, exclude_patterns, self.get_repository_info().base_path) if not should_exclude: return True else: return True except IndexError: # This may be some other output, or just doesn't have the # data we're looking for. Move along. pass return False
def history_scheduled_with_commit(self, changelist, include_files, exclude_patterns): """ Method to find if any file status has '+' in 4th column""" status_cmd = ['status', '-q', '--ignore-externals'] if changelist: status_cmd.extend(['--changelist', changelist]) if include_files: status_cmd.extend(include_files) for p in self._run_svn(status_cmd, split_lines=True): try: if not changelist and p.startswith('--- Changelist'): # svn status returns changelist information last. If we # hit a line starting with '--- Changelist' then we have # reached the changelist section and can exit the loop as # we are not interested in changelists. break if p[3] == '+': if exclude_patterns: # We found a file with history, but first we must make # sure that it is not being excluded. filename = p[8:].rstrip() should_exclude = filename_match_any_patterns( filename, exclude_patterns, self.get_repository_info().base_path) if not should_exclude: return True else: return True except IndexError: # This may be some other output, or just doesn't have the # data we're looking for. Move along. pass return False
def _diff_working_copy(self, base, include_files, exclude_patterns): """Return a diff of the working copy. Args: base (unicode): The base revision to diff against. include_files (list): A list of file paths to include in the diff. exclude_patterns (list): A list of file paths to exclude from the diff. Returns: dict: A dictionary containing ``diff``, ``parent_diff``, and ``base_commit_id`` keys. In the case of TFS, the parent diff key will always be ``None``. """ # We pass results_unicode=False because that uses the filesystem # encoding, but the XML results we get should always be UTF-8, and are # well-formed with the encoding specified. We can therefore let # ElementTree determine how to decode it. status = self._run_tf(['status', '-format:xml'], results_unicode=False) root = ET.fromstring(status) diff = [] for pending_change in root.findall('./pending-changes/pending-change'): action = pending_change.attrib['change-type'].split(', ') new_filename = pending_change.attrib['server-item'].encode('utf-8') local_filename = pending_change.attrib['local-item'] old_version = pending_change.attrib['version'].encode('utf-8') file_type = pending_change.attrib.get('file-type') new_version = b'(pending)' old_data = b'' new_data = b'' copied = 'branch' in action if (not file_type or (not os.path.isfile(local_filename) and 'delete' not in action)): continue if (exclude_patterns and filename_match_any_patterns( local_filename, exclude_patterns, base_dir=None)): continue if 'rename' in action: old_filename = \ pending_change.attrib['source-item'].encode('utf-8') else: old_filename = new_filename if copied: old_filename = \ pending_change.attrib['source-item'].encode('utf-8') old_version = ('%d' % self._convert_symbolic_revision( 'W', old_filename.decode('utf-8'))) if 'add' in action: old_filename = b'/dev/null' if file_type != 'binary': with open(local_filename) as f: new_data = f.read() old_data = b'' elif 'delete' in action: old_data = self._run_tf([ 'print', '-version:%s' % old_version.decode('utf-8'), old_filename.decode('utf-8') ], results_unicode=False) new_data = b'' new_version = b'(deleted)' elif 'edit' in action: old_data = self._run_tf([ 'print', '-version:%s' % old_version.decode('utf-8'), old_filename.decode('utf-8') ], results_unicode=False) with open(local_filename) as f: new_data = f.read() old_label = b'%s\t%s' % (old_filename, old_version) new_label = b'%s\t%s' % (new_filename, new_version) if copied: diff.append(b'Copied from: %s\n' % old_filename) if file_type == 'binary': if 'add' in action: old_filename = new_filename diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) diff.append(b'Binary files %s and %s differ\n' % (old_filename, new_filename)) elif old_filename != new_filename and old_data == new_data: # Renamed file with no changes diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) else: old_tmp = tempfile.NamedTemporaryFile(delete=False) old_tmp.write(old_data) old_tmp.close() new_tmp = tempfile.NamedTemporaryFile(delete=False) new_tmp.write(new_data) new_tmp.close() unified_diff = execute([ 'diff', '-u', '--label', old_label.decode('utf-8'), '--label', new_label.decode('utf-8'), old_tmp.name, new_tmp.name ], extra_ignore_errors=(1, ), log_output_on_error=False, results_unicode=False) diff.append(unified_diff) os.unlink(old_tmp.name) os.unlink(new_tmp.name) if len(root.findall('./candidate-pending-changes/pending-change')) > 0: logging.warning('There are added or deleted files which have not ' 'been added to TFS. These will not be included ' 'in your review request.') return { 'diff': b''.join(diff), 'parent_diff': None, 'base_commit_id': base, }
def _diff_working_copy(self, base, include_files, exclude_patterns): """Return a diff of the working copy. Args: base (unicode): The base revision to diff against. include_files (list): A list of file paths to include in the diff. exclude_patterns (list): A list of file paths to exclude from the diff. Returns: dict: A dictionary containing ``diff``, ``parent_diff``, and ``base_commit_id`` keys. In the case of TFS, the parent diff key will always be ``None``. """ # We pass results_unicode=False because that uses the filesystem # encoding, but the XML results we get should always be UTF-8, and are # well-formed with the encoding specified. We can therefore let # ElementTree determine how to decode it. status = self._run_tf(['vc', 'status', '/format:xml'], results_unicode=False) root = ET.fromstring(status) diff = [] for pending_change in root.findall( './PendingSet/PendingChanges/PendingChange'): action = pending_change.attrib['chg'].split(' ') old_filename = \ pending_change.attrib.get('srcitem', '').encode('utf-8') new_filename = pending_change.attrib['item'].encode('utf-8') local_filename = pending_change.attrib['local'] old_version = \ pending_change.attrib.get('svrfm', '0').encode('utf-8') file_type = pending_change.attrib['type'] encoding = pending_change.attrib['enc'] new_version = b'(pending)' old_data = b'' new_data = b'' binary = (encoding == '-1') copied = 'Branch' in action if (not file_type or (not os.path.isfile(local_filename) and 'Delete' not in action)): continue if (exclude_patterns and filename_match_any_patterns( local_filename, exclude_patterns, base_dir=None)): continue if 'Add' in action: old_filename = b'/dev/null' if not binary: with open(local_filename, 'rb') as f: new_data = f.read() old_data = b'' elif 'Delete' in action: old_data = self._run_tf([ 'vc', 'view', '/version:%s' % old_version.decode('utf-8'), old_filename.decode('utf-8') ], results_unicode=False) new_data = b'' new_version = b'(deleted)' elif 'Edit' in action: if not binary: old_data = self._run_tf([ 'vc', 'view', old_filename.decode('utf-8'), '/version:%s' % old_version.decode('utf-8') ], results_unicode=False) with open(local_filename, 'rb') as f: new_data = f.read() old_label = b'%s\t%s' % (old_filename, old_version) new_label = b'%s\t%s' % (new_filename, new_version) if copied: diff.append(b'Copied from: %s\n' % old_filename) if binary: if 'Add' in action: old_filename = new_filename diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) diff.append(b'Binary files %s and %s differ\n' % (old_filename, new_filename)) elif old_filename != new_filename and old_data == new_data: # Renamed file with no changes. diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) else: old_tmp = tempfile.NamedTemporaryFile(delete=False) old_tmp.write(old_data) old_tmp.close() new_tmp = tempfile.NamedTemporaryFile(delete=False) new_tmp.write(new_data) new_tmp.close() unified_diff = execute([ 'diff', '-u', '--label', old_label.decode('utf-8'), '--label', new_label.decode('utf-8'), old_tmp.name, new_tmp.name ], extra_ignore_errors=(1, ), log_output_on_error=False, results_unicode=False) diff.append(unified_diff) os.unlink(old_tmp.name) os.unlink(new_tmp.name) return { 'diff': b''.join(diff), 'parent_diff': None, 'base_commit_id': base, }
def _diff_working_copy(self, base, include_files, exclude_patterns): """Return a diff of the working copy. Args: base (unicode): The base revision to diff against. include_files (list): A list of file paths to include in the diff. exclude_patterns (list): A list of file paths to exclude from the diff. Returns: dict: A dictionary containing ``diff``, ``parent_diff``, and ``base_commit_id`` keys. In the case of TFS, the parent diff key will always be ``None``. """ # We pass results_unicode=False because that uses the filesystem # encoding, but the XML results we get should always be UTF-8, and are # well-formed with the encoding specified. We can therefore let # ElementTree determine how to decode it. status = self._run_tf(['status', '-format:xml'], results_unicode=False) root = ET.fromstring(status) diff = [] for pending_change in root.findall('./pending-changes/pending-change'): action = pending_change.attrib['change-type'].split(', ') new_filename = pending_change.attrib['server-item'].encode('utf-8') local_filename = pending_change.attrib['local-item'] old_version = pending_change.attrib['version'].encode('utf-8') file_type = pending_change.attrib.get('file-type') new_version = b'(pending)' old_data = b'' new_data = b'' copied = 'branch' in action if (not file_type or (not os.path.isfile(local_filename) and 'delete' not in action)): continue if (exclude_patterns and filename_match_any_patterns(local_filename, exclude_patterns, base_dir=None)): continue if 'rename' in action: old_filename = \ pending_change.attrib['source-item'].encode('utf-8') else: old_filename = new_filename if copied: old_filename = \ pending_change.attrib['source-item'].encode('utf-8') old_version = ( '%d' % self._convert_symbolic_revision( 'W', old_filename.decode('utf-8'))) if 'add' in action: old_filename = b'/dev/null' if file_type != 'binary': with open(local_filename) as f: new_data = f.read() old_data = b'' elif 'delete' in action: old_data = self._run_tf( ['print', '-version:%s' % old_version.decode('utf-8'), old_filename.decode('utf-8')], results_unicode=False) new_data = b'' new_version = b'(deleted)' elif 'edit' in action: old_data = self._run_tf( ['print', '-version:%s' % old_version.decode('utf-8'), old_filename.decode('utf-8')], results_unicode=False) with open(local_filename) as f: new_data = f.read() old_label = b'%s\t%s' % (old_filename, old_version) new_label = b'%s\t%s' % (new_filename, new_version) if copied: diff.append(b'Copied from: %s\n' % old_filename) if file_type == 'binary': if 'add' in action: old_filename = new_filename diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) diff.append(b'Binary files %s and %s differ\n' % (old_filename, new_filename)) elif old_filename != new_filename and old_data == new_data: # Renamed file with no changes diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) else: old_tmp = tempfile.NamedTemporaryFile(delete=False) old_tmp.write(old_data) old_tmp.close() new_tmp = tempfile.NamedTemporaryFile(delete=False) new_tmp.write(new_data) new_tmp.close() unified_diff = execute( ['diff', '-u', '--label', old_label.decode('utf-8'), '--label', new_label.decode('utf-8'), old_tmp.name, new_tmp.name], extra_ignore_errors=(1,), log_output_on_error=False, results_unicode=False) diff.append(unified_diff) os.unlink(old_tmp.name) os.unlink(new_tmp.name) if len(root.findall('./candidate-pending-changes/pending-change')) > 0: logging.warning('There are added or deleted files which have not ' 'been added to TFS. These will not be included ' 'in your review request.') return { 'diff': b''.join(diff), 'parent_diff': None, 'base_commit_id': base, }
def _diff_working_copy(self, base, include_files, exclude_patterns): """Return a diff of the working copy. Args: base (unicode): The base revision to diff against. include_files (list): A list of file paths to include in the diff. exclude_patterns (list): A list of file paths to exclude from the diff. Returns: dict: A dictionary containing ``diff``, ``parent_diff``, and ``base_commit_id`` keys. In the case of TFS, the parent diff key will always be ``None``. """ # We pass results_unicode=False because that uses the filesystem # encoding, but the XML results we get should always be UTF-8, and are # well-formed with the encoding specified. We can therefore let # ElementTree determine how to decode it. status = self._run_tf(['vc', 'status', '/format:xml'], results_unicode=False) root = ET.fromstring(status) diff = [] for pending_change in root.findall( './PendingSet/PendingChanges/PendingChange'): action = pending_change.attrib['chg'].split(' ') old_filename = \ pending_change.attrib.get('srcitem', '').encode('utf-8') new_filename = pending_change.attrib['item'].encode('utf-8') local_filename = pending_change.attrib['local'] old_version = \ pending_change.attrib.get('svrfm', '0').encode('utf-8') file_type = pending_change.attrib['type'] encoding = pending_change.attrib['enc'] new_version = b'(pending)' old_data = b'' new_data = b'' binary = (encoding == '-1') copied = 'Branch' in action if (not file_type or (not os.path.isfile(local_filename) and 'Delete' not in action)): continue if (exclude_patterns and filename_match_any_patterns(local_filename, exclude_patterns, base_dir=None)): continue if 'Add' in action: old_filename = b'/dev/null' if not binary: with open(local_filename, 'rb') as f: new_data = f.read() old_data = b'' elif 'Delete' in action: old_data = self._run_tf( ['vc', 'view', '/version:%s' % old_version.decode('utf-8'), old_filename.decode('utf-8')], results_unicode=False) new_data = b'' new_version = b'(deleted)' elif 'Edit' in action: if not binary: old_data = self._run_tf( ['vc', 'view', old_filename.decode('utf-8'), '/version:%s' % old_version.decode('utf-8')], results_unicode=False) with open(local_filename, 'rb') as f: new_data = f.read() old_label = b'%s\t%s' % (old_filename, old_version) new_label = b'%s\t%s' % (new_filename, new_version) if copied: diff.append(b'Copied from: %s\n' % old_filename) if binary: if 'Add' in action: old_filename = new_filename diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) diff.append(b'Binary files %s and %s differ\n' % (old_filename, new_filename)) elif old_filename != new_filename and old_data == new_data: # Renamed file with no changes. diff.append(b'--- %s\n' % old_label) diff.append(b'+++ %s\n' % new_label) else: old_tmp = tempfile.NamedTemporaryFile(delete=False) old_tmp.write(old_data) old_tmp.close() new_tmp = tempfile.NamedTemporaryFile(delete=False) new_tmp.write(new_data) new_tmp.close() unified_diff = execute( ['diff', '-u', '--label', old_label.decode('utf-8'), '--label', new_label.decode('utf-8'), old_tmp.name, new_tmp.name], extra_ignore_errors=(1,), log_output_on_error=False, results_unicode=False) diff.append(unified_diff) os.unlink(old_tmp.name) os.unlink(new_tmp.name) return { 'diff': b''.join(diff), 'parent_diff': None, 'base_commit_id': base, }