|
Wt examples
3.3.5
|
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 #include <string> 00014 00019 00024 class Git { 00025 public: 00028 class Exception : public std::runtime_error { 00029 public: 00032 Exception(const std::string& msg); 00033 }; 00034 00039 class ObjectId : public boost::array<unsigned char, 20> { 00040 public: 00043 ObjectId(); 00044 00050 explicit ObjectId(const std::string& id); 00051 00054 std::string toString() const; 00055 }; 00056 00059 enum ObjectType { Tree, Commit, Blob }; 00060 00063 struct Object { 00064 ObjectId id; 00065 ObjectType type; 00066 std::string name; 00067 00068 Object(const ObjectId& id, ObjectType type); 00069 }; 00070 00073 Git(); 00074 00079 void setRepositoryPath(const std::string& repository); 00080 00085 ObjectId getCommitTree(const std::string& revision) const; 00086 00091 ObjectId getCommit(const std::string& revision) const; 00092 00097 ObjectId getTreeFromCommit(const ObjectId& commit) const; 00098 00106 Object treeGetObject(const ObjectId& tree, int index) const; 00107 00112 int treeSize(const ObjectId& tree) const; 00113 00118 std::string catFile(const ObjectId& id) const; 00119 00120 typedef std::list<std::pair<std::string, std::string> > Cache; 00121 00122 private: 00125 std::string repository_; 00126 00129 mutable Cache cache_; 00130 00135 void checkRepository() const; 00136 00145 bool getCmdResult(const std::string& cmd, std::string& result, 00146 const std::string& tag) const; 00147 00156 bool getCmdResult(const std::string& cmd, std::string& result, 00157 int index) const; 00158 00163 int getCmdResultLineCount(const std::string& cmd) const; 00164 }; 00165 00168 #endif // GIT_H_
1.7.6.1