23
23
#include <sigc++/adaptors/bind.h>
25
27
using namespace std;
27
/** Represents the information needed to retrieve a changelog. */
28
struct changelog_entity
30
/** The name of the source package. */
33
/** The name of the source version. */
36
/** The section of the package. */
39
/** Initializes the empty entity: all the members are 0-length
42
changelog_entity():pkg(), ver(), section()
46
changelog_entity(const std::string &_pkg,
47
const std::string &_ver,
48
const std::string &_section)
49
:pkg(_pkg), ver(_ver), section(_section)
53
changelog_entity &operator=(const changelog_entity &other)
57
section = other.section;
61
/** Find a source record in the given set of source records
62
* corresponding to the package pkg, version ver.
64
* \param records the source records object
65
* \param pkg the package name to match on
66
* \param ver the version string to match on
68
* \return a matching changelog entity, or the empty entity if no
71
changelog_entity find_src_ver(pkgSourceList &list,
72
const std::string &pkg,
73
const std::string &ver)
75
pkgSrcRecords records(list);
78
pkgSrcRecords :: Parser *parser = records.Find(pkg.c_str());
80
while(parser != NULL && parser->Version() != ver)
81
parser = records.Find(pkg.c_str());
84
return changelog_entity();
86
return changelog_entity(pkg, ver, parser->Section());
89
static void set_name(temp::name n, temp::name *target)
31
void set_name(temp::name n, temp::name *target)
147
/** Find a source record in the given set of source records
148
* corresponding to the given package and archive.
150
* IMPORTANT: You should dump errors before starting this routine; it
151
* assumes that there are no pending errors.
153
* \param records the source records object
154
* \param pkg the package name to match on
155
* \param ver the version string to match on
157
* \return a matching changelog entity, or the empty entity
158
* ("","","") if no such entity exists.
161
// Based heavily on pkgSrcRecords.
162
changelog_entity find_src_archive(pkgSourceList &list,
163
const std::string &pkg,
164
const std::string &archive)
166
for(pkgSourceList::const_iterator i = list.begin(); i!=list.end(); ++i)
168
if((*i)->GetDist() != archive)
171
vector<pkgIndexFile *> *indexes = (*i)->GetIndexFiles();
173
for(vector<pkgIndexFile *> :: const_iterator j = indexes->begin();
174
j != indexes->end(); ++j)
176
auto_ptr<pkgSrcRecords :: Parser> p((*j)->CreateSrcParser());
178
if(_error->PendingError())
179
return changelog_entity();
182
// Step through the file until we reach the end or find
184
while(p.get()->Step() == true)
186
if(_error->PendingError() == true)
187
return changelog_entity();
189
if(p.get()->Package() == pkg)
190
return changelog_entity(pkg,
198
return changelog_entity();
201
90
bool do_cmdline_changelog(const vector<string> &packages)
268
if(ver.end() && source == cmdline_version_version)
269
filename = changelog_by_version(package, sourcestr);
159
aptitude::cmdline::source_package p =
160
aptitude::cmdline::find_source_package(package,
164
download_manager *m = NULL;
167
m = get_changelog_from_source(p.get_package(),
171
sigc::bind(sigc::ptr_fun(&set_name), &filename));
272
download_manager *m = get_changelog(ver,
273
sigc::bind(sigc::ptr_fun(&set_name), &filename));
276
cmdline_do_download(m);
283
changelog_entity ent;
287
case cmdline_version_cand:
288
// In this case, pull the first one we see (not very
289
// elegant, but finding the actual candidate is a bit
292
pkgSrcRecords r(*apt_source_list);
294
pkgSrcRecords :: Parser *p(r.Find(package.c_str()));
295
while(p != NULL && p->Package() != package)
296
p = r.Find(package.c_str());
299
ent = changelog_entity(package, p->Version(),
305
case cmdline_version_archive:
306
_error->DumpErrors();
307
ent = find_src_archive(*apt_source_list,
312
case cmdline_version_version:
313
ent = find_src_ver(*apt_source_list, package, sourcestr);
175
// Fall back to string-based guessing.
176
if(ver.end() && source == cmdline_version_version)
316
177
filename = changelog_by_version(package, sourcestr);
322
if(!filename.valid() && !ent.pkg.empty())
325
= get_changelog_from_source(ent.pkg,
329
sigc::bind(sigc::ptr_fun(&set_name), &filename));
179
m = get_changelog(ver,
180
sigc::bind(sigc::ptr_fun(&set_name), &filename));
185
cmdline_do_download(m, 0);
191
aptitude::cmdline::source_package p =
192
aptitude::cmdline::find_source_package(package,
196
download_manager *m = NULL;
199
m = get_changelog_from_source(p.get_package(),
203
sigc::bind(sigc::ptr_fun(&set_name), &filename));
206
// If the user didn't specify a version or selected a
207
// candidate and we couldn't find anything, we have no
208
// recourse. But if they passed a version number, we
209
// can fall back to just blindly guessing that the
333
cmdline_do_download(m);
214
case cmdline_version_cand:
217
case cmdline_version_archive:
220
case cmdline_version_version:
221
filename = changelog_by_version(package, sourcestr);
226
if(!filename.valid() && m != NULL)
228
cmdline_do_download(m, 0);
340
234
if(!filename.valid())