[pacman-dev] [PATCH] Improve changelog handling

Dan McGee dpmcgee at gmail.com
Fri Dec 7 14:00:05 EST 2007


On Dec 7, 2007 12:41 PM, Xavier <shiningxc at gmail.com> wrote:
>
> On Sat, Dec 08, 2007 at 02:47:23AM +1000, Allan McRae wrote:
> > diff --git a/src/pacman/package.c b/src/pacman/package.c
> > index ac3f820..00c3535 100644
> > --- a/src/pacman/package.c
> > +++ b/src/pacman/package.c
> > @@ -232,29 +232,26 @@ void dump_pkg_files(pmpkg_t *pkg)
> >      fflush(stdout);
> >  }
> >
> > -/* Display the changelog of an installed package
> > +/* Display the changelog of a package
> >   */
> > -void dump_pkg_changelog(char *clfile, const char *pkgname)
> > +void dump_pkg_changelog(pmpkg_t *pkg)
> >  {
> > -    FILE* fp = NULL;
> > -    char line[PATH_MAX+1];
> > -
> > -    if((fp = fopen(clfile, "r")) == NULL)
> > -    {
> > -        fprintf(stderr, _("error: no changelog available for '%s'.\n"),
> > pkgname);
> > +    alpm_list_t *changelog = NULL;
> > +    alpm_list_t *i;
> > +    char line[PATH_MAX];
> > +
> > +    changelog = alpm_pkg_get_changelog(pkg);
> > +    if(changelog == NULL) {
> > +        fprintf(stderr, _("error: no changelog available for '%s'.\n"),
> > alpm_pkg_get_name(pkg));
> >          return;
> > -    }
> > -    else
> > -    {
> > -        while(!feof(fp))
> > -        {
> > -            fgets(line, (int)PATH_MAX, fp);
> > -            printf("%s", line);
> > -            line[0] = '\0';
> > +    } else {
> > +        for(i = changelog; i; i = alpm_list_next(i)) {
> > +            snprintf(line, PATH_MAX-1, "%s", (char*)alpm_list_getdata(i));
> > +            fprintf(stdout, "%s\n", line);
> >          }
> > -        fclose(fp);
> > -        return;
> >      }
> > +
> > +    FREELIST(changelog);
> >  }
> >
>
> Dan, you said earlier the FREELIST macros shouldn't be used in the frontend.
> I don't know why I said "ah, ok", because I actually don't understand this,
> and Nagy didn't either.

Hmm, you should question me on things like this. Not sure why I said that...

If you point me to that email, I might be able to remember why I was
thinking wrong. Since we have it in alpm_list.h, it should be legit to
use.

> There are several other places in the frontend where it could be used instead
> of alpm_list_free_inner(list, free); alpm_list_free(list);

I agree, its helpful to clean things up.

-Dan




More information about the pacman-dev mailing list