1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_SWISSKNIFE_HISTORY_H_ |
6 |
|
|
#define CVMFS_SWISSKNIFE_HISTORY_H_ |
7 |
|
|
|
8 |
|
|
#include <string> |
9 |
|
|
#include <vector> |
10 |
|
|
|
11 |
|
|
#include "hash.h" |
12 |
|
|
#include "history_sqlite.h" |
13 |
|
|
#include "swissknife.h" |
14 |
|
|
#include "util_concurrency.h" |
15 |
|
|
|
16 |
|
|
namespace manifest { |
17 |
|
|
class Manifest; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
namespace catalog { |
21 |
|
|
class Catalog; |
22 |
|
|
class WritableCatalog; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
namespace upload { |
26 |
|
|
struct SpoolerDefinition; |
27 |
|
|
struct SpoolerResult; |
28 |
|
|
class Spooler; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
namespace swissknife { |
32 |
|
|
|
33 |
|
|
class CommandTag : public Command { |
34 |
|
|
public: |
35 |
|
|
static const std::string kHeadTag; |
36 |
|
|
static const std::string kHeadTagDescription; |
37 |
|
|
static const std::string kPreviousHeadTag; |
38 |
|
|
static const std::string kPreviousHeadTagDescription; |
39 |
|
|
|
40 |
|
|
CommandTag() { } |
41 |
|
|
|
42 |
|
|
protected: |
43 |
|
|
typedef std::vector<history::History::Tag> TagList; |
44 |
|
|
typedef std::vector<history::History::Branch> BranchList; |
45 |
|
|
|
46 |
|
|
struct Environment { |
47 |
|
|
Environment(const std::string &repository_url, |
48 |
|
|
const std::string &tmp_path) : |
49 |
|
|
repository_url(repository_url), tmp_path(tmp_path) {} |
50 |
|
|
|
51 |
|
|
const std::string repository_url; |
52 |
|
|
const std::string tmp_path; |
53 |
|
|
|
54 |
|
|
UnlinkGuard manifest_path; |
55 |
|
|
UniquePtr<manifest::Manifest> manifest; |
56 |
|
|
UniquePtr<manifest::Manifest> previous_manifest; |
57 |
|
|
UniquePtr<history::History> history; |
58 |
|
|
UniquePtr<upload::Spooler> spooler; |
59 |
|
|
UnlinkGuard history_path; |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
Environment* InitializeEnvironment(const ArgumentList &args, |
64 |
|
|
const bool read_write); |
65 |
|
|
bool CloseAndPublishHistory(Environment *environment); |
66 |
|
|
bool UploadCatalogAndUpdateManifest(Environment *env, |
67 |
|
|
catalog::WritableCatalog *catalog); |
68 |
|
|
void UploadClosure(const upload::SpoolerResult &result, |
69 |
|
|
Future<shash::Any> *hash); |
70 |
|
|
|
71 |
|
|
bool UpdateUndoTags(Environment *env, |
72 |
|
|
const history::History::Tag ¤t_head_template, |
73 |
|
|
const bool undo_rollback = false); |
74 |
|
|
|
75 |
|
|
// TODO(jblomer): replace by swissknife::Assistant |
76 |
|
|
bool FetchObject(const std::string &repository_url, |
77 |
|
|
const shash::Any &object_hash, |
78 |
|
|
const std::string &destination_path) const; |
79 |
|
|
history::History* GetHistory(const manifest::Manifest *manifest, |
80 |
|
|
const std::string &repository_url, |
81 |
|
|
const std::string &history_path, |
82 |
|
|
const bool read_write) const; |
83 |
|
|
|
84 |
|
|
catalog::Catalog* GetCatalog(const std::string &repository_url, |
85 |
|
|
const shash::Any &catalog_hash, |
86 |
|
|
const std::string catalog_path, |
87 |
|
|
const bool read_write) const; |
88 |
|
|
|
89 |
|
|
void PrintTagMachineReadable(const history::History::Tag &tag) const; |
90 |
|
|
|
91 |
|
|
std::string AddPadding(const std::string &str, |
92 |
|
|
const size_t padding, |
93 |
|
|
const bool align_right = false, |
94 |
|
|
const std::string &fill_char = " ") const; |
95 |
|
|
|
96 |
|
|
bool IsUndoTagName(const std::string &tag_name) const; |
97 |
|
|
}; |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
//------------------------------------------------------------------------------ |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
/** |
104 |
|
|
* If -a and -d are specified, removal of tags takes place before the new tag is |
105 |
|
|
* added. |
106 |
|
|
*/ |
107 |
|
|
class CommandEditTag : public CommandTag { |
108 |
|
|
public: |
109 |
|
|
virtual std::string GetName() const { return "tag_edit"; } |
110 |
|
|
virtual std::string GetDescription() const { |
111 |
|
|
return "Create a tag and/or remove tags."; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
virtual ParameterList GetParams() const; |
115 |
|
|
int Main(const ArgumentList &args); |
116 |
|
|
|
117 |
|
|
protected: |
118 |
|
|
int RemoveTags(const ArgumentList &args, Environment *env); |
119 |
|
|
int AddNewTag(const ArgumentList &args, Environment *env); |
120 |
|
|
|
121 |
|
|
shash::Any GetTagRootHash(Environment *env, |
122 |
|
|
const std::string &root_hash_string) const; |
123 |
|
|
bool ManipulateTag(Environment *env, |
124 |
|
|
const history::History::Tag &tag_template, |
125 |
|
|
const bool user_provided_hash); |
126 |
|
|
bool MoveTag(Environment *env, |
127 |
|
|
const history::History::Tag &tag_template); |
128 |
|
|
bool CreateTag(Environment *env, |
129 |
|
|
const history::History::Tag &new_tag); |
130 |
|
|
}; |
131 |
|
|
|
132 |
|
|
|
133 |
|
|
//------------------------------------------------------------------------------ |
134 |
|
|
|
135 |
|
|
|
136 |
|
|
class CommandListTags : public CommandTag { |
137 |
|
|
public: |
138 |
|
|
virtual std::string GetName() const { return "tag_list"; } |
139 |
|
|
virtual std::string GetDescription() const { |
140 |
|
|
return "List tags in the tag database."; |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
virtual ParameterList GetParams() const; |
144 |
|
|
int Main(const ArgumentList &args); |
145 |
|
|
|
146 |
|
|
protected: |
147 |
|
|
struct BranchLevel { |
148 |
|
|
BranchLevel() : branch(), level(0) { } |
149 |
|
|
BranchLevel(const history::History::Branch &b, unsigned l) |
150 |
|
|
: branch(b), level(l) { } |
151 |
|
|
history::History::Branch branch; |
152 |
|
|
unsigned level; |
153 |
|
|
}; |
154 |
|
|
typedef std::vector<BranchLevel> BranchHierarchy; |
155 |
|
|
|
156 |
|
|
void SortBranchesRecursively(unsigned level, |
157 |
|
|
const std::string &parent_branch, |
158 |
|
|
const BranchList &branches, |
159 |
|
|
BranchHierarchy *hierarchy) const; |
160 |
|
|
BranchHierarchy SortBranches(const BranchList &branches) const; |
161 |
|
|
|
162 |
|
|
void PrintHumanReadableTagList(const TagList &tags) const; |
163 |
|
|
void PrintMachineReadableTagList(const TagList &tags) const; |
164 |
|
|
void PrintHumanReadableBranchList(const BranchHierarchy &branches) const; |
165 |
|
|
void PrintMachineReadableBranchList(const BranchHierarchy &branches) const; |
166 |
|
|
}; |
167 |
|
|
|
168 |
|
|
|
169 |
|
|
//------------------------------------------------------------------------------ |
170 |
|
|
|
171 |
|
|
|
172 |
|
|
class CommandInfoTag : public CommandTag { |
173 |
|
|
public: |
174 |
|
|
virtual std::string GetName() const { return "tag_info"; } |
175 |
|
|
virtual std::string GetDescription() const { |
176 |
|
|
return "Obtain detailed information about a tag."; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
virtual ParameterList GetParams() const; |
180 |
|
|
int Main(const ArgumentList &args); |
181 |
|
|
|
182 |
|
|
protected: |
183 |
|
|
std::string HumanReadableFilesize(const size_t filesize) const; |
184 |
|
|
void PrintHumanReadableInfo(const history::History::Tag &tag) const; |
185 |
|
|
}; |
186 |
|
|
|
187 |
|
|
|
188 |
|
|
//------------------------------------------------------------------------------ |
189 |
|
|
|
190 |
|
|
|
191 |
|
|
class CommandRollbackTag : public CommandTag { |
192 |
|
|
public: |
193 |
|
|
virtual std::string GetName() const { return "tag_rollback"; } |
194 |
|
|
virtual std::string GetDescription() const { |
195 |
|
|
return "Rollback repository to a given tag."; |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
virtual ParameterList GetParams() const; |
199 |
|
|
int Main(const ArgumentList &args); |
200 |
|
|
|
201 |
|
|
protected: |
202 |
|
|
void PrintDeletedTagList(const TagList &tags) const; |
203 |
|
|
}; |
204 |
|
|
|
205 |
|
|
|
206 |
|
|
//------------------------------------------------------------------------------ |
207 |
|
|
|
208 |
|
|
|
209 |
|
|
class CommandEmptyRecycleBin : public CommandTag { |
210 |
|
|
public: |
211 |
|
|
virtual std::string GetName() const { return "tag_empty_bin"; } |
212 |
|
|
virtual std::string GetDescription() const { |
213 |
|
|
return "Empty the internal recycle bin of the history database."; |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
virtual ParameterList GetParams() const; |
217 |
|
|
int Main(const ArgumentList &args); |
218 |
|
|
}; |
219 |
|
|
|
220 |
|
|
} // namespace swissknife |
221 |
|
|
|
222 |
|
|
#endif // CVMFS_SWISSKNIFE_HISTORY_H_ |