Be memory efficient and clear hunk data after displaying it
[vng.git] / hunks / File.h
blob29de772d996ad1273e50cc23238683825ec7c151
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 {
35 public:
36 File();
37 File(const File &other);
38 ~File();
40 /// return if the file is (still) present on the filesystem.
41 bool isValid() const;
43 void setFileName(const QByteArray &filename);
44 void setOldFileName(const QByteArray &filename);
45 QByteArray fileName() const;
46 QByteArray oldFileName() const;
48 void addHunk(const Hunk &hunk);
49 QList<Hunk> hunks() const;
51 void setProtection(const QString &string);
52 void setOldProtection(const QString &string);
53 QString protection() const;
54 QString oldProtection() const;
55 QFile::Permissions permissions() const;
57 void setOldSha1(const QString &string);
58 void setSha1(const QString &string);
59 QString oldSha1() const;
60 QString sha1() const;
62 /// return hunk count
63 int count() const;
64 /// return the accumulated number of added lines in all the hunks
65 int linesAdded() const;
66 /// return the accumulated number of removed lines in all the hunks
67 int linesRemoved() const;
69 /// return true if this file has registered any changes.
70 bool hasChanged() const;
71 void setRenameAcceptance(Vng::Acceptance accepted);
72 void setProtectionAcceptance(Vng::Acceptance accepted);
73 Vng::Acceptance renameAcceptance() const;
74 Vng::Acceptance protectionAcceptance() const;
76 void setBinary(bool binary);
77 bool isBinary() const;
79 void outputWhatsChanged(QTextStream &out, Configuration &config, bool printSummary, bool unified);
81 /// use the sha1s set to fetch the hunks.
82 void fetchHunks(bool againstHead);
83 /// remove the diff(s) stored in memory for this file, diff related method calls will no longer work after this.
84 void cleanHunksData();
86 File &operator=(const File &other);
87 bool operator==(const File &other) const;
88 bool operator!=(const File &other) const;
90 /**
91 * Calling this will check with the repo database if the path is registered in the repo.
92 * @returns true if the current repo and current HEAD know this commit, false otherwise.
94 static bool fileKnownToGit(const QFileInfo &path);
95 /// overloaded method provided for your convenience.
96 static bool fileKnownToGit(const QString &path);
98 private:
99 class Private;
100 Private * d;
103 #endif