commit:     26d038ae9c2f499cfb52486913cc326854a50571
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 27 17:07:57 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Mar 27 17:07:57 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=26d038ae

q: migrate to new repo posthook system

This also extends the reinit interface to optionally take a path to the
overlay to process.  That allows the postsync hook to fire on specific
repos rather than all of them.

URL: https://bugs.gentoo.org/522032

 Makefile               |  7 ++++++-
 Makefile.am            |  5 +++++
 main.c                 |  3 ++-
 main.h                 |  1 +
 man/q.1                |  6 +++---
 q.c                    | 34 +++++++++++++++++++++++++++-------
 repo.postsync/q-reinit | 10 ++++++++++
 7 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index fe6092f..baa27c2 100644
--- a/Makefile
+++ b/Makefile
@@ -27,9 +27,11 @@ LIBADD    += $(shell echo | $(CC) -dM -E - | grep -q ' 
__FreeBSD__' && echo '-lk
 LIBADD    += -liniparser
 DESTDIR   :=
 PREFIX    := $(DESTDIR)/usr
+ETCDIR    := $(DESTDIR)/etc
 STRIP     := strip
 MKDIR     := mkdir -p
 CP        := cp
+INSTALL_EXE := install -m755
 
 ifndef V
 Q = @
@@ -106,13 +108,16 @@ testclean:
 
 install: all
        $(MKDIR) $(PREFIX)/bin/
-       $(CP) q $(PREFIX)/bin/
+       $(INSTALL_EXE) q $(PREFIX)/bin/
 
        set -e ; \
        for applet in $(filter-out q,$(APPLETS)) ; do \
                ln -sf q $(PREFIX)/bin/$${applet} ; \
        done
 
+       $(MKDIR) $(ETCDIR)/portage/repo.postsync.d
+       $(INSTALL_EXE) repo.postsync/* $(ETCDIR)/portage/repo.postsync.d/
+
 ifneq ($(wildcard man/*.1),)
        $(MKDIR) $(PREFIX)/share/man/man1/
        cp $(wildcard man/*.1) $(PREFIX)/share/man/man1/

diff --git a/Makefile.am b/Makefile.am
index 225c979..362ee21 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,6 +2,11 @@ ACLOCAL_AMFLAGS = -I autotools/m4
 
 SUBDIRS = autotools/gnulib
 
+portagedir = $(sysconfdir)/portage
+postsyncddir = $(portagedir)/repo.postsync.d
+
+dist_postsyncd_SCRIPTS = repo.postsync/q-reinit
+
 bin_PROGRAMS = q
 q_SOURCES = main.c
 q_CPPFLAGS = \

diff --git a/main.c b/main.c
index e9bacda..0834756 100644
--- a/main.c
+++ b/main.c
@@ -976,7 +976,8 @@ initialize_flat(const char *overlay, int cache_type, bool 
force)
        }
 
        if (!quiet)
-               warn("Updating ebuild %scache ... ", cache_type == CACHE_EBUILD 
? "" : "meta");
+               warn("Updating ebuild %scache in %s ... ",
+                       cache_type == CACHE_EBUILD ? "" : "meta", overlay);
 
        count = frac = secs = 0;
 

diff --git a/main.h b/main.h
index 877c1ec..6848a9f 100644
--- a/main.h
+++ b/main.h
@@ -99,3 +99,4 @@
        getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL)
 
 #define a_argument required_argument
+#define opt_argument optional_argument

diff --git a/man/q.1 b/man/q.1
index 322e1af..0f8f367 100644
--- a/man/q.1
+++ b/man/q.1
@@ -1,4 +1,4 @@
-.TH q "1" "Mar 2014" "Gentoo Foundation" "q"
+.TH q "1" "Mar 2016" "Gentoo Foundation" "q"
 .SH NAME
 q \- invoke a portage utility applet
 .SH SYNOPSIS
@@ -11,10 +11,10 @@ q \- invoke a portage utility applet
 \fB\-i\fR, \fB\-\-install\fR
 Install symlinks for applets
 .TP
-\fB\-r\fR, \fB\-\-reinitialize\fR
+\fB\-r\fR \fI[arg]\fR, \fB\-\-reinitialize\fR \fI[arg]\fR
 Reinitialize ebuild cache
 .TP
-\fB\-m\fR, \fB\-\-metacache\fR
+\fB\-m\fR \fI[arg]\fR, \fB\-\-metacache\fR \fI[arg]\fR
 Reinitialize metadata cache
 .TP
 \fB\-M\fR \fI<arg>\fR, \fB\-\-modpath\fR \fI<arg>\fR

diff --git a/q.c b/q.c
index 53b359f..1475f99 100644
--- a/q.c
+++ b/q.c
@@ -8,10 +8,10 @@
 
 #define Q_FLAGS "irmM:" COMMON_FLAGS
 static struct option const q_long_opts[] = {
-       {"install",      no_argument, NULL, 'i'},
-       {"reinitialize", no_argument, NULL, 'r'},
-       {"metacache",    no_argument, NULL, 'm'},
-       {"modpath",       a_argument, NULL, 'M'},
+       {"install",       no_argument, NULL, 'i'},
+       {"reinitialize", opt_argument, NULL, 'r'},
+       {"metacache",    opt_argument, NULL, 'm'},
+       {"modpath",        a_argument, NULL, 'M'},
        COMMON_LONG_OPTS
 };
 static const char * const q_opts_help[] = {
@@ -84,8 +84,24 @@ int q_main(int argc, char **argv)
                switch (i) {
                COMMON_GETOPTS_CASES(q)
                case 'M': modpath = optarg; break;
-               case 'm': reinitialize_metacache = 1; break;
-               case 'r': reinitialize = 1; break;
+               case 'm':
+                       if (optarg) {
+                               const char *path = initialize_flat(optarg, 
CACHE_METADATA, true);
+                               if (path) { /* silence warning */ }
+                               IF_DEBUG(free((void *)path));
+                               reinitialize_metacache = -1;
+                       } else
+                               reinitialize_metacache = 1;
+                       break;
+               case 'r':
+                       if (optarg) {
+                               const char *path = initialize_flat(optarg, 
CACHE_EBUILD, true);
+                               if (path) { /* silence warning */ }
+                               IF_DEBUG(free((void *)path));
+                               reinitialize = -1;
+                       } else
+                               reinitialize = 1;
+                       break;
                case 'i': install = 1; break;
                }
        }
@@ -128,8 +144,12 @@ int q_main(int argc, char **argv)
                return ret;
        }
 
-       if (reinitialize || reinitialize_metacache)
+       if (reinitialize > 0 || reinitialize_metacache > 0)
                return 0;
+       if (reinitialize < 0 || reinitialize_metacache < 0) {
+               reinitialize = reinitialize_metacache = 0;
+               return 0;
+       }
        if (argc == optind)
                q_usage(EXIT_FAILURE);
        if ((func = lookup_applet(argv[optind])) == NULL)

diff --git a/repo.postsync/q-reinit b/repo.postsync/q-reinit
new file mode 100644
index 0000000..0833c66
--- /dev/null
+++ b/repo.postsync/q-reinit
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+repository_name=$1
+repository_path=$3
+
+if [ -n "${repository_name}" ]; then
+       q ${PORTAGE_QUIET:+-q} --reinitialize="${repository_path}"
+fi
+
+:

Reply via email to