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