~ubuntu-branches/ubuntu/lucid/aptitude/lucid-proposed

« back to all changes in this revision

Viewing changes to src/cmdline/cmdline_changelog.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-05-27 10:28:10 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527102810-pxc090mnjkr4xlek
Tags: 0.4.11.2-1ubuntu1
* Merge from debian unstable, remaining changes:
  - 03_branding.dpatch: ubuntu branding
  - 04_changelog.dpatch: take changelogs from changelogs.ubuntu.com
  - 07_hide_recommends_warning.dpatch: do not show a warning about
    missing recommends
  - 08_ubuntu_default_source.dpatch: do not clean lists directory
    on transient network failures
  - 11_gxx43.dpatch:build tests without -Werror
* Updated:
  - 03_branding.dpatch
* Disabled 07_hide_recommends warning because we do install 
  recommends now by default too

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <sigc++/adaptors/bind.h>
24
24
 
 
25
#include <stdlib.h>
 
26
 
25
27
using namespace std;
26
28
 
27
 
/** Represents the information needed to retrieve a changelog. */
28
 
struct changelog_entity
29
 
{
30
 
  /** The name of the source package. */
31
 
  std::string pkg;
32
 
 
33
 
  /** The name of the source version. */
34
 
  std::string ver;
35
 
 
36
 
  /** The section of the package. */
37
 
  std::string section;
38
 
 
39
 
  /** Initializes the empty entity: all the members are 0-length
40
 
   *  strings.
41
 
   */
42
 
  changelog_entity():pkg(), ver(), section()
43
 
  {
44
 
  }
45
 
 
46
 
  changelog_entity(const std::string &_pkg,
47
 
                   const std::string &_ver,
48
 
                   const std::string &_section)
49
 
    :pkg(_pkg), ver(_ver), section(_section)
50
 
  {
51
 
  }
52
 
 
53
 
  changelog_entity &operator=(const changelog_entity &other)
54
 
  {
55
 
    pkg = other.pkg;
56
 
    ver = other.ver;
57
 
    section = other.section;
58
 
  }
59
 
};
60
 
 
61
 
/** Find a source record in the given set of source records
62
 
 *  corresponding to the package pkg, version ver.
63
 
 *
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
67
 
 *
68
 
 *  \return a matching changelog entity, or the empty entity if no
69
 
 *  such entity exists.
70
 
 */
71
 
changelog_entity find_src_ver(pkgSourceList &list,
72
 
                              const std::string &pkg,
73
 
                              const std::string &ver)
74
 
{
75
 
  pkgSrcRecords records(list);
76
 
  records.Restart();
77
 
 
78
 
  pkgSrcRecords :: Parser *parser = records.Find(pkg.c_str());
79
 
 
80
 
  while(parser != NULL && parser->Version() != ver)
81
 
    parser = records.Find(pkg.c_str());
82
 
 
83
 
  if(parser == NULL)
84
 
    return changelog_entity();
85
 
  else
86
 
    return changelog_entity(pkg, ver, parser->Section());
87
 
}
88
 
 
89
 
static void set_name(temp::name n, temp::name *target)
 
29
namespace
 
30
{
 
31
void set_name(temp::name n, temp::name *target)
90
32
{
91
33
  *target = n;
92
34
}
112
54
                                                             &rval));
113
55
  if(m != NULL)
114
56
    {
115
 
      res = cmdline_do_download(m);
 
57
      res = cmdline_do_download(m, 0);
116
58
      delete m;
117
59
    }
118
60
 
122
64
                                    sigc::bind(sigc::ptr_fun(set_name), &rval));
123
65
      if(m != NULL)
124
66
        {
125
 
          res = cmdline_do_download(m);
 
67
          res = cmdline_do_download(m, 0);
126
68
          delete m;
127
69
        }
128
70
    }
133
75
                                    sigc::bind(sigc::ptr_fun(set_name), &rval));
134
76
      if(m != NULL)
135
77
        {
136
 
          res = cmdline_do_download(m);
 
78
          res = cmdline_do_download(m, 0);
137
79
          delete m;
138
80
        }
139
81
    }
143
85
  else
144
86
    return rval;
145
87
}
146
 
 
147
 
/** Find a source record in the given set of source records
148
 
 *  corresponding to the given package and archive.
149
 
 *
150
 
 *  IMPORTANT: You should dump errors before starting this routine; it
151
 
 *  assumes that there are no pending errors.
152
 
 *
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
156
 
 *
157
 
 *  \return a matching changelog entity, or the empty entity
158
 
 *  ("","","") if no such entity exists.
159
 
 */
160
 
 
161
 
// Based heavily on pkgSrcRecords.
162
 
changelog_entity find_src_archive(pkgSourceList &list,
163
 
                                  const std::string &pkg,
164
 
                                  const std::string &archive)
165
 
{
166
 
  for(pkgSourceList::const_iterator i = list.begin(); i!=list.end(); ++i)
167
 
    {
168
 
      if((*i)->GetDist() != archive)
169
 
        continue;
170
 
 
171
 
      vector<pkgIndexFile *> *indexes = (*i)->GetIndexFiles();
172
 
 
173
 
      for(vector<pkgIndexFile *> :: const_iterator j = indexes->begin();
174
 
          j != indexes->end(); ++j)
175
 
        {
176
 
          auto_ptr<pkgSrcRecords :: Parser> p((*j)->CreateSrcParser());
177
 
 
178
 
          if(_error->PendingError())
179
 
            return changelog_entity();
180
 
          if(p.get() != 0)
181
 
            {
182
 
              // Step through the file until we reach the end or find
183
 
              // the package:
184
 
              while(p.get()->Step() == true)
185
 
                {
186
 
                  if(_error->PendingError() == true)
187
 
                    return changelog_entity();
188
 
 
189
 
                  if(p.get()->Package() == pkg)
190
 
                    return changelog_entity(pkg,
191
 
                                            p.get()->Version(),
192
 
                                            p.get()->Section());
193
 
                }
194
 
            }
195
 
        }
196
 
    }
197
 
 
198
 
  return changelog_entity();
199
88
}
200
89
 
