public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: man/, man/include/, /
Date: Mon, 13 May 2019 12:57:30 +0000 (UTC)	[thread overview]
Message-ID: <1557752190.7854ca6d12f793f3b516373784831131db36bca9.grobian@gentoo> (raw)

commit:     7854ca6d12f793f3b516373784831131db36bca9
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon May 13 12:56:30 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon May 13 12:56:30 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7854ca6d

qlop: add mode for listing last emerge contents

add -l flag to list packages/sync from last emerge operation and make it
default (when no flags are given)

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md                       |  2 --
 man/include/qlop.desc         |  5 ++--
 man/include/qlop.optdesc.yaml |  3 +++
 man/qlop.1                    |  9 +++++--
 qlop.c                        | 62 ++++++++++++++++++++++++++++++++-----------
 5 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/TODO.md b/TODO.md
index 7df8983..58ea4c5 100644
--- a/TODO.md
+++ b/TODO.md
@@ -83,8 +83,6 @@
 
 - have a mode that doesn't print timestamp (to get just atoms, -v should
   work)
-- make a -d mode that allows to do equivalent of "last portage emerge"
-  to make it easy to see what was newly merged/unmerged
 
 # qlist
 - have -F for use with -I so one can do things like print SLOT for

diff --git a/man/include/qlop.desc b/man/include/qlop.desc
index 0c14e00..3505173 100644
--- a/man/include/qlop.desc
+++ b/man/include/qlop.desc
@@ -2,9 +2,10 @@
 reads from $EMERGE_LOG_DIR/emerge.log and tries to extract
 information about merges, unmerges and syncs.  It can
 calculate average merge times or just list them.  When given no
-arguments or just \fB-v\fR, \fIqlop\fR acts as if \fB-must\fR was given
+arguments or just \fB-v\fR, \fIqlop\fR acts as if \fB-slumt\fR was given
 and thus lists the time taken for all occurrances of merges, unmerges
-and sync operations found in the log.
+and sync operations found in the log for the last \fBemerge\fR(1) action
+performed by Portage.
 .P
 By default, packages are printed as CATEGORY/PN.  Use \fB-v\fR to print
 the package version and revision numbers, e.g\. CATEGORY/PF.  Note that

diff --git a/man/include/qlop.optdesc.yaml b/man/include/qlop.optdesc.yaml
index 25143b2..677c4d2 100644
--- a/man/include/qlop.optdesc.yaml
+++ b/man/include/qlop.optdesc.yaml
@@ -21,6 +21,9 @@ date: |
     .IP FORMAT|DATE
     Use \fIFORMAT\fR as input for \fBstrptime\fR(3) to parse \fIDATE\fR.
     .RE
+lastmerge: |
+    Limit selection to last Portage emerge action.  This option is a
+    dynamic version of \fB-d\fR, and hence both cannot be used together.
 time: |
     Show the time it took to merge, unmerge or sync.
 average: |

diff --git a/man/qlop.1 b/man/qlop.1
index 83b62f8..ae40fa7 100644
--- a/man/qlop.1
+++ b/man/qlop.1
@@ -10,9 +10,10 @@ qlop \- emerge log analyzer
 reads from $EMERGE_LOG_DIR/emerge.log and tries to extract
 information about merges, unmerges and syncs.  It can
 calculate average merge times or just list them.  When given no
-arguments or just \fB-v\fR, \fIqlop\fR acts as if \fB-must\fR was given
+arguments or just \fB-v\fR, \fIqlop\fR acts as if \fB-slumt\fR was given
 and thus lists the time taken for all occurrances of merges, unmerges
-and sync operations found in the log.
+and sync operations found in the log for the last \fBemerge\fR(1) action
+performed by Portage.
 .P
 By default, packages are printed as CATEGORY/PN.  Use \fB-v\fR to print
 the package version and revision numbers, e.g\. CATEGORY/PF.  Note that
