pactree: Implement handling of multiple packages

Message ID 20200306021037.66811-2-jakseb.dev@gmail.com
State New
Headers show
Series
  • pactree: Implement handling of multiple packages
Related show

Commit Message

Sebastian Jakubiak March 6, 2020, 2:10 a.m. UTC
Make it possible to invoke pactree for multiple packages at once.

Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com>
---

This patch is designed to be applied on top of the one from the parent
message.

 src/pactree.c | 51 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 19 deletions(-)

Comments

Sebastian Jakubiak March 6, 2020, 9:40 p.m. UTC | #1
The patch from the parent email:

> From: jakseb.dev at gmail.com (Sebastian Jakubiak)
> Date: Fri,  6 Mar 2020 03:10:38 +0100
> Subject: [PATCH] pactree: Implement handling of multiple packages
> In-Reply-To: <20200306021037.66811-1-jakseb.dev@gmail.com>
> References: <20200306021037.66811-1-jakseb.dev@gmail.com>
> Message-ID: <20200306021037.66811-2-jakseb.dev@gmail.com>
>
> Make it possible to invoke pactree for multiple packages at once.
> [...]

is broken. I didn't take into into account situations when target
packages (that is, the ones given as arguments to pactree) repeat or
one target package is a dependency of another. Some specific examples:

pactree tar tar xz
pactree [-g] tar glibc

I'm sorry.
Daniel M. Capella March 6, 2020, 11:37 p.m. UTC | #2
On March 6, 2020 4:40:44 PM EST, Sebastian Jakubiak <jakseb.dev@gmail.com> wrote:
> The patch from the parent email:
> 
> > From: jakseb.dev at gmail.com (Sebastian Jakubiak)
> > Date: Fri,  6 Mar 2020 03:10:38 +0100
> > Subject: [PATCH] pactree: Implement handling of multiple packages
> > In-Reply-To: <20200306021037.66811-1-jakseb.dev@gmail.com>
> > References: <20200306021037.66811-1-jakseb.dev@gmail.com>
> > Message-ID: <20200306021037.66811-2-jakseb.dev@gmail.com>
> >
> > Make it possible to invoke pactree for multiple packages at once.
> > [...]
> 
> is broken. I didn't take into into account situations when target
> packages (that is, the ones given as arguments to pactree) repeat or
> one target package is a dependency of another. Some specific examples:
> 
> pactree tar tar xz
> pactree [-g] tar glibc
> 
> I'm sorry.

Copy that.

--
Best,
Daniel <https://danielcapella.com>
Sebastian Jakubiak March 9, 2020, 6:02 p.m. UTC | #3
> Copy that.

What do you mean?
Daniel M. Capella March 9, 2020, 6:24 p.m. UTC | #4
On March 9, 2020 2:02:16 PM EDT, Sebastian Jakubiak <jakseb.dev@gmail.com> wrote:
> > Copy that.
> 
> What do you mean?

I meant, understood, will not apply. Sorry, it's radio/military jargon.

--
Best,
Daniel <https://danielcapella.com>

Patch

diff --git a/src/pactree.c b/src/pactree.c
index 9f074fe..1775587 100644
--- a/src/pactree.c
+++ b/src/pactree.c
@@ -354,7 +354,7 @@  static int parse_options(int argc, char *argv[])
 		}
 	}
 
-	if(!argv[optind] || argv[optind + 1]) {
+	if(!argv[optind]) {
 		usage();
 		return 1;
 	}
@@ -430,12 +430,18 @@  static void print(const char *parentname, const char *pkgname,
 	}
 }
 
-static void print_start(const char *pkgname, const char *provname)
+static void print_start(void)
 {
 	if(graphviz) {
 		printf("digraph G { START [color=red, style=filled];\n"
-				"node [style=filled, color=green];\n"
-				" \"START\" -> \"%s\";\n", pkgname);
+				"node [style=filled, color=green];\n");
+	}
+}
+
+static void print_target(const char *pkgname, const char *provname)
+{
+	if(graphviz) {
+		printf(" \"START\" -> \"%s\";\n", pkgname);
 	} else {
 		tdepth d = {
 			NULL,
@@ -526,7 +532,7 @@  static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r
 
 int main(int argc, char *argv[])
 {
-	int freelist = 0, ret;
+	int freelist = 0, ret, target_ind;
 	alpm_errno_t err;
 	const char *target_name;
 	alpm_pkg_t *pkg;
@@ -560,23 +566,30 @@  int main(int argc, char *argv[])
 		freelist = 1;
 	}
 
-	/* we only care about the first non option arg for walking */
-	target_name = argv[optind];
-
-	pkg = alpm_find_dbs_satisfier(handle, dblist, target_name);
-	if(!pkg) {
-		fprintf(stderr, "error: package '%s' not found\n", target_name);
-		cleanup(1);
-	}
+	for(target_ind = optind; argv[target_ind]; ++target_ind) {
+		target_name = argv[target_ind];
+		pkg = alpm_find_dbs_satisfier(handle, dblist, target_name);
+		if(!pkg) {
+			fprintf(stderr, "error: package '%s' not found\n", target_name);
+			cleanup(1);
+		}
+	}
 
+	print_start();
+
-	print_start(alpm_pkg_get_name(pkg), target_name);
-
-	tdepth d = {
-		NULL,
-		NULL,
-		1
-	};
-	walk_deps(dblist, pkg, &d, reverse);
+	for(target_ind = optind; argv[target_ind]; ++target_ind) {
+		target_name = argv[target_ind];
+		pkg = alpm_find_dbs_satisfier(handle, dblist, target_name);
+
+		print_target(alpm_pkg_get_name(pkg), target_name);
+
+		tdepth d = {
+			NULL,
+			NULL,
+			1
+		};
+		walk_deps(dblist, pkg, &d, reverse);
+	}
 
 	print_end();