201
90
bool do_cmdline_changelog(const vector<string> &packages)
240
129
 
241
130
      temp::name filename;
242
131
 
243
 
      // For real packages/versions, we can do a sanity check.
 
132
      // For real packages/versions, we can do a sanity check on the
 
133
      // version and warn the user if it looks like it doesn't have a
 
134
      // corresponding source package.
244
135
      if(!pkg.end())
245
136
        {
246
137
          pkgCache::VerIterator ver=cmdline_find_ver(pkg,
265
156
                }
266
157
            }
267
158
 
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,
 
161
                                                   source,
 
162
                                                   sourcestr);
 
163
 
 
164
          download_manager *m = NULL;
 
165
          if(!p.valid())
 
166
            {
 
167
              m = get_changelog_from_source(p.get_package(),
 
168
                                            p.get_version(),
 
169
                                            p.get_section(),
 
170
                                            pkg.Name(),
 
171
                                            sigc::bind(sigc::ptr_fun(&set_name), &filename));
 
172
            }
270
173
          else
271
174
            {
272
 
              download_manager *m = get_changelog(ver,
273
 
                                                  sigc::bind(sigc::ptr_fun(&set_name), &filename));
274
 
              if(m != NULL)
275
 
                {
276
 
                  cmdline_do_download(m);
277
 
                  delete m;
278
 
                }
279
 
            }
280
 
        }
281
 
      else
282
 
        {
283
 
          changelog_entity ent;
284
 
 
285
 
          switch(source)
286
 
            {
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
290
 
              // hard)
291
 
              {
292
 
                pkgSrcRecords r(*apt_source_list);
293
 
 
294
 
                pkgSrcRecords :: Parser *p(r.Find(package.c_str()));
295
 
                while(p != NULL && p->Package() != package)
296
 
                  p = r.Find(package.c_str());
297
 
 
298
 
                if(p != NULL)
299
 
                  ent = changelog_entity(package, p->Version(),
300
 
                                         p->Section());
301
 
              }
302
 
 
303
 
              break;
304
 
 
305
 
            case cmdline_version_archive:
306
 
              _error->DumpErrors();
307
 
              ent = find_src_archive(*apt_source_list,
308
 
                                     package, sourcestr);
309
 
 
310
 
              break;
311
 
 
312
 
            case cmdline_version_version:
313
 
              ent = find_src_ver(*apt_source_list, package, sourcestr);
314
 
 
315
 
              if(ent.pkg.empty())
 
175
              // Fall back to string-based guessing.
 
176
              if(ver.end() && source == cmdline_version_version)
316
177
                filename = changelog_by_version(package, sourcestr);
317
 
 
318
 
              break;
319
 
            }
320
 
 
321
 
 
322
 
          if(!filename.valid() && !ent.pkg.empty())
323
 
            {
324
 
              download_manager *m
325
 
                = get_changelog_from_source(ent.pkg,
326
 
                                            ent.ver,
327
 
                                            ent.section,
328
 
                                            ent.pkg,
329
 
                                            sigc::bind(sigc::ptr_fun(&set_name), &filename));
330
 
 
331
 
              if(m != NULL)
 
178
              else
 
179
                m = get_changelog(ver,
 
180
                                  sigc::bind(sigc::ptr_fun(&set_name), &filename));
 
181
            }
 
182
 
 
183
          if(m != NULL)
 
184
            {
 
185
              cmdline_do_download(m, 0);
 
186
              delete m;
 
187
            }
 
188
        }
 
189
      else
 
190
        {
 
191
          aptitude::cmdline::source_package p =
 
192
            aptitude::cmdline::find_source_package(package,
 
193
                                                   source,
 
194
                                                   sourcestr);
 
195
 
 
196
          download_manager *m = NULL;
 
197
 
 
198
          if(p.valid())
 
199
            m = get_changelog_from_source(p.get_package(),
 
200
                                          p.get_version(),
 
201
                                          p.get_section(),
 
202
                                          p.get_package(),
 
203
                                          sigc::bind(sigc::ptr_fun(&set_name), &filename));
 
204
          else
 
205
            {
 
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
 
210
              // version exists.
 
211
 
 
212
              switch(source)
332
213
                {
333
 
                  cmdline_do_download(m);
334
 
 
335
 
                  delete m;
 
214
                case cmdline_version_cand:
 
215
                  break;
 
216
 
 
217
                case cmdline_version_archive:
 
218
                  break;
 
219
 
 
220
                case cmdline_version_version:
 
221
                  filename = changelog_by_version(package, sourcestr);
 
222
                  break;
336
223
                }
337
224
            }
 
225
 
 
226
          if(!filename.valid() && m != NULL)
 
227
            {
 
228
              cmdline_do_download(m, 0);
 
229
 
 
230
              delete m;
 
231
            }
338
232
        }
339
233
 
340
234
      if(!filename.valid())