Remove the Masterlist::Info struct

Just use MasterlistInfo, since it's used by the API already.
This commit is contained in:
Oliver Hamlet
2016-10-10 17:54:43 +01:00
parent f7cc42f945
commit bd13e011ee
7 changed files with 39 additions and 48 deletions
+1 -15
View File
@@ -114,21 +114,7 @@ bool ApiDatabase::UpdateMasterlist(const std::string& masterlistPath,
MasterlistInfo ApiDatabase::GetMasterlistRevision(const std::string& masterlistPath,
const bool getShortID) {
MasterlistInfo apiMasterlistInfo;
apiMasterlistInfo.is_modified = false;
Masterlist::Info info = Masterlist::GetInfo(masterlistPath, getShortID);
if (boost::ends_with(info.revision, " (edited)")) {
apiMasterlistInfo.revision_id = info.revision.substr(0, info.revision.length() - 9);
apiMasterlistInfo.revision_date = info.date.substr(0, info.date.length() - 9);
apiMasterlistInfo.is_modified = true;
} else {
apiMasterlistInfo.revision_id = info.revision;
apiMasterlistInfo.revision_date = info.date;
apiMasterlistInfo.is_modified = false;
}
return apiMasterlistInfo;
return Masterlist::GetInfo(masterlistPath, getShortID);
}
//////////////////////////
+6 -9
View File
@@ -37,10 +37,10 @@ using std::string;
namespace fs = boost::filesystem;
namespace loot {
Masterlist::Info Masterlist::GetInfo(const boost::filesystem::path& path, bool shortID) {
MasterlistInfo Masterlist::GetInfo(const boost::filesystem::path& path, bool shortID) {
// Compare HEAD and working copy, and get revision info.
GitHelper git;
Info info;
MasterlistInfo info;
git.SetErrorMessage((boost::format(translate("An error occurred while trying to read the local masterlist's version. If this error happens again, try deleting the \".git\" folder in %1%.")) % path.parent_path().string()).str());
if (!fs::exists(path)) {
@@ -61,10 +61,10 @@ Masterlist::Info Masterlist::GetInfo(const boost::filesystem::path& path, bool s
BOOST_LOG_TRIVIAL(trace) << "Generating hex string for Git object ID.";
if (shortID) {
git.Call(git_object_short_id(&git.GetData().buffer, git.GetData().object));
info.revision = git.GetData().buffer.ptr;
info.revision_id = git.GetData().buffer.ptr;
} else {
char c_rev[GIT_OID_HEXSZ + 1];
info.revision = git_oid_tostr(c_rev, GIT_OID_HEXSZ + 1, git_object_id(git.GetData().object));
info.revision_id = git_oid_tostr(c_rev, GIT_OID_HEXSZ + 1, git_object_id(git.GetData().object));
}
BOOST_LOG_TRIVIAL(trace) << "Getting date for Git object.";
@@ -74,13 +74,10 @@ Masterlist::Info Masterlist::GetInfo(const boost::filesystem::path& path, bool s
boost::locale::date_time dateTime(time);
std::stringstream out;
out << boost::locale::as::ftime("%Y-%m-%d") << dateTime;
info.date = out.str();
info.revision_date = out.str();
BOOST_LOG_TRIVIAL(trace) << "Diffing masterlist HEAD and working copy.";
if (GitHelper::IsFileDifferent(path.parent_path(), path.filename().string())) {
info.revision += string(" ") + translate("(edited)").str();
info.date += string(" ") + translate("(edited)").str();
}
info.is_modified = GitHelper::IsFileDifferent(path.parent_path(), path.filename().string());
return info;
}
+2 -6
View File
@@ -30,23 +30,19 @@
#include <boost/filesystem.hpp>
#include "backend/metadata_list.h"
#include "loot/struct/masterlist_info.h"
namespace loot {
class Game;
class Masterlist : public MetadataList {
public:
struct Info {
std::string revision;
std::string date;
};
bool Update(const Game& game);
bool Update(const boost::filesystem::path& path,
const std::string& repoURL,
const std::string& repoBranch);
static Info GetInfo(const boost::filesystem::path& path, bool shortID);
static MasterlistInfo GetInfo(const boost::filesystem::path& path, bool shortID);
};
}
+5 -3
View File
@@ -109,9 +109,11 @@ private:
YAML::Node convertMasterlistMetadata() {
YAML::Node masterlistNode;
try {
Masterlist::Info info = state_.getCurrentGame().GetMasterlist().GetInfo(state_.getCurrentGame().MasterlistPath(), true);
masterlistNode["revision"] = info.revision;
masterlistNode["date"] = info.date;
MasterlistInfo info = state_.getCurrentGame().GetMasterlist().GetInfo(state_.getCurrentGame().MasterlistPath(), true);
addSuffixIfModified(info);
masterlistNode["revision"] = info.revision_id;
masterlistNode["date"] = info.revision_date;
} catch (std::exception &e) {
masterlistNode["revision"] = e.what();
masterlistNode["date"] = e.what();
+7
View File
@@ -74,6 +74,13 @@ protected:
}
}
void addSuffixIfModified(MasterlistInfo& info) {
if (info.is_modified) {
info.revision_date += " " + boost::locale::translate("(edited)").str();
info.revision_id += " " + boost::locale::translate("(edited)").str();
}
}
private:
static void appendMessages(std::vector<Message>& destination,
const std::vector<Message>& source) {
+5 -3
View File
@@ -77,9 +77,11 @@ private:
void storeMasterlistMetadata(YAML::Node& gameMetadata) {
try {
Masterlist::Info info = game_.GetMasterlist().GetInfo(game_.MasterlistPath(), true);
gameMetadata["masterlist"]["revision"] = info.revision;
gameMetadata["masterlist"]["date"] = info.date;
MasterlistInfo info = game_.GetMasterlist().GetInfo(game_.MasterlistPath(), true);
addSuffixIfModified(info);
gameMetadata["masterlist"]["revision"] = info.revision_id;
gameMetadata["masterlist"]["date"] = info.revision_date;
} catch (std::exception& e) {
gameMetadata["masterlist"]["revision"] = e.what();
gameMetadata["masterlist"]["date"] = e.what();
+13 -12
View File
@@ -180,9 +180,10 @@ TEST_P(MasterlistTest, getInfoShouldReturnRevisionAndDateStringsOfTheCorrectLeng
repoUrl,
repoBranch));
Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(40, info.revision.length());
EXPECT_EQ(10, info.date.length());
MasterlistInfo info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(40, info.revision_id.length());
EXPECT_EQ(10, info.revision_date.length());
EXPECT_FALSE(info.is_modified);
}
TEST_P(MasterlistTest, getInfoShouldReturnRevisionAndDateStringsOfTheCorrectLengthsWhenRequestingAShortId) {
@@ -191,10 +192,11 @@ TEST_P(MasterlistTest, getInfoShouldReturnRevisionAndDateStringsOfTheCorrectLeng
repoUrl,
repoBranch));
Masterlist::Info info = masterlist.GetInfo(masterlistPath, true);
EXPECT_GE((unsigned)40, info.revision.length());
EXPECT_LE((unsigned)7, info.revision.length());
EXPECT_EQ(10, info.date.length());
MasterlistInfo info = masterlist.GetInfo(masterlistPath, true);
EXPECT_GE((unsigned)40, info.revision_id.length());
EXPECT_LE((unsigned)7, info.revision_id.length());
EXPECT_EQ(10, info.revision_date.length());
EXPECT_FALSE(info.is_modified);
}
TEST_P(MasterlistTest, getInfoShouldAppendSuffixesToReturnedStringsIfTheMasterlistHasBeenEdited) {
@@ -205,11 +207,10 @@ TEST_P(MasterlistTest, getInfoShouldAppendSuffixesToReturnedStringsIfTheMasterli
boost::filesystem::ofstream out(masterlistPath);
out.close();
Masterlist::Info info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(49, info.revision.length());
EXPECT_EQ(" (edited)", info.revision.substr(40));
EXPECT_EQ(19, info.date.length());
EXPECT_EQ(" (edited)", info.date.substr(10));
MasterlistInfo info = masterlist.GetInfo(masterlistPath, false);
EXPECT_EQ(40, info.revision_id.length());
EXPECT_EQ(10, info.revision_date.length());
EXPECT_TRUE(info.is_modified);
}
}
}