GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/swissknife_history.h
Date: 2026-06-28 02:36:10
Exec Total Coverage
Lines: 0 20 0.0%
Branches: 0 30 0.0%

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.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 &current_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 int CleanupOldAutoTags(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, const history::History::Tag &tag_template);
127 bool CreateTag(Environment *env, const history::History::Tag &new_tag);
128 };
129
130
131 //------------------------------------------------------------------------------
132
133
134 class CommandListTags : public CommandTag {
135 public:
136 virtual std::string GetName() const { return "tag_list"; }
137 virtual std::string GetDescription() const {
138 return "List tags in the tag database.";
139 }
140
141 virtual ParameterList GetParams() const;
142 int Main(const ArgumentList &args);
143
144 protected:
145 struct BranchLevel {
146 BranchLevel() : branch(), level(0) { }
147 BranchLevel(const history::History::Branch &b, unsigned l)
148 : branch(b), level(l) { }
149 history::History::Branch branch;
150 unsigned level;
151 };
152 typedef std::vector<BranchLevel> BranchHierarchy;
153
154 void SortBranchesRecursively(unsigned level,
155 const std::string &parent_branch,
156 const BranchList &branches,
157 BranchHierarchy *hierarchy) const;
158 BranchHierarchy SortBranches(const BranchList &branches) const;
159
160 void PrintHumanReadableTagList(const TagList &tags) const;
161 void PrintMachineReadableTagList(const TagList &tags) const;
162 void PrintHumanReadableBranchList(const BranchHierarchy &branches) const;
163 void PrintMachineReadableBranchList(const BranchHierarchy &branches) const;
164 };
165
166
167 //------------------------------------------------------------------------------
168
169
170 class CommandInfoTag : public CommandTag {
171 public:
172 virtual std::string GetName() const { return "tag_info"; }
173 virtual std::string GetDescription() const {
174 return "Obtain detailed information about a tag.";
175 }
176
177 virtual ParameterList GetParams() const;
178 int Main(const ArgumentList &args);
179
180 protected:
181 std::string HumanReadableFilesize(const size_t filesize) const;
182 void PrintHumanReadableInfo(const history::History::Tag &tag) const;
183 };
184
185
186 //------------------------------------------------------------------------------
187
188
189 class CommandRollbackTag : public CommandTag {
190 public:
191 virtual std::string GetName() const { return "tag_rollback"; }
192 virtual std::string GetDescription() const {
193 return "Rollback repository to a given tag.";
194 }
195
196 virtual ParameterList GetParams() const;
197 int Main(const ArgumentList &args);
198
199 protected:
200 void PrintDeletedTagList(const TagList &tags) const;
201 };
202
203
204 //------------------------------------------------------------------------------
205
206
207 class CommandEmptyRecycleBin : public CommandTag {
208 public:
209 virtual std::string GetName() const { return "tag_empty_bin"; }
210 virtual std::string GetDescription() const {
211 return "Empty the internal recycle bin of the history database.";
212 }
213
214 virtual ParameterList GetParams() const;
215 int Main(const ArgumentList &args);
216 };
217
218 } // namespace swissknife
219
220 #endif // CVMFS_SWISSKNIFE_HISTORY_H_
221