From 1c4fa81cc398e21868ad237509f1ea8e772d76de Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 18 Nov 2024 20:07:02 +0100 Subject: Add a --comment option to record Comment: in history Suggested-by: mhoye on IRC --- apt-pkg/deb/dpkgpm.cc | 2 ++ apt-private/private-cmndline.cc | 1 + doc/apt-get.8.xml | 5 +++++ doc/examples/configure-index | 2 ++ test/integration/test-history | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100755 test/integration/test-history diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index ecedb8cd5..8cadd2712 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1087,6 +1087,8 @@ bool pkgDPkgPM::OpenLog() std::string RequestingUser = AptHistoryRequestingUser(); if (RequestingUser != "") WriteHistoryTag("Requested-By", RequestingUser); + if (auto comment = _config->Find("APT::History::Comment"); not comment.empty()) + WriteHistoryTag("Comment", comment); WriteHistoryTag("Install", install); WriteHistoryTag("Reinstall", reinstall); WriteHistoryTag("Upgrade", upgrade); diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 3a8cc6b1d..5d4eeb5cb 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -192,6 +192,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0, "solver", "APT::Solver", CommandLine::HasArg); addArg(0, "strict-pinning", "APT::Solver::Strict-Pinning", 0); addArg(0, "planner", "APT::Planner", CommandLine::HasArg); + addArg(0, "comment", "APT::History::Comment", CommandLine::HasArg); addArg('U', "update", "APT::Update", 0); if (CmdMatches("upgrade")) { diff --git a/doc/apt-get.8.xml b/doc/apt-get.8.xml index f1089f5d6..7d0ccece7 100644 --- a/doc/apt-get.8.xml +++ b/doc/apt-get.8.xml @@ -416,6 +416,11 @@ Configuration Item: APT::Get::List-Columns. + + Add the given value to the Comment: field in history.log + Configuration Item: APT::History::Comment. + + This option controls the architecture packages are built for diff --git a/doc/examples/configure-index b/doc/examples/configure-index index feadca8d2..6723a48da 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -903,3 +903,5 @@ APT::Color::Show::Package ""; update-manager::always-include-phased-updates ""; update-manager::never-include-phased-updates ""; + +apt::history::comment ""; diff --git a/test/integration/test-history b/test/integration/test-history new file mode 100755 index 000000000..47829e162 --- /dev/null +++ b/test/integration/test-history @@ -0,0 +1,40 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +buildsimplenativepackage 'pkg1' 'amd64' '1' 'stable' +buildsimplenativepackage 'pkg2' 'amd64' '1' 'stable' + + +setupaptarchive + +cathistory() { + sed rootdir/var/log/apt/history.log -re 's/^(Commandline|Start-Date|End-Date):.*/\1: dummy/' +} + + +testsuccess aptget install pkg1 + +testequal " +Start-Date: dummy +Commandline: dummy +Install: pkg1:amd64 (1) +End-Date: dummy" cathistory + +testsuccess aptget install pkg2 --comment="A test comment" + +testequal " +Start-Date: dummy +Commandline: dummy +Install: pkg1:amd64 (1) +End-Date: dummy + +Start-Date: dummy +Commandline: dummy +Comment: A test comment +Install: pkg2:amd64 (1) +End-Date: dummy" cathistory -- cgit v1.2.3-70-g09d2