aboutsummaryrefslogtreecommitdiff
path: root/func.cc
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-08-13 17:11:18 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-08-13 17:11:18 +0900
commit180b409602e3174a891568d79d42e6343378f40a (patch)
tree3ca970d4c05c1c834d1fd545aa8479762d90ffa0 /func.cc
parent4db9edc950808e5da5fe4fb954b45403e462064b (diff)
downloadkati-180b409602e3174a891568d79d42e6343378f40a.tar.gz
[C++] Store command results with no output
Instead, we stop storing results of commands which are specified by --ignore_dirty
Diffstat (limited to 'func.cc')
-rw-r--r--func.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/func.cc b/func.cc
index 97c3bc2..9f72e75 100644
--- a/func.cc
+++ b/func.cc
@@ -516,6 +516,19 @@ static void ShellFuncImpl(const string& shell, const string& cmd,
static vector<CommandResult*> g_command_results;
+bool ShouldStoreCommandResult(StringPiece cmd) {
+ if (HasWord(cmd, "date") || HasWord(cmd, "echo"))
+ return false;
+ if (g_ignore_dirty_pattern) {
+ Pattern pat(g_ignore_dirty_pattern);
+ for (StringPiece tok : WordScanner(cmd)) {
+ if (pat.Match(tok))
+ return false;
+ }
+ }
+ return true;
+}
+
void ShellFunc(const vector<Value*>& args, Evaluator* ev, string* s) {
shared_ptr<string> cmd = args[0]->Eval(ev);
if (ev->avoid_io() && !HasNoIoInShellScript(*cmd)) {
@@ -530,7 +543,7 @@ void ShellFunc(const vector<Value*>& args, Evaluator* ev, string* s) {
string out;
FindCommand* fc = NULL;
ShellFuncImpl(*shell, *cmd, &out, &fc);
- if (!out.empty() && !HasWord(*cmd, "date") && !HasWord(*cmd, "echo")) {
+ if (ShouldStoreCommandResult(*cmd)) {
CommandResult* cr = new CommandResult();
cr->cmd = *cmd;
cr->find.reset(fc);