We don't want vng executable to be placed inside Vng.app/Contents/MacOS on Mac OS X.
[vng.git] / WhatsNew.cpp
blob478b30dffb4f52c0f258585a69d91fc62b3dff59
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 "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"},
30 // TODO :)
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"},
35 CommandLineLastOption
38 WhatsNew::WhatsNew()
39 : AbstractCommand("whatsnew")
41 CommandLineParser::addOptionDefinitions(options);
44 AbstractCommand::ReturnCodes WhatsNew::run()
46 if (! checkInRepository())
47 return NotInRepo;
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");
51 if (shouldUsePager())
52 Logger::startPager();
53 ChangeSet changeSet;
54 changeSet.fillFromCurrentChanges(rebasedArguments());
56 QTextStream &out = Logger::standardOut();
57 if (changeSet.count() == 0) {
58 out << "No Changes!" << endl;
59 return Ok;
61 if (!printSummary && !unified) {
62 m_config.colorize(out);
63 out << "{\n";
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();
69 if (printSummary) {
70 if (deleted)
71 out <<"D ";
72 else if (added)
73 out <<"A ";
74 else if (renamed)
75 out << "R ";
76 else
77 out << "M ";
79 if (deleted || renamed)
80 out << file.oldFileName();
81 else
82 out << file.fileName();
83 if (renamed)
84 out << " => " << file.fileName();
86 int removed = file.linesRemoved();
87 int added = file.linesAdded();
88 if (removed)
89 out << " -" << QString::number(removed);
90 if (added)
91 out << " +" << QString::number(added);
92 out << endl;
93 continue;
96 if (deleted) { // file deleted.
97 if (!unified) {
98 m_config.colorize(out);
99 out <<"rmfile ";
100 m_config.normalColor(out);
101 out << file.oldFileName() << endl;
104 else if (added) { // file added.
105 if (!unified) {
106 m_config.colorize(out);
107 out <<"addfile ";
108 m_config.normalColor(out);
109 out << file.fileName() << endl;
112 else {
113 if(renamed) { // rename
114 if (!unified) m_config.colorize(out);
115 out <<"move ";
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;
131 continue;
133 if (unified) {
134 out << "--- a/";
135 if (file.oldFileName().isEmpty())
136 out << "/dev/null\n";
137 else
138 out << file.oldFileName() << endl;
139 out << "--- b/";
140 if (file.fileName().isEmpty())
141 out << "/dev/null\n";
142 else
143 out << file.fileName() << endl;
145 foreach(Hunk hunk, file.hunks()) {
146 if (unified) {
147 out << QString(hunk.header());
148 out << QString(hunk.patch());
149 continue;
151 for (int i = 0; i < hunk.subHunkCount(); i++) {
152 m_config.colorize(out);
153 out <<"hunk ";
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);
162 else
163 out << QString(patch);
167 if (!printSummary && !unified) {
168 m_config.colorize(out);
169 out << "}\n";
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";