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/>.
20 #include "hunks/ChangeSet.h"
22 #include "GitRunner.h"
23 #include "CommandLineParser.h"
25 #include <QTextStream>
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"},
39 : AbstractCommand("whatsnew")
41 CommandLineParser::addOptionDefinitions(options
);
42 CommandLineParser::setArgumentDefinition("whatsnew [FILE or DIRECTORY]" );
45 AbstractCommand::ReturnCodes
WhatsNew::run()
47 if (! checkInRepository())
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");
61 changeSet
.fillFromCurrentChanges(rebasedArguments());
63 QTextStream
&out
= Logger::standardOut();
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
);
76 qint64 lineLength
= Vng::readLine(&git
, buf
, sizeof(buf
));
79 QString line
= QString::fromUtf8(buf
, lineLength
);
83 else if (changeSet
.count() == 0) {
84 out
<< "No Changes!" << endl
;
87 if (!printSummary
&& !unified
) {
88 m_config
.colorize(out
);
91 for (int i
=0; i
< changeSet
.count(); ++i
) {
92 File file
= changeSet
.file(i
);
93 file
.outputWhatsChanged(out
, m_config
, printSummary
, unified
);
94 file
.cleanHunksData();
97 if (!printSummary
&& !unified
) {
98 m_config
.colorize(out
);
100 m_config
.normalColor(out
);
103 return AbstractCommand::Ok
;
106 QString
WhatsNew::argumentDescription() const
108 return QString("[FILE or DIRECTORY]");
111 QString
WhatsNew::commandDescription() const
113 return "whatsnew gives you a view of what changes you've made in your working\n"
114 "copy that haven't yet been recorded. The changes are displayed in\n"
115 "vng patch format.\n";