1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2020-2021 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 enum class DiffLineTypes
29 NO_NEWLINE_OLDFILE
, // "\ No newline at end of file"
35 struct DiffLineForStaging
37 DiffLineForStaging(std::string_view line
, DiffLineTypes theType
)
43 std::string_view sLine
; // Includes EOL
47 // Stores a copy of a patch loaded in Patch View Dialog, as a vector of lines (which also stores the type of each line).
48 // Also stores information about the selection made by the user. Handles line text and line type retrieval.
50 // When the user invokes the partial staging/unstaging functionality in the Patch View Dialog, it creates an instance
51 // of this class and then pass the instance to StagingOperations, which will handle the staging/unstaging operations.
52 class CDiffLinesForStaging
55 std::vector
<DiffLineForStaging
> m_linevec
;
56 int m_firstLineSelected
;
57 int m_lastLineSelected
;
60 CDiffLinesForStaging(const char* text
, int numLines
, int firstLineSelected
, int lastLineSelected
);
62 int GetFirstLineNumberSelected() const;
63 int GetLastLineNumberSelected() const;
64 std::string_view
GetFullLineByLineNumber(int line
) const;
65 std::string
GetFullTextOfSelectedLines() const;
66 std::string
GetFullTextOfLineRange(int startline
, int endline
) const;
67 int GetLastDocumentLine() const;
68 DiffLineTypes
GetLineType(int line
) const;
69 bool IsNoNewlineComment(int line
) const;
71 static bool GetOldAndNewLinesCountFromHunk(std::string_view hunk
, int* oldCount
, int* newCount
, bool allowSingleLine
= false);
73 #ifdef GOOGLETEST_INCLUDE_GTEST_GTEST_H_
75 const auto& GetLineVec() const { return m_linevec
; };