move commands to their own subdir
[vng.git] / WhatsNew.cpp
blobd1827ebab8c7ff931a39d9a4e8db54253078a26d
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
4 * Copyright (C) 2002-2004 David Roundy
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "WhatsNew.h"
20 #include "hunks/ChangeSet.h"
21 #include "Logger.h"
22 #include "GitRunner.h"
23 #include "CommandLineParser.h"
25 #include <QTextStream>
26 #include <QProcess>
28 static const CommandLineOption options[] = {
29 {"-s, --summary", "summarize changes"},
30 {"--no-summary", "don't summarize changes"},
31 {"-u, --unified", "output patch in a format similar to diff -u"},
32 {"-l, --look-for-adds", "In addition to modifications, look for files that are not boring, and thus are potentially pending addition"},
33 {"--dont-look-for-adds", "Don't look for any files or directories that could be added, and don't add them automatically"},
34 //{"--boring", "don't skip boring files"},
35 CommandLineLastOption
38 WhatsNew::WhatsNew()
39 : AbstractCommand("whatsnew")
41 CommandLineParser::addOptionDefinitions(options);
42 CommandLineParser::setArgumentDefinition("whatsnew [FILE or DIRECTORY]" );
45 AbstractCommand::ReturnCodes WhatsNew::run()
47 if (! checkInRepository())
48 return NotInRepo;
49 moveToRoot();
51 CommandLineParser *args = CommandLineParser::instance();
52 const bool lookForAdds = m_config.contains("look-for-adds") && !args->contains("dont-look-for-adds-summary")
53 || args->contains("look-for-adds");
54 const bool printSummary = lookForAdds || m_config.contains("summary") &&
55 !args->contains("no-summary") || args->contains("summary");
56 const bool unified = m_config.contains("unified") || args->contains("unified");
58 if (shouldUsePager())
59 Logger::startPager();
60 ChangeSet changeSet;
61 changeSet.fillFromCurrentChanges(rebasedArguments());
63 QTextStream &out = Logger::standardOut();
64 if (lookForAdds) {
65 QProcess git;
66 QStringList arguments;
67 arguments << "ls-files" << "-o" << "--directory" << "--no-empty-directory" << "--exclude-standard";
69 GitRunner runner(git, arguments);
70 ReturnCodes rc = runner.start(GitRunner::WaitForStandardOutput);
71 if (rc != Ok)
72 return rc;
74 char buf[1024];
75 while(true) {
76 qint64 lineLength = Vng::readLine(&git, buf, sizeof(buf));
77 if (lineLength == -1)
78 break;
79 QString line = QString::fromUtf8(buf, lineLength);
80 out << "a " << line;
83 else if (changeSet.count() == 0) {
84 out << "No Changes!" << endl;
85 return Ok;
87 if (!printSummary && !unified) {
88 m_config.colorize(out);
89 out << "{\n";
91 foreach(File file, changeSet.files()) {
92 file.outputWhatsChanged(out, m_config, printSummary, unified);
93 Logger::flushPager();
95 if (!printSummary && !unified) {
96 m_config.colorize(out);
97 out << "}\n";
98 m_config.normalColor(out);
101 return AbstractCommand::Ok;
104 QString WhatsNew::argumentDescription() const
106 return QString("[FILE or DIRECTORY]");
109 QString WhatsNew::commandDescription() const
111 return "whatsnew gives you a view of what changes you've made in your working\n"
112 "copy that haven't yet been recorded. The changes are displayed in\n"
113 "vng patch format.\n";