From 63341a2d23cc36309cc6be3743e21255ba7218ce Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Sat, 18 Oct 2008 18:41:50 +0200 Subject: [PATCH] Add a setter on Record --- src/AbstractCommand.h | 1 + src/commands/Record.cpp | 12 ++++++++---- src/commands/Record.h | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 5bf9512..ebdb71d 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -42,6 +42,7 @@ public: NotInRepo, WriteError, OtherVngError, + UserCancelled, GitCrashed = 10, GitFailed, GitTimedOut diff --git a/src/commands/Record.cpp b/src/commands/Record.cpp index f927931..59814a9 100644 --- a/src/commands/Record.cpp +++ b/src/commands/Record.cpp @@ -57,7 +57,8 @@ static const CommandLineOption options[] = { Record::Record() : AbstractCommand("record"), - m_mode(Unset) + m_mode(Unset), + m_editComment(false) { CommandLineParser::addOptionDefinitions(options); CommandLineParser::setArgumentDefinition("record [FILE or DIRECTORY]" ); @@ -163,7 +164,7 @@ AbstractCommand::ReturnCodes Record::run() if (dryRun()) return Ok; - if (m_patchName.isEmpty() && getenv("EDITOR")) { + if ((m_editComment || m_patchName.isEmpty()) && getenv("EDITOR")) { class Deleter : public QObject { public: Deleter() : commitMessage(0) { } @@ -187,7 +188,10 @@ AbstractCommand::ReturnCodes Record::run() } const char * defaultCommitMessage1 = "\n***END OF DESCRIPTION***"; // we will look for this string later const char * defaultCommitMessage2 = "\nPlace the long patch description above the ***END OF DESCRIPTION*** marker.\n\nThis patch contains the following changes:\n\n"; - commitMessage->write("\n", 1); + if (! m_patchName.isEmpty()) + commitMessage->write(m_patchName); + else + commitMessage->write("\n", 1); commitMessage->write(defaultCommitMessage1, strlen(defaultCommitMessage1)); commitMessage->write(defaultCommitMessage2, strlen(defaultCommitMessage2)); QBuffer buffer; @@ -219,7 +223,7 @@ AbstractCommand::ReturnCodes Record::run() } else if (modification == QFileInfo(*commitMessage).lastModified()) { Logger::warn() << "unchanged, won't record\n"; - return Ok; + return UserCancelled; } else { // get data until the separator line. diff --git a/src/commands/Record.h b/src/commands/Record.h index e8a0e11..6158fa7 100644 --- a/src/commands/Record.h +++ b/src/commands/Record.h @@ -49,6 +49,9 @@ public: /// retuns the sha1 of the recorded patch after run() has successfully concluded. QString sha1() const; + // is set to true, force the editor to be started, if false use the command line options + void setEditComment(bool on) { m_editComment = on; } + virtual ReturnCodes run(); protected: @@ -61,6 +64,7 @@ private: UsageMode m_mode; QByteArray m_patchName; QString m_sha1; + bool m_editComment; }; #endif -- 2.11.4.GIT