File indexing completed on 2025-03-09 05:11:41
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "stash.h" 0008 #include "entities/commit.h" 0009 0010 #include "gitmanager.h" 0011 #include <utility> 0012 0013 #include <git2/stash.h> 0014 namespace Git 0015 { 0016 Stash::Stash(Manager *git, QString name) 0017 : mGit(git) 0018 , mMessage(std::move(name)) 0019 { 0020 } 0021 0022 Stash::Stash(size_t index, git_repository *repo, const char *message, const git_oid *stash_id) 0023 : mIndex{index} 0024 { 0025 git_commit *commit = NULL; 0026 0027 git_commit_lookup(&commit, repo, stash_id); 0028 mCommit.reset(new Commit{commit}); 0029 0030 mSubject = git_commit_body(commit); 0031 0032 mMessage = message; 0033 0034 mSubject = QString{git_commit_message(commit)}.replace("\n", ""); 0035 0036 mCommitHash = git_oid_tostr_s(stash_id); 0037 } 0038 0039 Stash::~Stash() 0040 { 0041 if (ptr) 0042 git_commit_free(ptr); 0043 } 0044 0045 const QString &Stash::message() const 0046 { 0047 return mMessage; 0048 } 0049 0050 const QString &Stash::subject() const 0051 { 0052 return mSubject; 0053 } 0054 0055 QSharedPointer<Commit> Stash::commit() const 0056 { 0057 return mCommit; 0058 } 0059 0060 QString Stash::commitHash() const 0061 { 0062 return mCommitHash; 0063 } 0064 0065 size_t Stash::index() const 0066 { 0067 return mIndex; 0068 } 0069 0070 } // namespace Git