Wt examples 3.3.12
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 bvba, Kessel-Lo, 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
24class 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
60
63 struct Object {
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 repository_;
126
129 mutable Cache cache_;
130
135 void checkRepository() const;
136
145 bool getCmdResult(const std::string& cmd, std::string& result,
146 const std::string& tag) const;
147
156 bool getCmdResult(const std::string& cmd, std::string& result,
157 int index) const;
158
163 int getCmdResultLineCount(const std::string& cmd) const;
164};
165
168#endif // GIT_H_
Exception class.
Definition Git.h:28
Git object Id.
Definition Git.h:39
std::string toString() const
Print as a 40-digit hexadecimal number.
Definition Git.C:182
ObjectId()
Default constructor.
Definition Git.C:170
Git utility class for browsing git archives.
Definition Git.h:24
Cache cache_
A small LRU cache that stores results of git commands.
Definition Git.h:129
std::list< std::pair< std::string, std::string > > Cache
Definition Git.h:120
ObjectId getCommit(const std::string &revision) const
Get the commit for a particular revision.
Definition Git.C:223
std::string repository_
The path to the repository.
Definition Git.h:125
ObjectId getTreeFromCommit(const ObjectId &commit) const
Get the tree for a particular commit.
Definition Git.C:230
std::string catFile(const ObjectId &id) const
Return the raw contents of a git object.
Definition Git.C:213
int getCmdResultLineCount(const std::string &cmd) const
Returns the number of lines in the output of a git command.
Definition Git.C:324
Object treeGetObject(const ObjectId &tree, int index) const
Get some info on a tree object.
Definition Git.C:245
void checkRepository() const
Checks the repository.
Definition Git.C:342
int treeSize(const ObjectId &tree) const
Return the number of objects inside a tree object.
Definition Git.C:279
void setRepositoryPath(const std::string &repository)
Set the git repository path.
Definition Git.C:201
ObjectType
Git object type.
Definition Git.h:59
@ Commit
Definition Git.h:59
@ Blob
Definition Git.h:59
@ Tree
Definition Git.h:59
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:307
ObjectId getCommitTree(const std::string &revision) const
Get the tree for a particular revision.
Definition Git.C:207
Git()
Constructor.
Definition Git.C:197
Git object.
Definition Git.h:63
ObjectId id
Definition Git.h:64
ObjectType type
Definition Git.h:65
std::string name
Definition Git.h:66

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8