From ce1460dd98185f80db479c7dc7ca19026149a255 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 24 Dec 2015 00:37:32 +0100 Subject: Add support for changing the `diff` command via an environment variable While the file arguments remain fixed the actual `diff` application and its output style can be changed using the `CHANGE_LOG_DIFF_CMD` environment variable. --- src/tracking/change_tracker.cc | 11 +++++++++-- src/tracking/change_tracker.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/tracking') diff --git a/src/tracking/change_tracker.cc b/src/tracking/change_tracker.cc index 913604e..9bbdcb6 100644 --- a/src/tracking/change_tracker.cc +++ b/src/tracking/change_tracker.cc @@ -24,10 +24,14 @@ boost::process::context getDefaultContext() { namespace tracking { -ChangeTracker::ChangeTracker(utility::Logger* logger): +ChangeTracker::ChangeTracker(utility::Logger* logger, const std::string& diff_cmd): + diff_cmd_(diff_cmd), logger_(logger), children_() { } +ChangeTracker::ChangeTracker(utility::Logger* logger): + ChangeTracker(logger, "diff -p") { } + ChangeTracker::~ChangeTracker() { for ( auto&& tracked : this->children_ ) { std::get(tracked)->get_stdin().close(); @@ -70,7 +74,10 @@ bool ChangeTracker::track(const std::string& file_path) { auto result = this->children_.emplace( file_path, std::make_unique( - boost::process::launch_shell("diff -p - " + file_path, getDefaultContext()) + boost::process::launch_shell( + this->diff_cmd_ + " - " + file_path, + getDefaultContext() + ) ) ); diff --git a/src/tracking/change_tracker.h b/src/tracking/change_tracker.h index 54af4f7..24251e5 100644 --- a/src/tracking/change_tracker.h +++ b/src/tracking/change_tracker.h @@ -11,6 +11,7 @@ namespace tracking { class ChangeTracker { public: + ChangeTracker(utility::Logger*, const std::string&); ChangeTracker(utility::Logger*); ~ChangeTracker(); @@ -19,6 +20,7 @@ class ChangeTracker { bool track(const std::string&); private: + const std::string diff_cmd_; utility::Logger* const logger_; std::unordered_map< -- cgit v1.2.3