@@ -98,6 +99,10 @@ Seconds since 1970-01-01 00:00:00 +0000 (UTC), the UNIX epoch.
 Use \fIFORMAT\fR as input for \fBstrptime\fR(3) to parse \fIDATE\fR.
 .RE
 .TP
+\fB\-l\fR, \fB\-\-lastmerge\fR
+Limit selection to last Portage emerge action.  This option is a
+dynamic version of \fB-d\fR, and hence both cannot be used together.
+.TP
 \fB\-f\fR \fI<arg>\fR, \fB\-\-logfile\fR \fI<arg>\fR
 Read emerge logfile instead of $EMERGE_LOG_DIR/emerge.log.
 .TP

diff --git a/qlop.c b/qlop.c
index a60e5ac..5217638 100644
--- a/qlop.c
+++ b/qlop.c
@@ -24,7 +24,7 @@
 
 #define QLOP_DEFAULT_LOGFILE "emerge.log"
 
-#define QLOP_FLAGS "ctaHMmuUserd:f:w:" COMMON_FLAGS
+#define QLOP_FLAGS "ctaHMmuUslerd:f:w:" COMMON_FLAGS
 static struct option const qlop_long_opts[] = {
 	{"summary",   no_argument, NULL, 'c'},
 	{"time",      no_argument, NULL, 't'},
@@ -38,6 +38,7 @@ static struct option const qlop_long_opts[] = {
 	{"endtime",   no_argument, NULL, 'e'},
 	{"running",   no_argument, NULL, 'r'},
 	{"date",       a_argument, NULL, 'd'},
+	{"lastmerge", no_argument, NULL, 'l'},
 	{"logfile",    a_argument, NULL, 'f'},
 	{"atoms",      a_argument, NULL, 'w'},
 	COMMON_LONG_OPTS
@@ -55,6 +56,7 @@ static const char * const qlop_opts_help[] = {
 	"Report time at which the operation finished (iso started)",
 	"Show current emerging packages",
 	"Limit selection to this time (1st -d is start, 2nd -d is end)",
+	"Limit selection to last Portage emerge action",
 	"Read emerge logfile instead of $EMERGE_LOG_DIR/" QLOP_DEFAULT_LOGFILE,
 	"Read package atoms to report from file",
 	COMMON_OPTS_HELP
@@ -80,6 +82,7 @@ struct qlop_mode {
 	char do_human:1;
 	char do_machine:1;
 	char do_endtime:1;
+	char show_lastmerge:1;
 };
 
 static bool
@@ -319,7 +322,8 @@ static int do_emerge_log(
 	char buf[BUFSIZ];
 	char *p;
 	char *q;
-	time_t tstart;
+	time_t tstart = LONG_MAX;
+	time_t last_merge = 0;
 	time_t sync_start = 0;
 	time_t sync_time = 0;
 	size_t sync_cnt = 0;
@@ -332,6 +336,7 @@ static int do_emerge_log(
 	DECLARE_ARRAY(unmerge_averages);
 	size_t i;
 	size_t parallel_emerge = 0;
+	bool all_atoms = false;
 
 	struct pkg_match {
 		char id[BUFSIZ];
@@ -352,7 +357,8 @@ static int do_emerge_log(
 		return 1;
 	}
 
-	if (array_cnt(atoms) == 0) {
+	all_atoms = array_cnt(atoms) == 0;
+	if (all_atoms || flags->show_lastmerge) {
 		/* assemble list of atoms */
 		while (fgets(buf, sizeof(buf), fp) != NULL) {
 			if ((p = strchr(buf, ':')) == NULL)
@@ -363,6 +369,17 @@ static int do_emerge_log(
 			if (tstart < tbegin || tstart > tend)
 				continue;
 
+			if (flags->show_lastmerge) {
+				if (strncmp(p, "  *** emerge ", 13) == 0) {
+					last_merge = tstart;
+					array_for_each(atoms, i, atomw)
+						atom_implode(atomw);
+					xarrayfree_int(atoms);
+				}
+				if (!all_atoms)
+					continue;
+			}
+
 			atom = NULL;
 			if (strncmp(p, "  >>> emerge ", 13) == 0 &&
 					(p = strchr(p + 13, ')')) != NULL)
@@ -411,6 +428,10 @@ static int do_emerge_log(
 		rewind(fp);
 	}
 
+	if (flags->show_lastmerge) {
+		tbegin = last_merge;
+		tend = tstart;
+	}
 	/* loop over lines searching for atoms */
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		if ((p = strchr(buf, ':')) == NULL)
@@ -876,22 +897,24 @@ int qlop_main(int argc, char **argv)
 	m.do_human = 0;
 	m.do_machine = 0;
 	m.do_endtime = 0;
+	m.show_lastmerge = 0;
 
 	while ((ret = GETOPT_LONG(QLOP, qlop, "")) != -1) {
 		switch (ret) {
 			COMMON_GETOPTS_CASES(qlop)
 
-			case 't': m.do_time = 1;      break;
-			case 'm': m.do_merge = 1;     break;
-			case 'u': m.do_unmerge = 1;   break;
-			case 'U': m.do_autoclean = 1; break;
-			case 's': m.do_sync = 1;      break;
-			case 'r': m.do_running = 1;   break;
-			case 'a': m.do_average = 1;   break;
-			case 'c': m.do_summary = 1;   break;
-			case 'H': m.do_human = 1;     break;
-			case 'M': m.do_machine = 1;   break;
-			case 'e': m.do_endtime = 1;   break;
+			case 't': m.do_time = 1;        break;
+			case 'm': m.do_merge = 1;       break;
+			case 'u': m.do_unmerge = 1;     break;
+			case 'U': m.do_autoclean = 1;   break;
+			case 's': m.do_sync = 1;        break;
+			case 'r': m.do_running = 1;     break;
+			case 'a': m.do_average = 1;     break;
+			case 'c': m.do_summary = 1;     break;
+			case 'H': m.do_human = 1;       break;
+			case 'M': m.do_machine = 1;     break;
+			case 'e': m.do_endtime = 1;     break;
+			case 'l': m.show_lastmerge = 1; break;
 			case 'd':
 				if (start_time == 0) {
 					if (!parse_date(optarg, &start_time))
@@ -945,7 +968,7 @@ int qlop_main(int argc, char **argv)
 	if (atomfile)
 		free(atomfile);
 
-	/* default operation: -must */
+	/* default operation: -slumt */
 	if (
 			m.do_time == 0 &&
 			m.do_merge == 0 &&
@@ -962,6 +985,8 @@ int qlop_main(int argc, char **argv)
 		if (array_cnt(atoms) == 0)
 			m.do_sync = 1;
 		m.do_time = 1;
+		if (start_time == 0)
+			m.show_lastmerge = 1;
 	}
 
 	/* handle deps */
@@ -987,11 +1012,18 @@ int qlop_main(int argc, char **argv)
 		m.do_machine = 0;
 	}
 
+	/* handle -s + atoms */
 	if (m.do_sync && array_cnt(atoms) > 0) {
 		warn("-s cannot be used when specifying atoms, dropping -s");
 		m.do_sync = 0;
 	}
 
+	/* handle -l / -d conflict */
+	if (start_time != 0 && m.show_lastmerge) {
+		warn("-l and -d cannot be used together, dropping -l");
+		m.show_lastmerge = 0;
+	}
+
 	/* set default for -t, -a or -r */
 	if ((m.do_average || m.do_time || m.do_running) &&
 			!(m.do_merge || m.do_unmerge || m.do_sync))


             reply	other threads:[~2019-05-13 12:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-13 12:57 Fabian Groffen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-05-16 14:30 [gentoo-commits] proj/portage-utils:master commit in: man/, man/include/, / Fabian Groffen
2019-07-14 13:31 Fabian Groffen
2019-02-05 13:51 Fabian Groffen
2018-04-12 19:33 Fabian Groffen
2018-04-03 11:50 Fabian Groffen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1557752190.7854ca6d12f793f3b516373784831131db36bca9.grobian@gentoo \
    --to=grobian@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox