Пример #1
0
 def _is_binary(self):
     """True if the file is binary."""
     try:
         self.tree.lock_read()
         try:
             lines = self.tree.get_file_lines(self.file_id)
             check_text_lines(lines)
         finally:
             self.tree.unlock()
         return False
     except BinaryFile:
         return True
Пример #2
0
    def _select_hunks(self, creator, file_id, work_tree_lines):
        """Provide diff hunk selection for modified text.

        If self.reporter.invert_diff is True, the diff is inverted so that
        insertions are displayed as removals and vice versa.

        :param creator: a ShelfCreator
        :param file_id: The id of the file to shelve.
        :param work_tree_lines: Line contents of the file in the working tree.
        :return: number of shelved hunks.
        """
        if self.reporter.invert_diff:
            target_lines = work_tree_lines
        else:
            target_lines = self.target_tree.get_file_lines(file_id)
        textfile.check_text_lines(work_tree_lines)
        textfile.check_text_lines(target_lines)
        parsed = self.get_parsed_patch(file_id, self.reporter.invert_diff)
        final_hunks = []
        if not self.auto:
            offset = 0
            self.diff_writer.write(parsed.get_header())
            for hunk in parsed.hunks:
                self.diff_writer.write(str(hunk))
                selected = self.prompt_bool(self.reporter.vocab['hunk'],
                                            allow_editor=(self.change_editor
                                                          is not None))
                if not self.reporter.invert_diff:
                    selected = (not selected)
                if selected:
                    hunk.mod_pos += offset
                    final_hunks.append(hunk)
                else:
                    offset -= (hunk.mod_range - hunk.orig_range)
        sys.stdout.flush()
        if self.reporter.invert_diff:
            change_count = len(final_hunks)
        else:
            change_count = len(parsed.hunks) - len(final_hunks)
        patched = patches.iter_patched_from_hunks(target_lines,
                                                  final_hunks)
        lines = list(patched)
        return lines, change_count
Пример #3
0
    def _select_hunks(self, creator, file_id, work_tree_lines):
        """Provide diff hunk selection for modified text.

        If self.reporter.invert_diff is True, the diff is inverted so that
        insertions are displayed as removals and vice versa.

        :param creator: a ShelfCreator
        :param file_id: The id of the file to shelve.
        :param work_tree_lines: Line contents of the file in the working tree.
        :return: number of shelved hunks.
        """
        if self.reporter.invert_diff:
            target_lines = work_tree_lines
        else:
            target_lines = self.target_tree.get_file_lines(file_id)
        textfile.check_text_lines(work_tree_lines)
        textfile.check_text_lines(target_lines)
        parsed = self.get_parsed_patch(file_id, self.reporter.invert_diff)
        final_hunks = []
        if not self.auto:
            offset = 0
            self.diff_writer.write(parsed.get_header())
            for hunk in parsed.hunks:
                self.diff_writer.write(str(hunk))
                selected = self.prompt_bool(self.reporter.vocab['hunk'],
                                            allow_editor=(self.change_editor
                                                          is not None))
                if not self.reporter.invert_diff:
                    selected = (not selected)
                if selected:
                    hunk.mod_pos += offset
                    final_hunks.append(hunk)
                else:
                    offset -= (hunk.mod_range - hunk.orig_range)
        sys.stdout.flush()
        if self.reporter.invert_diff:
            change_count = len(final_hunks)
        else:
            change_count = len(parsed.hunks) - len(final_hunks)
        patched = patches.iter_patched_from_hunks(target_lines, final_hunks)
        lines = list(patched)
        return lines, change_count
Пример #4
0
 def __init__(self, base, a, b, is_cherrypick=False):
     check_text_lines(base)
     check_text_lines(a)
     check_text_lines(b)
     self.base = base
     self.a = a
     self.b = b
     self.is_cherrypick = is_cherrypick
Пример #5
0
 def __init__(self, base, a, b, is_cherrypick=False):
     check_text_lines(base)
     check_text_lines(a)
     check_text_lines(b)
     self.base = base
     self.a = a
     self.b = b
     self.is_cherrypick = is_cherrypick
Пример #6
0
    def __init__(self, base, a, b, is_cherrypick=False):
        """Constructor.

        :param base: lines in BASE
        :param a: lines in A
        :param b: lines in B
        :param is_cherrypick: flag indicating if this merge is a cherrypick.
            When cherrypicking b => a, matches with b and base do not conflict.
        """
        textfile.check_text_lines(base)
        textfile.check_text_lines(a)
        textfile.check_text_lines(b)
        self.base = base
        self.a = a
        self.b = b
        self.is_cherrypick = is_cherrypick
Пример #7
0
    def __init__(self, base, a, b, is_cherrypick=False, allow_objects=False):
        """Constructor.

        :param base: lines in BASE
        :param a: lines in A
        :param b: lines in B
        :param is_cherrypick: flag indicating if this merge is a cherrypick.
            When cherrypicking b => a, matches with b and base do not conflict.
        :param allow_objects: if True, do not require that base, a and b are
            plain Python strs.  Also prevents BinaryFile from being raised.
            Lines can be any sequence of comparable and hashable Python
            objects.
        """
        if not allow_objects:
            textfile.check_text_lines(base)
            textfile.check_text_lines(a)
            textfile.check_text_lines(b)
        self.base = base
        self.a = a
        self.b = b
        self.is_cherrypick = is_cherrypick
Пример #8
0
    def __init__(self, base, a, b, is_cherrypick=False, allow_objects=False):
        """Constructor.

        :param base: lines in BASE
        :param a: lines in A
        :param b: lines in B
        :param is_cherrypick: flag indicating if this merge is a cherrypick.
            When cherrypicking b => a, matches with b and base do not conflict.
        :param allow_objects: if True, do not require that base, a and b are
            plain Python strs.  Also prevents BinaryFile from being raised.
            Lines can be any sequence of comparable and hashable Python
            objects.
        """
        if not allow_objects:
            textfile.check_text_lines(base)
            textfile.check_text_lines(a)
            textfile.check_text_lines(b)
        self.base = base
        self.a = a
        self.b = b
        self.is_cherrypick = is_cherrypick
Пример #9
0
 def test_check_text_lines(self):
     lines = ['ab' * 2048]
     check_text_lines(lines)
     lines = ['a' * 1023 + '\x00']
     self.assertRaises(BinaryFile, check_text_lines, lines)
Пример #10
0
 def test_check_text_lines(self):
     lines = ['ab' * 2048]
     check_text_lines(lines)
     lines = ['a' * 1023 + '\x00']
     self.assertRaises(BinaryFile, check_text_lines, lines)