Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jan 17, 2024
1 parent d233b72 commit 5796f72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 112 deletions.
98 changes: 2 additions & 96 deletions src/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ void Git::CommitID::assign(const QString &qid)
}
}



QString Git::CommitID::toQString(int maxlen) const
{
if (valid) {
Expand Down Expand Up @@ -656,7 +654,6 @@ QList<Git::Branch> Git::branches()
}
}
}
// pos = text.indexOf(')');
if (pos > 1) {
name = text.mid(1, pos - 1);
pos++;
Expand Down Expand Up @@ -828,10 +825,10 @@ Git::CommitItemList Git::log_all(QString const &id, int maxcount)
*
* コミットに関連する署名情報を取得する
*/
std::optional<Git::CommitItem> Git::log_signature(QString const &id)
std::optional<Git::CommitItem> Git::log_signature(CommitID const &id)
{
QString cmd = "log -1 --show-signature --pretty=format:\"id:%H#gpg:%G?#key:%GF#sub:%GP#trust:%GT##%s\" %1";
cmd = cmd.arg(id);
cmd = cmd.arg(id.toQString());
git(cmd);
if (getProcessExitCode() == 0) {
QString gpgtext;
Expand All @@ -855,43 +852,6 @@ std::optional<Git::CommitItem> Git::log_signature(QString const &id)
return std::nullopt;
}

/**
* @brief Git::log_show_signature
* @param id コミットID
* @return
*
* コミットに署名が付いている場合は署名情報を返す
*/
std::optional<Git::Signature_> Git::log_show_signature_(CommitID const &id)
{
QString cmd = "log --show-signature -1 %1";
cmd = cmd.arg(id.toQString());
if (git(cmd, true)) {
bool gpg = false;
Git::Signature_ sig;
std::vector<std::string> lines;
{
std::string text = resultStdString();
misc::splitLines(text, &lines, false);
}
for (int i = 0; i < lines.size(); i++) {
std::string const &line = lines[i];
if (strncmp(line.c_str(), "gpg:", 4) == 0) {
gpg = true;
if (!sig.text.empty()) {
sig.text += '\n';
}
sig.text += line;
if (strstr(line.c_str(), "signature from")) {
parseSignatureFrom(line, &sig);
}
}
}
if (gpg) return sig;
}
return std::nullopt;
}

Git::CommitItemList Git::log(int maxcount)
{
return log_all(QString(), maxcount);
Expand Down Expand Up @@ -975,60 +935,6 @@ Git::CommitItem Git::parseCommit(QByteArray const &ba)
return out;
}

void Git::parseSignatureFrom(std::string_view const &line, Git::Signature_ *sig)
{
static const std::string sig_good = "Good signature from";
static const std::string sig_bad = "BAD signature from";

// status
auto i = line.find(sig_good);
if (i != std::string::npos) {
sig->status = Git::Signature_::Good;
i += sig_good.size();
} else {
i = line.find(sig_bad);
if (i != std::string::npos) {
sig->status = Git::Signature_::BAD;
i += sig_bad.size();
}
}

if (i != std::string::npos) {
std::string_view s = line.substr(i);
s = misc::trimmed(s);
// trust
i = s.find("[");
if (i != std::string::npos) {
std::string_view trust = s.substr(i + 1);
auto j = trust.find(']');
if (j != std::string::npos) {
trust = trust.substr(0, j);
sig->trust = trust;
}
s = s.substr(0, i);
}
s = misc::trimmed(s);
// remove quotes
if (s.size() >= 2 && s[0] == '"' && s[s.size() - 1] == '"') {
s = s.substr(1, s.size() - 2);
}
// name and mail
i = s.find('<');
if (i != std::string::npos) {
std::string_view name = s.substr(0, i);
sig->name = misc::trimmed(name);
std::string_view mail = s.substr(i + 1);
i = mail.find('>');
if (i != std::string::npos) {
mail = mail.substr(0, i);
if (mail.find('@') != std::string::npos) {
sig->mail = misc::trimmed(mail);
}
}
}
}
}

std::optional<Git::CommitItem> Git::queryCommit(CommitID const &id)
{
Git::CommitItem ret;
Expand Down
17 changes: 1 addition & 16 deletions src/Git.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,6 @@ class Git : QObject {
};
using CommitItemList = std::vector<CommitItem>;

struct Signature_ {
enum Status {
No,
BAD,
Good,
};
Status status = No;
std::string text;
std::string name;
std::string mail;
std::string trust; // marginal, full, ultimate, ...
};

class Hunk {
public:
std::string at;
Expand Down Expand Up @@ -396,9 +383,8 @@ class Git : QObject {
bool init();
QStringList getUntrackedFiles();
CommitItemList log_all(QString const &id, int maxcount);
std::optional<CommitItem> log_signature(const QString &id);
std::optional<CommitItem> log_signature(CommitID const &id);
CommitItemList log(int maxcount);
std::optional<Git::Signature_> log_show_signature_(CommitID const &id);
std::optional<CommitItem> queryCommit(const CommitID &id);

struct CloneData {
Expand Down Expand Up @@ -563,7 +549,6 @@ class Git : QObject {
bool submodule_add(const CloneData &data, bool force, AbstractPtyProcess *pty);
bool submodule_update(const SubmoduleUpdateData &data, AbstractPtyProcess *pty);
static CommitItem parseCommit(const QByteArray &ba);
static void parseSignatureFrom(std::string_view const &line, Git::Signature_ *sig);
};

struct NamedCommitItem {
Expand Down

0 comments on commit 5796f72

Please sign in to comment.