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 "CommandLineParser.h"
24 #include <QTextStream>
26 static const CommandLineOption options
[] = {
27 {"-s, --summary", "summarize changes"},
28 {"--no-summary", "don't summarize changes"},
29 {"-u, --unified", "output patch in a format similar to diff -u"},
31 //{"--ignore-times", "don't trust the file modification times"},
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())
49 CommandLineParser
*args
= CommandLineParser::instance();
50 const bool printSummary
= m_config
.contains("summary") && !args
->contains("no-summary") || args
->contains("summary");
51 const bool unified
= m_config
.contains("unified") || args
->contains("unified");
55 changeSet
.fillFromCurrentChanges(rebasedArguments());
57 QTextStream
&out
= Logger::standardOut();
58 if (changeSet
.count() == 0) {
59 out
<< "No Changes!" << endl
;
62 if (!printSummary
&& !unified
) {
63 m_config
.colorize(out
);
66 foreach(File file
, changeSet
.files()) {
67 const bool deleted
= file
.fileName().isEmpty() && !file
.oldFileName().isEmpty();
68 const bool added
= !deleted
&& !file
.fileName().isEmpty() && file
.oldFileName().isEmpty();
69 const bool renamed
= !deleted
&& !added
&& file
.fileName() != file
.oldFileName();
80 if (deleted
|| renamed
)
81 out
<< file
.oldFileName();
83 out
<< file
.fileName();
85 out
<< " => " << file
.fileName();
87 int removed
= file
.linesRemoved();
88 int added
= file
.linesAdded();
90 out
<< " -" << QString::number(removed
);
92 out
<< " +" << QString::number(added
);
97 if (deleted
) { // file deleted.
99 m_config
.colorize(out
);
101 m_config
.normalColor(out
);
102 out
<< file
.oldFileName() << endl
;
105 else if (added
) { // file added.
107 m_config
.colorize(out
);
109 m_config
.normalColor(out
);
110 out
<< file
.fileName() << endl
;
114 if(renamed
) { // rename
115 if (!unified
) m_config
.colorize(out
);
117 if (!unified
) m_config
.normalColor(out
);
118 out
<< "`" << file
.oldFileName() << "' `" << file
.fileName() << "'" << endl
;
120 if (file
.oldProtection() != file
.protection()) {
121 if (!unified
) m_config
.colorize(out
);
122 out
<<"mode change ";
123 if (!unified
) m_config
.normalColor(out
);
124 out
<< file
.fileName() << " " << file
.oldProtection() << " => " << file
.protection() << endl
;
127 if (file
.isBinary()) { // will not have any hunks
128 if (!unified
) m_config
.colorize(out
);
129 out
<< "binary modification ";
130 if (!unified
) m_config
.normalColor(out
);
131 out
<< file
.fileName() << endl
;
136 if (file
.oldFileName().isEmpty())
137 out
<< "/dev/null\n";
139 out
<< file
.oldFileName() << endl
;
141 if (file
.fileName().isEmpty())
142 out
<< "/dev/null\n";
144 out
<< file
.fileName() << endl
;
146 foreach(Hunk hunk
, file
.hunks()) {
148 out
<< QString(hunk
.header());
149 out
<< QString(hunk
.patch());
152 for (int i
= 0; i
< hunk
.subHunkCount(); i
++) {
153 m_config
.colorize(out
);
155 QByteArray patch
= hunk
.subHunk(i
);
156 m_config
.normalColor(out
);
157 out
<< file
.fileName() <<" "<< QString::number(hunk
.lineNumber(i
)) << endl
;
158 if (patch
.contains((char) 0)) { // binary
159 m_config
.colorize(out
);
160 out
<< "binary data\n";
161 m_config
.normalColor(out
);
164 out
<< QString(patch
);
167 Logger::flushPager();
169 if (!printSummary
&& !unified
) {
170 m_config
.colorize(out
);
172 m_config
.normalColor(out
);
175 return AbstractCommand::Ok
;
178 QString
WhatsNew::argumentDescription() const
180 return QString("[FILE or DIRECTORY]");
183 QString
WhatsNew::commandDescription() const
185 return "whatsnew gives you a view of what changes you've made in your working\n"
186 "copy that haven't yet been recorded. The changes are displayed in\n"
187 "vng patch format.\n";