[Aptitude-devel] Bug#248561: aptitude: display origin (%O) in format strings

Jan Blunck jblunck at infradead.org
Fri Apr 11 15:25:30 UTC 2014


[Please CC me on replies.]

Hello Aptitude developers,

I've come across the problem described in bug 248561 (
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=248561) and I would like
to propose the attached changes which add the %O format field to display
the Origin of a package.

This functionality is specifically helpful when using multiple different
3rd party repositories with packages for the same target suite/codename.
For users of the Open Build Service this would dramatically improve the
usability of the presented information.

Thanks,
Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/aptitude-devel/attachments/20140411/f28762bb/attachment-0001.html>
-------------- next part --------------
commit c8797bd106e7fda242c82573260f607992b2ea6a
Author: Jan Blunck <jblunck at infradead.org>
Date:   Fri Apr 11 08:07:49 2014 -0700

    Add new format %O to display "Origin" field of packages (bdo #248561)
    
    For package maintainers that work with multiple package repositories for
    the same target suite or codename it is helpful to display the repository
    origin field. The Origin has no meaning wrt to repository layout and
    therefore can be filled with free form texts.
    
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=248561

diff --git a/src/pkg_columnizer.cc b/src/pkg_columnizer.cc
index 7642775..34ddb00 100644
--- a/src/pkg_columnizer.cc
+++ b/src/pkg_columnizer.cc
@@ -73,7 +73,8 @@ cw::config::column_type_defaults pkg_item::pkg_columnizer::defaults[pkg_columniz
   {17, false, true},    // downloadsize
   {4, false, false},    // pin_priority
   {15, false, true},    // hostname
-  {1, false, false}     // trust_state
+  {1, false, false},     // trust_state
+  {10, true, true},     // origin
 };
 
 // Default widths for:
@@ -489,6 +490,15 @@ cw::column_disposition pkg_item::pkg_columnizer::setup_column(const pkgCache::Pk
       else
 	return cw::column_disposition("", 0);
 
+    case origin:
+      if(!visible_ver.end())
+	{
+	  string buf = origins_text(visible_ver, ",");
+	  return cw::column_disposition(buf,0);
+	}
+      else
+	return cw::column_disposition("", 0);
+
     case hostname:
       {
 	char buf[256];
@@ -612,6 +622,8 @@ int pkg_item::pkg_columnizer::parse_column_type(char id)
       return sizechange;
     case 'i':
       return pin_priority;
+    case 'O':
+      return origin;
     default:
       return -1;
     }
diff --git a/src/pkg_columnizer.h b/src/pkg_columnizer.h
index b676db1..e49d826 100644
--- a/src/pkg_columnizer.h
+++ b/src/pkg_columnizer.h
@@ -68,7 +68,7 @@ public:
 	      autoset, tagged, archive, sizechange,
 
               progname, progver, brokencount, diskusage, downloadsize,
-	      pin_priority, hostname, trust_state, numtypes};
+	      pin_priority, hostname, trust_state, origin, numtypes};
   static cwidget::config::column_type_defaults defaults[numtypes];
   static const char *column_names[numtypes];
 
diff --git a/src/pkg_ver_item.cc b/src/pkg_ver_item.cc
index e159e40..789c9e1 100644
--- a/src/pkg_ver_item.cc
+++ b/src/pkg_ver_item.cc
@@ -90,6 +90,15 @@ cw::column_disposition pkg_ver_columnizer::setup_column(const pkgCache::VerItera
       else
 	return cw::column_disposition("", 0);
 
+    case origin:
+      if(!ver.end())
+	{
+	  string buf = origins_text(ver, ",");
+	  return cw::column_disposition(buf,0);
+	}
+      else
+	return cw::column_disposition("", 0);
+
     case installed_size:
       if(ver.end())
 	return cw::column_disposition("", 0);
diff --git a/src/solution_fragment.cc b/src/solution_fragment.cc
index e0ed179..6e084e5 100644
--- a/src/solution_fragment.cc
+++ b/src/solution_fragment.cc
@@ -34,6 +34,7 @@
 #include <generic/util/util.h>
 
 #include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string/join.hpp>
 
 #include <cwidget/fragment.h>
 #include <cwidget/generic/util/transcode.h>
@@ -85,6 +86,29 @@ string archives_text(const pkgCache::VerIterator &ver,
   return rval;
 }
 
+string origins_text(const pkgCache::VerIterator &ver,
+		    const std::string &separator)
+{
+  // Uniquify and sort the origins.
+  std::set<std::string> origins;
+
+  for(pkgCache::VerFileIterator vf=ver.FileList(); !vf.end(); ++vf)
+    {
+      static const std::string now("now");
+
+      // Suppress entry for "now" archive
+      if(vf.File().Archive() && (now.compare(vf.File().Archive()) == 0))
+	continue;
+
+      if(vf.File().Origin())
+	origins.insert(vf.File().Origin());
+      else
+	origins.insert(_("<NULL>"));
+    }
+
+  return boost::algorithm::join(origins, separator);
+}
+
 string dep_targets(const pkgCache::DepIterator &start)
 {
   string rval;
diff --git a/src/solution_fragment.h b/src/solution_fragment.h
index eb151c2..3df33a7 100644
--- a/src/solution_fragment.h
+++ b/src/solution_fragment.h
@@ -69,6 +69,18 @@ std::string archives_text(const pkgCache::VerIterator &v,
                           bool suppress_now = false,
                           const std::string &inter_archive_string = ", ");
 
+/** \return a list of the origins to which a version
+ *  belongs in the form "origin1,origin2,..."
+ *
+ *  The output will be sorted and contain each origin name at most
+ *  once.
+ *
+ *  \param v   the version whose origins are to be returned.
+ *  \param separator   The string to place between origins.
+ */
+std::string origins_text(const pkgCache::VerIterator &v,
+			 const std::string &separator = ", ");
+
 /** \return a cwidget::fragment describing the given choice. */
 cwidget::fragment *choice_fragment(const generic_choice<aptitude_universe> &c);
 


More information about the Aptitude-devel mailing list