From ab768a4a8829d7a964efe41aee1045631c97c1bf Mon Sep 17 00:00:00 2001 From: Johannes Winkelmann Date: Wed, 12 Apr 2006 16:06:17 +0000 Subject: [PATCH] prt-get: support recursive dependent and a tree view git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1234 0b5ae1c7-2405-0410-a7fc-ba219f786e1e --- ChangeLog | 1 + TODO | 2 ++ configure | 2 +- configure.in | 2 +- doc/prt-get.8 | 8 +++++--- src/argparser.cpp | 18 +++++++++++++++++- src/argparser.h | 5 +++++ src/main.cpp | 4 ++-- src/prtget.cpp | 35 ++++++++++++++++++++++++++++++----- src/prtget.h | 6 ++++-- 10 files changed, 68 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12f63f5..dfdfc50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ - update default prt-get.conf to reflect new port hierarchy (core/opt/contrib) - add timestamps to log files - fix aliasing bug introduce earlier in the .12 session (thanks Mark) +- add --recursive and --tree for dependent * 0.5.11 29.05.2005 Johannes Winkelmann - add --path to 'ls' diff --git a/TODO b/TODO index dc1f30a..7cc58d2 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +- add --rebuild-set to dependent +--------------------------- - use `eval $(fgrep -h 'PKGMK_PACKAGE_DIR=' $(which pkgmk) /etc/pkgmk.conf) && echo $PKGMK_PACKAGE_DIR` to determine PACKAGE_DIR - add update-footprint, update-md5sum commands (patch in trac) diff --git a/configure b/configure index 744f2ad..fa8fe49 100755 --- a/configure +++ b/configure @@ -1614,7 +1614,7 @@ fi # Define the identity of the package. PACKAGE=prt-get - VERSION=0.5.12pre2 + VERSION=0.5.12pre4 cat >>confdefs.h <<_ACEOF diff --git a/configure.in b/configure.in index cafe635..b3494f7 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ # Process this file with autoconf to produce a configure script. AC_INIT AC_CONFIG_SRCDIR([src/prtget.cpp]) -AM_INIT_AUTOMAKE(prt-get,0.5.12pre2) +AM_INIT_AUTOMAKE(prt-get,0.5.12pre4) dnl Determine default prefix diff --git a/doc/prt-get.8 b/doc/prt-get.8 index b2fac60..eb2ae90 100644 --- a/doc/prt-get.8 +++ b/doc/prt-get.8 @@ -209,9 +209,11 @@ to make an install including dependencies .TP .B dependent print a list of package which depend on -.B package. -Only list direct dependencies. Usually shows dependent packages which -are installed. To see all dependencies, add the --all switch +.B package. + +Usually shows dependent packages which are installed. To see all dependencies, +add the --all switch; use --recursive to get a recursive list (without +duplication), and --tree to get a nicely indented one .TP .B deptree diff --git a/src/argparser.cpp b/src/argparser.cpp index c39e626..1aabbc4 100644 --- a/src/argparser.cpp +++ b/src/argparser.cpp @@ -45,7 +45,9 @@ ArgParser::ArgParser( int argc, char** argv ) m_preferHigher( false ), m_strictDiff( false ), m_useRegex(false), - m_fullPath(false) + m_fullPath(false), + m_recursive(false), + m_printTree(false) { } @@ -196,6 +198,10 @@ bool ArgParser::parse() m_useRegex = true; } else if ( s == "--full" ) { m_fullPath = true; + } else if ( s == "--recursive" ) { + m_recursive = true; + } else if ( s == "--tree" ) { + m_printTree = true; } else if ( s == "-f" ) { m_pkgaddArgs += " " + s; @@ -382,6 +388,16 @@ bool ArgParser::printPath() const return m_printPath; } +bool ArgParser::recursive() const +{ + return m_recursive; +} + +bool ArgParser::printTree() const +{ + return m_printTree; +} + const string& ArgParser::commandName() const { return m_commandName; diff --git a/src/argparser.h b/src/argparser.h index 1859c35..0260f06 100644 --- a/src/argparser.h +++ b/src/argparser.h @@ -57,6 +57,8 @@ public: bool strictDiff() const; bool useRegex() const; bool fullPath() const; + bool recursive() const; + bool printTree() const; const string& alternateConfigFile() const; const string& pkgmkArgs() const; @@ -107,6 +109,9 @@ private: bool m_useRegex; bool m_fullPath; + bool m_recursive; + bool m_printTree; + string m_alternateConfigFile; string m_pkgmkArgs; string m_pkgaddArgs; diff --git a/src/main.cpp b/src/main.cpp index 1af02ed..64904af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ int main( int argc, char** argv ) << endl; } else if ( !argParser.isCommandGiven() ) { if (argParser.commandName() != "") { - cerr << "prt-get: Unknown command '" + cerr << "prt-get: Unknown command '" << argParser.commandName() << "'. " << "try prt-get help for more information" << endl; } else { @@ -122,7 +122,7 @@ int main( int argc, char** argv ) prtGet.readme(); break; case ArgParser::DEPENDENT: - prtGet.printDependendent(); + prtGet.printDependent(); break; case ArgParser::SYSUP: prtGet.sysup(); diff --git a/src/prtget.cpp b/src/prtget.cpp index 92d36d4..7d0dab4 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -1244,37 +1244,58 @@ bool PrtGet::printFile(const string& file) return true; } -void PrtGet::printDependendent() +void PrtGet::printDependent() { assertExactArgCount(1); initRepo(); string arg = *(m_parser->otherArgs().begin()); + printDependent(arg, 0); +} + +void PrtGet::printDependent(const string& dep, int level) +{ map::const_iterator it = m_repo->packages().begin(); + static map shownMap; set dependent; for ( ; it != m_repo->packages().end(); ++it ) { // TODO: is the following line needed? const Package* p = it->second; - if ( p && p->dependencies().find( arg ) != string::npos ) { + if ( p && p->dependencies().find( dep ) != string::npos ) { list tokens; StringHelper::split( p->dependencies(), ',', tokens ); list::iterator it = find( tokens.begin(), tokens.end(), - arg ); + dep ); if ( it != tokens.end() ) { dependent.insert( p ); } } } - + // prepared for recursive search + string indent = ""; + if (m_parser->printTree()) { + for (int i = 0; i < level; ++i) { + indent += " "; + } + } set::iterator it2 = dependent.begin(); for ( ; it2 != dependent.end(); ++it2 ) { const Package* p = *it2; + + if (m_parser->recursive() && !m_parser->printTree()) { + if (shownMap[p->name()]) { + continue; + } + shownMap[p->name()] = true; + } + if ( m_parser->all() || m_pkgDB->isInstalled( p->name() ) ) { - cout << p->name(); + + cout << indent << p->name(); if ( m_parser->verbose() > 0 ) { cout << " " << p->version() << "-" << p->release(); } @@ -1283,6 +1304,10 @@ void PrtGet::printDependendent() } cout << endl; + + if (m_parser->recursive()) { + printDependent( p->name(), level+2 ); + } } } } diff --git a/src/prtget.h b/src/prtget.h index c5ad4db..602f8c2 100644 --- a/src/prtget.h +++ b/src/prtget.h @@ -67,7 +67,7 @@ public: void current(); void printDepends( bool simpleListing=false ); void printDependTree(); - void printDependendent(); + void printDependent(); void printDiff(); void printQuickDiff(); @@ -96,6 +96,8 @@ public: protected: void printDepsLevel(int indent, const Package* package); + + void printDependent(const std::string& dep, int level); void executeTransaction( InstallTransaction& transaction, bool update, bool group ); @@ -140,7 +142,7 @@ protected: void assertMaxArgCount(int count); void assertExactArgCount(int count); void argCountFailure(int count, const string& specifier); - + bool greaterThan( const string& v1, const string& v2 ); static bool printFile(const string& file); };