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
);
44 AbstractCommand::ReturnCodes
WhatsNew::run()
46 if (! checkInRepository())
48 CommandLineParser
*args
= CommandLineParser::instance();
49 const bool printSummary
= m_config
.contains("summary") && !args
->contains("no-summary") || args
->contains("summary");
50 const bool unified
= m_config
.contains("unified") || args
->contains("unified");
54 changeSet
.fillFromCurrentChanges(rebasedArguments());
56 QTextStream
&out
= Logger::standardOut();
57 if (changeSet
.count() == 0) {
58 out
<< "No Changes!" << endl
;
61 if (!printSummary
&& !unified
) {
62 m_config
.colorize(out
);
65 foreach(File file
, changeSet
.files()) {
66 const bool deleted
= file
.fileName().isEmpty() && !file
.oldFileName().isEmpty();
67 const bool added
= !deleted
&& !file
.fileName().isEmpty() && file
.oldFileName().isEmpty();
68 const bool renamed
= !deleted
&& !added
&& file
.fileName() != file
.oldFileName();
79 if (deleted
|| renamed
)
80 out
<< file
.oldFileName();
82 out
<< file
.fileName();
84 out
<< " => " << file
.fileName();
86 int removed
= file
.linesRemoved();
87 int added
= file
.linesAdded();
89 out
<< " -" << QString::number(removed
);
91 out
<< " +" << QString::number(added
);
96 if (deleted
) { // file deleted.
98 m_config
.colorize(out
);
100 m_config
.normalColor(out
);
101 out
<< file
.oldFileName() << endl
;
104 else if (added
) { // file added.
106 m_config
.colorize(out
);
108 m_config
.normalColor(out
);
109 out
<< file
.fileName() << endl
;
113 if(renamed
) { // rename
114 if (!unified
) m_config
.colorize(out
);
116 if (!unified
) m_config
.normalColor(out
);
117 out
<< "`" << file
.oldFileName() << "' `" << file
.fileName() << "'" << endl
;
119 if (file
.oldProtection() != file
.protection()) {
120 if (!unified
) m_config
.colorize(out
);
121 out
<<"mode change ";
122 if (!unified
) m_config
.normalColor(out
);
123 out
<< file
.fileName() << " " << file
.oldProtection() << " => " << file
.protection() << endl
;
126 if (file
.isBinary()) { // will not have any hunks
127 if (!unified
) m_config
.colorize(out
);
128 out
<< "binary modification ";
129 if (!unified
) m_config
.normalColor(out
);
130 out
<< file
.fileName() << endl
;
135 if (file
.oldFileName().isEmpty())
136 out
<< "/dev/null\n";
138 out
<< file
.oldFileName() << endl
;
140 if (file
.fileName().isEmpty())
141 out
<< "/dev/null\n";
143 out
<< file
.fileName() << endl
;
145 foreach(Hunk hunk
, file
.hunks()) {
147 out
<< QString(hunk
.header());
148 out
<< QString(hunk
.patch());
151 for (int i
= 0; i
< hunk
.subHunkCount(); i
++) {
152 m_config
.colorize(out
);
154 QByteArray patch
= hunk
.subHunk(i
);
155 m_config
.normalColor(out
);
156 out
<< file
.fileName() <<" "<< QString::number(hunk
.lineNumber(i
)) << endl
;
157 if (patch
.contains((char) 0)) { // binary
158 m_config
.colorize(out
);
159 out
<< "binary data\n";
160 m_config
.normalColor(out
);
163 out
<< QString(patch
);
167 if (!printSummary
&& !unified
) {
168 m_config
.colorize(out
);
170 m_config
.normalColor(out
);
173 return AbstractCommand::Ok
;
176 QString
WhatsNew::argumentDescription() const
178 return QString("[FILE or DIRECTORY]");
181 QString
WhatsNew::commandDescription() const
183 return "whatsnew gives you a view of what changes you've made in your working\n"
184 "copy that haven't yet been recorded. The changes are displayed in\n"
185 "vng patch format.\n";