aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-12-24 00:37:32 +0100
committerAdrian Kummerlaender2015-12-24 00:37:32 +0100
commitce1460dd98185f80db479c7dc7ca19026149a255 (patch)
tree1936a524076c93511c23cc640466a8f5a26443e2
parentf47dc6ba1a17052ad4dde1d685772b83f23a8477 (diff)
downloadchange-ce1460dd98185f80db479c7dc7ca19026149a255.tar
change-ce1460dd98185f80db479c7dc7ca19026149a255.tar.gz
change-ce1460dd98185f80db479c7dc7ca19026149a255.tar.bz2
change-ce1460dd98185f80db479c7dc7ca19026149a255.tar.lz
change-ce1460dd98185f80db479c7dc7ca19026149a255.tar.xz
change-ce1460dd98185f80db479c7dc7ca19026149a255.tar.zst
change-ce1460dd98185f80db479c7dc7ca19026149a255.zip
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.
-rw-r--r--src/change_log.cc8
-rw-r--r--src/tracking/change_tracker.cc11
-rw-r--r--src/tracking/change_tracker.h2
3 files changed, 18 insertions, 3 deletions
diff --git a/src/change_log.cc b/src/change_log.cc
index c592f20..44a6046 100644
--- a/src/change_log.cc
+++ b/src/change_log.cc
@@ -23,7 +23,13 @@ void init() {
logger = std::make_unique<utility::Logger>(STDERR_FILENO);
}
- tracker = std::make_unique<tracking::ChangeTracker>(logger.get());
+ if ( getenv("CHANGE_LOG_DIFF_CMD") != NULL ) {
+ tracker = std::make_unique<tracking::ChangeTracker>(
+ logger.get(), getenv("CHANGE_LOG_DIFF_CMD")
+ );
+ } else {
+ tracker = std::make_unique<tracking::ChangeTracker>(logger.get());
+ }
}
ssize_t write(int fd, const void* buffer, size_t count) {
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<DIFF_PROCESS>(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::child>(
- 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<