Wt examples  3.7.1
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 {
25 public:
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 {
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 
122 private:
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_
Definition: Git.h:59
ObjectId getCommitTree(const std::string &revision) const
Get the tree for a particular revision.
Definition: Git.C:207
Definition: Git.h:59
Git object Id.
Definition: Git.h:39
Git object.
Definition: Git.h:63
std::string name
Definition: Git.h:66
Git()
Constructor.
Definition: Git.C:197
std::list< std::pair< std::string, std::string > > Cache
Definition: Git.h:120
Git utility class for browsing git archives.
Definition: Git.h:24
ObjectId id
Definition: Git.h:64
std::string catFile(const ObjectId &id) const
Return the raw contents of a git object.
Definition: Git.C:213
ObjectType
Git object type.
Definition: Git.h:59
std::string repository_
The path to the repository.
Definition: Git.h:125
ObjectId getCommit(const std::string &revision) const
Get the commit for a particular revision.
Definition: Git.C:223
int getCmdResultLineCount(const std::string &cmd) const
Returns the number of lines in the output of a git command.
Definition: Git.C:324
void checkRepository() const
Checks the repository.
Definition: Git.C:342
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
Cache cache_
A small LRU cache that stores results of git commands.
Definition: Git.h:129
Exception(const std::string &msg)
Constructor.
Definition: Git.C:166
ObjectId getTreeFromCommit(const ObjectId &commit) const
Get the tree for a particular commit.
Definition: Git.C:230
Object treeGetObject(const ObjectId &tree, int index) const
Get some info on a tree object.
Definition: Git.C:245
Exception class.
Definition: Git.h:28
int treeSize(const ObjectId &tree) const
Return the number of objects inside a tree object.
Definition: Git.C:279
ObjectType type
Definition: Git.h:65
void setRepositoryPath(const std::string &repository)
Set the git repository path.
Definition: Git.C:201

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13