Immensely speed up 'vng changes'
[vng.git] / src / hunks / File.h
bloba7bc44507e3a79d8e6f20cf99c969ba444614613
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (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, see <http://www.gnu.org/licenses/>.
19 #ifndef FILE_H
20 #define FILE_H
22 #include "Hunk.h"
23 #include <QList>
24 #include <QString>
25 #include <QFile>
27 class QTextStream;
28 class Configuration;
29 class QFileInfo;
31 /**
32 * This class represents a single file in ChangeSet.
34 class File
36 public:
37 File();
38 File(const File &other);
39 ~File();
41 /// return if the file is (still) present on the filesystem.
42 bool isValid() const;
44 void setFileName(const QByteArray &filename);
45 void setOldFileName(const QByteArray &filename);
46 QByteArray fileName() const;
47 QByteArray oldFileName() const;
49 void addHunk(const Hunk &hunk);
50 QList<Hunk> hunks() const;
52 void setProtection(const QString &string);
53 void setOldProtection(const QString &string);
54 QString protection() const;
55 QString oldProtection() const;
56 QFile::Permissions permissions() const;
58 void setOldSha1(const QString &string);
59 void setSha1(const QString &string);
60 QString oldSha1() const;
61 QString sha1() const;
63 /// return hunk count
64 int count() const;
65 /// return the accumulated number of added lines in all the hunks
66 int linesAdded() const;
67 /// return the accumulated number of removed lines in all the hunks
68 int linesRemoved() const;
70 /// return true if this file has registered any changes.
71 bool hasChanged() const;
72 void setRenameAcceptance(Vng::Acceptance accepted);
73 void setProtectionAcceptance(Vng::Acceptance accepted);
74 void setBinaryChangeAcceptance(Vng::Acceptance accepted);
75 Vng::Acceptance renameAcceptance() const;
76 Vng::Acceptance protectionAcceptance() const;
77 Vng::Acceptance binaryChangeAcceptance() const;
78 /**
79 * This method will iterate over all the hunks and subhunks to return the combined acceptance of the changes for this file.
81 Vng::Acceptance changesAcceptance();
83 void setBinary(bool binary);
84 bool isBinary() const;
86 void outputWhatsChanged(QTextStream &out, Configuration &config, bool printSummary, bool unified);
88 /// use the sha1s set to fetch the hunks.
89 void fetchHunks(bool againstHead);
90 /// remove the diff(s) stored in memory for this file, diff related method calls will no longer work after this.
91 void cleanHunksData();
93 File &operator=(const File &other);
94 bool operator==(const File &other) const;
95 bool operator!=(const File &other) const;
97 /**
98 * Calling this will check with the repo database if the path is registered in the repo.
99 * @returns true if the current repo and current HEAD know this commit, false otherwise.
101 static bool fileKnownToGit(const QFileInfo &path);
102 /// overloaded method provided for your convenience.
103 static bool fileKnownToGit(const QString &path);
106 * In git output non-latin1 characters are encoded like \nnn but in accepting arguments git expects normal output.
107 * So we need to convert sometimes.
109 static QByteArray escapeGitFilename(const QByteArray &fileName);
111 private:
112 class Private;
113 Private * d;
116 #endif