Consolidate adjacent lines, if same commit ID.

        Will modify line number to be a range, when two or more lines with the
        same commit ID.
161478
def sort(self):
        
        self.sorted_commits = []
        if not self.commits:
            return self.sorted_commits
        prev_commit = self.commits.pop(0)
        prev_line = prev_commit.line_number
        prev_uuid = prev_commit.uuid
        for commit in self.commits:
            if (commit.uuid != prev_uuid or
                    commit.line_number != (prev_line + 1)):
                prev_commit.lines = self.line_range(prev_commit.line_number,
                                                    prev_line)
                self.sorted_commits.append(prev_commit)
                prev_commit = commit
            prev_line = commit.line_number
            prev_uuid = commit.uuid
        # Take care of last commit
        prev_commit.lines = self.line_range(prev_commit.line_number, prev_line)
        self.sorted_commits.append(prev_commit)
        return self.sorted_commits
658014
private void resolveToCurrent(List<Delta<E>> deltas)
    {
        int lineOffset = 0;

        for (Delta<E> d : deltas) {
            Chunk<E> original = d.getOriginal();
            Chunk<E> revised = d.getRevised();

            int pos = original.getPosition() + lineOffset;
            // delete lines
            for (int i = 0; i < original.size(); i++) {
                int origLine = elementList.remove(pos);
                currentRevisionContent.remove(pos);
                if (origLine != -1) {
                    sourceRevisions.set(origLine, currentRevision);
                }
            }

            for (int i = 0; i < revised.size(); i++) {
                currentRevisionContent.add(pos + i, revised.getLines().get(i));
                elementList.add(pos + i, -1);
            }

            lineOffset += revised.size() - original.size();
        }
    }
527975
def lines_by_sha(commit_sha)
      `#{File.join(File.dirname(__FILE__), 'reporter', 'git-lines.sh')} #{@config.working_dir} #{commit_sha}`.split("\n")
    end
459474
def multiline_push(self, code, lines):
        """"""
        for line in lines[:-1]:
            answer = '%s-%s' % (code, line)
            self.push(answer)
        self.push(code, lines[-1])
1189205
def get_coord_line_number(self,coord):
    """"""
    if coord[0] in self._coords:
      if coord[1] in self._coords[coord[0]]:
        return self._coords[coord[0]][coord[1]]
    return None
129181
def append(self, lines, index=-1):
        """"""
        if isinstance(lines, (basestring, bytes)):
            lines = [lines]
        return self.request('nvim_buf_set_lines', index, index, True, lines)
321396
def sorted_puts(line)
      if line == nil || line.size == 0
        raise ArgumentError, 'Line cannot be blank!'
      end
      if line.index($/)
        raise ArgumentError, "Cannot `puts` a line with extra line endings. Make sure the line does not contain `#{$/.inspect}`"
      end

      matched, idx = binary_seek(line)

      if matched
        # an exact match was found, nothing to do
      else
        if idx == nil
          # append to end of file
          self.seek(0, IO::SEEK_END)
          puts(line)
        else
          self.seek(cached_positions[idx][0], IO::SEEK_SET)
          do_at_current_position{puts(line)}
        end
        update_cached_position(idx, line)
      end
      nil
    end
617860
def endline_handle(self, original, loc, tokens):
        """"""
        internal_assert(len(tokens) == 1, "invalid endline tokens", tokens)
        lines = tokens[0].splitlines(True)
        if self.minify:
            lines = lines[0]
        out = []
        ln = lineno(loc, original)
        for endline in lines:
            out.append(self.wrap_line_number(self.adjust(ln)) + endline)
            ln += 1
        return "".join(out)
791380
def _updateNumbers(self, linenumers):
        
        b = self.blockCount()
        c = b - linenumers
        if c > 0:
            # remove lines numbers
            for _ in range(c):
                # remove last line:
                self.setFocus()
                storeCursorPos = self.textCursor()
                self.moveCursor(
                    QtGui.QTextCursor.End,
                    QtGui.QTextCursor.MoveAnchor)
                self.moveCursor(
                    QtGui.QTextCursor.StartOfLine,
                    QtGui.QTextCursor.MoveAnchor)
                self.moveCursor(
                    QtGui.QTextCursor.End,
                    QtGui.QTextCursor.KeepAnchor)
                self.textCursor().removeSelectedText()
                self.textCursor().deletePreviousChar()
                self.setTextCursor(storeCursorPos)
        elif c < 0:
            # add line numbers
            for i in range(-c):
                self.appendPlainText(str(b + i + 1))
