Make detection of empty repo also work after a git gc
[vng.git] / src / patches / Commit.h
blob32df8d7a02f95c2baed7d707e666905a0b0b8909
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/>.
18 #ifndef COMMIT_H
19 #define COMMIT_H
21 #include "../Vng.h"
23 #include <QString>
24 #include <QDateTime>
26 class CommitPrivate;
27 class ChangeSet;
28 class File;
30 /**
31 * A commit object represents a single change with an author/commit time etc.
33 class Commit
35 public:
36 /// default constructor creates an invalid commit object.
37 Commit();
38 Commit(const QString &treeism, const Commit &nextCommit = Commit());
39 Commit(const Commit &other);
40 ~Commit();
42 /// return an older commit
43 QList<Commit> previous();
44 /// return a commit made at a later time that has this one as its parent.
45 Commit next();
47 int previousCommitsCount() const;
49 QString author() const;
50 QString committer() const;
51 QByteArray logMessage() const;
52 /// The tree structure sha1, which is part of the commit.
53 QString tree() const;
54 /// the param passed to the constructor. This can be something like "HEAD"
55 QString commitTreeIsm() const;
57 /// similar to the previos but this will always return a sha1 whereas
58 // the commitTreeIsm can return a ref.
59 QString commitTreeIsmSha1() const;
62 QDateTime commitTime() const;
63 QDateTime authorTime() const;
65 /// available only when the diff provided it.
66 ChangeSet changeSet() const;
68 /// Clear references to the previousCommits, if this commit is the last user of the parent commits it will clean up some memory.
69 void clearParents();
71 Commit &operator=(const Commit &other);
72 bool operator==(const Commit &other);
74 Vng::Acceptance acceptance() const;
75 void setAcceptance(Vng::Acceptance accepted);
77 bool isValid() const;
79 /**
80 * Return the first commit on this branch.
81 * If this is head commit on a branch (not master), this will search for
82 * the first commit that both this branch and another branch share.
84 Commit firstCommitInBranch();
86 static Commit createFromStream(QIODevice *device);
87 /// lists all files in the whole repo at the given commit time.
88 static QList<File> allFiles(const QString &commitTreeIsm = QLatin1String("HEAD"));
90 protected:
91 Commit(CommitPrivate *priv);
92 void fillFromTreeIsm(const QString &treeIsm);
93 CommitPrivate * d;
95 private:
96 static Commit createFromStream(QIODevice *device, CommitPrivate *priv);
99 #endif