Wt examples
3.2.3
|
00001 // This may look like C code, but it's really -*- C++ -*- 00002 /* 00003 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium. 00004 * 00005 * See the LICENSE file for terms of use. 00006 */ 00007 #ifndef GIT_H_ 00008 #define GIT_H_ 00009 00010 #include <stdexcept> 00011 #include <list> 00012 #include <boost/array.hpp> 00013 00018 00023 class Git { 00024 public: 00027 class Exception : public std::runtime_error { 00028 public: 00031 Exception(const std::string& msg); 00032 }; 00033 00038 class ObjectId : public boost::array<unsigned char, 20> { 00039 public: 00042 ObjectId(); 00043 00049 explicit ObjectId(const std::string& id); 00050 00053 std::string toString() const; 00054 }; 00055 00058 enum ObjectType { Tree, Commit, Blob }; 00059 00062 struct Object { 00063 ObjectId id; 00064 ObjectType type; 00065 std::string name; 00066 00067 Object(const ObjectId& id, ObjectType type); 00068 }; 00069 00072 Git(); 00073 00078 void setRepositoryPath(const std::string& repository); 00079 00084 ObjectId getCommitTree(const std::string& revision) const; 00085 00090 ObjectId getCommit(const std::string& revision) const; 00091 00096 ObjectId getTreeFromCommit(const ObjectId& commit) const; 00097 00105 Object treeGetObject(const ObjectId& tree, int index) const; 00106 00111 int treeSize(const ObjectId& tree) const; 00112 00117 std::string catFile(const ObjectId& id) const; 00118 00119 typedef std::list<std::pair<std::string, std::string> > Cache; 00120 00121 private: 00124 std::string repository_; 00125 00128 mutable Cache cache_; 00129 00134 void checkRepository() const; 00135 00144 bool getCmdResult(const std::string& cmd, std::string& result, 00145 const std::string& tag) const; 00146 00155 bool getCmdResult(const std::string& cmd, std::string& result, 00156 int index) const; 00157 00162 int getCmdResultLineCount(const std::string& cmd) const; 00163 }; 00164 00167 #endif // GIT_H_