File indexing completed on 2025-01-19 04:22:44

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 "filestatus.h"
0008 #include <utility>
0009 
0010 namespace Git
0011 {
0012 
0013 FileStatus::FileStatus() = default;
0014 
0015 FileStatus::FileStatus(QString name, FileStatus::Status status)
0016     : mName(std::move(name))
0017     , mStatus(status)
0018 {
0019 }
0020 
0021 const QString &FileStatus::name() const
0022 {
0023     return mName;
0024 }
0025 
0026 FileStatus::Status FileStatus::status() const
0027 {
0028     return mStatus;
0029 }
0030 
0031 void FileStatus::parseStatusLine(const QString &line)
0032 {
0033     const auto statusX = line.at(0);
0034     const auto statusY = line.at(1);
0035     const auto fileName = line.mid(3);
0036     mName = fileName;
0037 
0038     setStatus(statusX, statusY);
0039 
0040     //    qCDebug(KOMMITLIB_LOG) << "***=" << line << _status << statusX << statusY;
0041 }
0042 
0043 const QString &FileStatus::fullPath() const
0044 {
0045     return mFullPath;
0046 }
0047 
0048 void FileStatus::setFullPath(const QString &newFullPath)
0049 {
0050     mFullPath = newFullPath;
0051 }
0052 
0053 void FileStatus::setStatus(Status status)
0054 {
0055     mStatus = status;
0056 }
0057 
0058 void FileStatus::setStatus(const QString &x, const QString &y)
0059 {
0060     if (x == QLatin1Char('M') || y == QLatin1Char('M'))
0061         mStatus = Modified;
0062     else if (x == QLatin1Char('A'))
0063         mStatus = Added;
0064     else if (x == QLatin1Char('D'))
0065         mStatus = Removed;
0066     else if (x == QLatin1Char('R'))
0067         mStatus = Renamed;
0068     else if (x == QLatin1Char('C'))
0069         mStatus = Copied;
0070     else if (x == QLatin1Char('U'))
0071         mStatus = UpdatedButInmerged;
0072     else if (x == QLatin1Char('?'))
0073         mStatus = Untracked;
0074     else if (x == QLatin1Char('!'))
0075         mStatus = Ignored;
0076     else
0077         mStatus = Unknown;
0078 }
0079 
0080 void FileStatus::setName(const QString &newName)
0081 {
0082     mName = newName;
0083 }
0084 
0085 bool FileStatus::operator==(const FileStatus &other)
0086 {
0087     return mName == other.name();
0088 }
0089 
0090 bool operator==(const FileStatus &f1, const FileStatus &f2)
0091 {
0092     return f1.name() == f2.name();
0093 }
0094 
0095 }