File indexing completed on 2025-03-09 05:11:41
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "treediff.h" 0008 #include "filestatus.h" 0009 0010 namespace Git 0011 { 0012 0013 TreeDiff::TreeDiff() 0014 { 0015 } 0016 0017 bool TreeDiff::contains(const QString &entryPath) const 0018 { 0019 auto i = std::find_if(begin(), end(), [&entryPath](const TreeDiffEntry &f) { 0020 return f.oldFile() == entryPath || f.newFile() == entryPath; 0021 }); 0022 return i != end(); 0023 } 0024 0025 ChangeStatus TreeDiff::status(const QString &entryPath) const 0026 { 0027 auto i = std::find_if(begin(), end(), [&entryPath](const TreeDiffEntry &f) { 0028 return f.oldFile() == entryPath || f.newFile() == entryPath; 0029 }); 0030 if (i == end()) 0031 return ChangeStatus::Unmodified; 0032 0033 return (*i).status(); 0034 } 0035 0036 TreeDiffEntry::TreeDiffEntry() 0037 { 0038 } 0039 0040 TreeDiffEntry::TreeDiffEntry(const git_diff_delta *delta) 0041 { 0042 mOldFile = delta->old_file.path; 0043 mNewFile = delta->new_file.path; 0044 0045 switch (delta->status) { 0046 case GIT_DELTA_UNMODIFIED: 0047 mStatus = ChangeStatus::Unmodified; 0048 break; 0049 case GIT_DELTA_ADDED: 0050 mStatus = ChangeStatus::Added; 0051 break; 0052 case GIT_DELTA_DELETED: 0053 mStatus = ChangeStatus::Removed; 0054 break; 0055 case GIT_DELTA_MODIFIED: 0056 mStatus = ChangeStatus::Modified; 0057 break; 0058 case GIT_DELTA_RENAMED: 0059 mStatus = ChangeStatus::Renamed; 0060 break; 0061 case GIT_DELTA_COPIED: 0062 mStatus = ChangeStatus::Copied; 0063 break; 0064 case GIT_DELTA_IGNORED: 0065 mStatus = ChangeStatus::Ignored; 0066 break; 0067 case GIT_DELTA_UNTRACKED: 0068 mStatus = ChangeStatus::Untracked; 0069 break; 0070 case GIT_DELTA_TYPECHANGE: 0071 mStatus = ChangeStatus::TypeChange; 0072 break; 0073 case GIT_DELTA_UNREADABLE: 0074 mStatus = ChangeStatus::Unreadable; 0075 break; 0076 case GIT_DELTA_CONFLICTED: 0077 mStatus = ChangeStatus::Conflicted; 0078 break; 0079 } 0080 } 0081 0082 git_diff_delta *TreeDiffEntry::deltaPtr() const 0083 { 0084 return mDeltaPtr; 0085 } 0086 0087 QString TreeDiffEntry::oldFile() const 0088 { 0089 return mOldFile; 0090 } 0091 0092 QString TreeDiffEntry::newFile() const 0093 { 0094 return mNewFile; 0095 } 0096 0097 ChangeStatus TreeDiffEntry::status() const 0098 { 0099 return mStatus; 0100 } 0101 0102 bool TreeDiffEntry::operator==(const TreeDiffEntry &other) const 0103 { 0104 if (!mDeltaPtr) 0105 return false; 0106 return mDeltaPtr == other.mDeltaPtr; 0107 } 0108 0109 } // namespace Git