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"),
40 m_excludeMatcher(m_config
)
42 CommandLineParser::addOptionDefinitions(options
);
43 CommandLineParser::setArgumentDefinition("whatsnew [FILE or DIRECTORY]" );
46 AbstractCommand::ReturnCodes
WhatsNew::run()
48 if (! checkInRepository())
50 const bool unified
= m_config
.contains("unified") || CommandLineParser::instance()->contains("unified");
51 return printWhatsNew(unified
, true);
54 AbstractCommand::ReturnCodes
WhatsNew::printWhatsNew(bool unified
, bool chatty
)
56 moveToRoot( static_cast <RebaseOptions
> (CheckFileSystem
| PrintError
) ); // XXX why is the static cast needed :(
58 CommandLineParser
*args
= CommandLineParser::instance();
59 const bool lookForAdds
= (m_config
.contains("look-for-adds") && !args
->contains("dont-look-for-adds-summary"))
60 || args
->contains("look-for-adds");
61 const bool printSummary
= lookForAdds
62 || (m_config
.contains("summary") && !args
->contains("no-summary"))
63 || args
->contains("summary");
67 changeSet
.fillFromCurrentChanges(rebasedArguments());
68 changeSet
.waitForFinishFirstFile();
70 QTextStream
&out
= Logger::standardOut();
73 QStringList arguments
;
74 arguments
<< "ls-files" << "-o" << "--directory" << "--no-empty-directory" << "--exclude-standard";
76 GitRunner
runner(git
, arguments
);
77 ReturnCodes rc
= runner
.start(GitRunner::WaitForStandardOutput
);
83 qint64 lineLength
= Vng::readLine(&git
, buf
, sizeof(buf
));
86 QString line
= QString::fromUtf8(buf
, lineLength
);
87 if (!m_excludeMatcher
.isExcluded(line
))
91 else if (changeSet
.count() == 0) {
97 if (!printSummary
&& !unified
) {
98 m_config
.colorize(out
);
101 for (int i
=0; i
< changeSet
.count(); ++i
) {
102 File file
= changeSet
.file(i
);
103 file
.outputWhatsChanged(out
, m_config
, printSummary
, unified
);
104 file
.cleanHunksData();
105 Logger::flushPager();
107 if (!printSummary
&& !unified
) {
108 m_config
.colorize(out
);
110 m_config
.normalColor(out
);
113 return AbstractCommand::Ok
;
116 QString
WhatsNew::argumentDescription() const
118 return QString("[FILE or DIRECTORY]");
121 QString
WhatsNew::commandDescription() const
123 return "Whatsnew gives you a view of what changes you've made in your working\n"
124 "copy that haven't yet been recorded. The changes are displayed in\n"
125 "vng patch format.\n";