761235
def align_lines(lines: list, column_separator: str='|') -> list:
    
    rows = []
    col_len = []
    for line in lines:
        line = str(line)
        cols = []
        for col_index, col in enumerate(line.split(column_separator)):
            col = str(col).strip()
            cols.append(col)
            if col_index >= len(col_len):
                col_len.append(0)
            col_len[col_index] = max(col_len[col_index], len(col))
        rows.append(cols)

    lines_out = []
    for row in rows:
        cols_out = []
        for col_index, col in enumerate(row):
            if col_index == 0:
                col = col.ljust(col_len[col_index])
            else:
                col = col.rjust(col_len[col_index])
            cols_out.append(col)
        lines_out.append(' '.join(cols_out))
    return lines_out
656122
def _unique_ordered_lines(line_numbers):
        

        if len(line_numbers) == 0:
            return []

        # Ensure lines are unique by putting them in a set
        line_set = set(line_numbers)

        # Retrieve the list from the set, sort it, and return
        return sorted([line for line in line_set])
128930
def splitlines(self, keepends=False):
        """"""
        lines = self.split('\n')
        return [line+'\n' for line in lines] if keepends else (
               lines if lines[-1] else lines[:-1])
1245550
def all_prev_ordered(self, commit: Commit):
        
        # TODO: This method does a lot of work, choose correct data
        # structures to make it efficient.

        viewNo, ppSeqNo = commit.viewNo, commit.ppSeqNo

        if self.last_ordered_3pc == (viewNo, ppSeqNo - 1):
            # Last ordered was in same view as this COMMIT
            return True

        # if some PREPAREs/COMMITs were completely missed in the same view
        toCheck = set()
        toCheck.update(set(self.sentPrePrepares.keys()))
        toCheck.update(set(self.prePrepares.keys()))
        toCheck.update(set(self.prepares.keys()))
        toCheck.update(set(self.commits.keys()))
        for (v, p) in toCheck:
            if v < viewNo and (v, p) not in self.ordered:
                # Have commits from previous view that are unordered.
                return False
            if v == viewNo and p < ppSeqNo and (v, p) not in self.ordered:
                # If unordered commits are found with lower ppSeqNo then this
                # cannot be ordered.
                return False

        return True
1144987
def _get_merge(self):
        """"""
        line = self.next_line()
        if line is None:
            return None
        elif line.startswith(b'merge '):
            return line[len(b'merge '):]
        else:
            self.push_line(line)
            return None
211456
def merge(polylines, mx_dist=4):
    
    l = len(polylines)
    to_remove = set()
    for n in range(l - 1, -1, -1):
        if n not in to_remove:
            c = polylines[n]
            for p0, p1 in zip(c[:-1], c[1:]):
                # create a line from any subsegment:
                l0 = p0[0], p0[1], p1[0], p1[1]

                # for every other polyline:
                for m in range(l - 1, -1, -1):
                    if m not in to_remove:
                        if n == m:
                            continue
                        remove = False
                        cc = polylines[m]
                        ind = np.zeros(shape=cc.shape[0], dtype=bool)

                        # for every point p in this polyline:
                        for o in range(len(cc) - 1, -1, -1):
                            p = cc[o]

                            if line.segmentDistance(l0, p) < mx_dist:
                                remove = True
                                ind[o] = True

                        if remove:
                            polylines[n] = np.append(c, cc[ind], axis=0)
                            ind = ~ind
                            s = ind.sum()
                            if s < 2:
                                to_remove.add(m)
                            else:
                                polylines[m] = cc[ind]

    to_remove = sorted(to_remove)
    to_remove.reverse()
    for i in to_remove:
        polylines.pop(i)
1096458
def diff(old_commit, new_commit)
        stats = @g.diff(old_commit, new_commit).stats
        lines = lines_added(new_commit.sha)
        return if !lines.is_a?(Hash) || stats.blank?

        lines.each do |filename, filelines|
          stats[:files][filename][:lines_added] = filelines if stats[:files].key?(filename)
        end

        stats
      end
403408
def line_range(self, line_number):
    """"""
    if line_number <= 0 or line_number > len(self.lines):
      raise IndexError('NOTE: Python file line numbers are offset by 1.')

    if line_number not in self.logical_lines:
      return slice(line_number, line_number + 1)
    else:
      start, stop, _ = self.logical_lines[line_number]
      return slice(start, stop)