Wt examples  3.3.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 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 
18 
23 class Git {
24 public:
27  class Exception : public std::runtime_error {
28  public:
31  Exception(const std::string& msg);
32  };
33 
38  class ObjectId : public boost::array<unsigned char, 20> {
39  public:
42  ObjectId();
43 
49  explicit ObjectId(const std::string& id);
50 
53  std::string toString() const;
54  };
55 
58  enum ObjectType { Tree, Commit, Blob };
59 
62  struct Object {
65  std::string name;
66 
67  Object(const ObjectId& id, ObjectType type);
68  };
69 
72  Git();
73 
78  void setRepositoryPath(const std::string& repository);
79 
84  ObjectId getCommitTree(const std::string& revision) const;
85 
90  ObjectId getCommit(const std::string& revision) const;
91 
96  ObjectId getTreeFromCommit(const ObjectId& commit) const;
97 
105  Object treeGetObject(const ObjectId& tree, int index) const;
106 
111  int treeSize(const ObjectId& tree) const;
112 
117  std::string catFile(const ObjectId& id) const;
118 
119  typedef std::list<std::pair<std::string, std::string> > Cache;
120 
121 private:
124  std::string repository_;
125 
128  mutable Cache cache_;
129 
134  void checkRepository() const;
135 
144  bool getCmdResult(const std::string& cmd, std::string& result,
145  const std::string& tag) const;
146 
155  bool getCmdResult(const std::string& cmd, std::string& result,
156  int index) const;
157 
162  int getCmdResultLineCount(const std::string& cmd) const;
163 };
164 
167 #endif // GIT_H_
Definition: Git.h:58
void checkRepository() const
Checks the repository.
Definition: Git.C:323
int getCmdResultLineCount(const std::string &cmd) const
Returns the number of lines in the output of a git command.
Definition: Git.C:305
Object(const ObjectId &id, ObjectType type)
Definition: Git.C:173
int treeSize(const ObjectId &tree) const
Return the number of objects inside a tree object.
Definition: Git.C:260
Definition: Git.h:58
Object treeGetObject(const ObjectId &tree, int index) const
Get some info on a tree object.
Definition: Git.C:226
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:288
Git object Id.
Definition: Git.h:38
std::string toString() const
Print as a 40-digit hexadecimal number.
Definition: Git.C:163
Git object.
Definition: Git.h:62
std::string name
Definition: Git.h:65
Git()
Constructor.
Definition: Git.C:178
std::list< std::pair< std::string, std::string > > Cache
Definition: Git.h:119
Git utility class for browsing git archives.
Definition: Git.h:23
ObjectId id
Definition: Git.h:63
ObjectId getCommit(const std::string &revision) const
Get the commit for a particular revision.
Definition: Git.C:204
ObjectType
Git object type.
Definition: Git.h:58
std::string repository_
The path to the repository.
Definition: Git.h:124
Cache cache_
A small LRU cache that stores results of git commands.
Definition: Git.h:128
ObjectId getTreeFromCommit(const ObjectId &commit) const
Get the tree for a particular commit.
Definition: Git.C:211
Exception(const std::string &msg)
Constructor.
Definition: Git.C:147
ObjectId()
Default constructor.
Definition: Git.C:151
ObjectId getCommitTree(const std::string &revision) const
Get the tree for a particular revision.
Definition: Git.C:188
Exception class.
Definition: Git.h:27
ObjectType type
Definition: Git.h:64
std::string catFile(const ObjectId &id) const
Return the raw contents of a git object.
Definition: Git.C:194
void setRepositoryPath(const std::string &repository)
Set the git repository path.
Definition: Git.C:182

Generated on Wed Jun 11 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.7