Wt examples: gitmodel/Git.h Source File

Wt examples 4.10.4

Loading...
Searching...
No Matches
Git.h
Go to the documentation of this file.
1// This may look like C code, but it's really -*- C++ -*-
2/*
3 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7#ifndef GIT_H_
8#define GIT_H_
9
10#include <stdexcept>
11#include <list>
12#include <boost/array.hpp>
13#include <string>
14
19
24 class Git {
25public:
28 class Exception : public std::runtime_error {
29 public:
32 Exception(const std::string& msg);
33 };
34
39 class ObjectId : public boost::array<unsigned char, 20> {
40 public:
43 ObjectId();
44
50 explicit ObjectId(const std::string& id);
51
54 std::string toString() const;
55 };
56
59 enum ObjectType { Tree, Commit, Blob };
60
63 struct Object {
64 ObjectId id;
65 ObjectType type;
66 std::string name;
67
68 Object(const ObjectId& id, ObjectType type);
69 };
70
73 Git();
74
79 void setRepositoryPath(const std::string& repository);
80
85 ObjectId getCommitTree(const std::string& revision) const;
86
91 ObjectId getCommit(const std::string& revision) const;
92
97 ObjectId getTreeFromCommit(const ObjectId& commit) const;
98
106 Object treeGetObject(const ObjectId& tree, int index) const;
107
112 int treeSize(const ObjectId& tree) const;
113
118 std::string catFile(const ObjectId& id) const;
119
120 typedef std::list<std::pair<std::string, std::string> > Cache;
121
122private:
125 std::string baseCmd() const;
126
129 bool is_bare_;
130
133 std::string repository_;
134
137 mutable Cache cache_;
138
143 void checkRepository() const;
144
153 bool getCmdResult(const std::string& cmd, std::string& result,
154 const std::string& tag) const;
155
164 bool getCmdResult(const std::string& cmd, std::string& result,
165 int index) const;
166
171 int getCmdResultLineCount(const std::string& cmd) const;
172};
173
176#endif // GIT_H_
Git::Exception
Exception class.
Definition Git.h:28
Git::Exception::Exception
Exception(const std::string &msg)
Constructor.
Definition Git.C:169
Git::ObjectId
Git object Id.
Definition Git.h:39
Git::ObjectId::toString
std::string toString() const
Print as a 40-digit hexadecimal number.
Definition Git.C:185
Git::ObjectId::ObjectId
ObjectId()
Default constructor.
Definition Git.C:173
Git
Git utility class for browsing git archives.
Definition Git.h:24
Git::cache_
Cache cache_
A small LRU cache that stores results of git commands.
Definition Git.h:137
Git::getCommit
ObjectId getCommit(const std::string &revision) const
Get the commit for a particular revision.
Definition Git.C:230
Git::repository_
std::string repository_
The path to the repository.
Definition Git.h:133
Git::getTreeFromCommit
ObjectId getTreeFromCommit(const ObjectId &commit) const
Get the tree for a particular commit.
Definition Git.C:237
Git::catFile
std::string catFile(const ObjectId &id) const
Return the raw contents of a git object.
Definition Git.C:220
Git::getCmdResultLineCount
int getCmdResultLineCount(const std::string &cmd) const
Returns the number of lines in the output of a git command.
Definition Git.C:340
Git::is_bare_
bool is_bare_
Whether the repositoy is a bare repository.
Definition Git.h:129
Git::treeGetObject
Object treeGetObject(const ObjectId &tree, int index) const
Get some info on a tree object.
Definition Git.C:252
Git::checkRepository
void checkRepository() const
Checks the repository.
Definition Git.C:358
Git::treeSize
int treeSize(const ObjectId &tree) const
Return the number of objects inside a tree object.
Definition Git.C:286
Git::setRepositoryPath
void setRepositoryPath(const std::string &repository)
Set the git repository path.
Definition Git.C:205
Git::ObjectType
ObjectType
Git object type.
Definition Git.h:59
Git::Commit
@ Commit
Definition Git.h:59
Git::Blob
@ Blob
Definition Git.h:59
Git::Tree
@ Tree
Definition Git.h:59
Git::getCmdResult
bool getCmdResult(const std::string &cmd, std::string &result, const std::string &tag) const
Returns a line identified by a tag from the output of a git command.
Definition Git.C:323
Git::baseCmd
std::string baseCmd() const
The git base command after which extra arguments are added.
Definition Git.C:291
Git::getCommitTree
ObjectId getCommitTree(const std::string &revision) const
Get the tree for a particular revision.
Definition Git.C:214
Git::Cache
std::list< std::pair< std::string, std::string > > Cache
Definition Git.h:120
Git::Git
Git()
Constructor.
Definition Git.C:200
Git::Object
Git object.
Definition Git.h:63
Git::Object::Object
Object(const ObjectId &id, ObjectType type)
Definition Git.C:195
Git::Object::id
ObjectId id
Definition Git.h:64
Git::Object::type
ObjectType type
Definition Git.h:65
Git::Object::name
std::string name
Definition Git.h:66