Explorar o código

Dpkg::Changelog: Add new Timestamp field to output

This field contains the date of the entry in seconds since the epoch. To
make it easier to retrieve the date in a format that is easier to handle.
Guillem Jover %!s(int64=10) %!d(string=hai) anos
pai
achega
ea22158eb8

+ 2 - 0
debian/changelog

@@ -9,6 +9,8 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
       in Dpkg::Changelog.
     - Replace changelog program parsers with perl modules.
     - Add a getter for the Time::Piece object in Dpkg::Changelog.
+    - Add new Timestamp field to Dpkg::Changelog output, which ends up on
+      dpkg-parsechangelog's output.
   * Test suite:
     - Bump perlcritic ValuesAndExpressions::RequireNumberSeparators minimum
       to 99999.

+ 11 - 0
man/dpkg-parsechangelog.1

@@ -97,6 +97,17 @@ concatenated (space-separated) comments from all the versions requested.
 .BI Maintainer: " author"
 .TP
 .BI Date: " date"
+The date of the entry as a string, as it appears in the changelog.
+With a \fBstrptime\fP(3) format "\fB%a, %d %b %Y %T %z\fP", but where the
+day of the week might not actually correspond to the real day obtained
+from the rest of the date string.
+If you need a more accurate representation of the date, use the
+\fBTimestamp\fP field, but take into account it might not be possible to
+map it back to the exact value in this field.
+.TP
+.BI Timestamp: " timestamp"
+The date of the entry as a timestamp in seconds since the epoch
+(since dpkg 1.18.8).
 .TP
 .BI Closes: " bug-number"
 The Closes fields of all included entries are merged.

+ 8 - 0
scripts/Dpkg/Changelog.pm

@@ -495,6 +495,7 @@ sub _format_dpkg {
     $f->{Distribution} = join(' ', $src->get_distributions());
     $f->{Maintainer} = $src->get_maintainer() // '';
     $f->{Date} = $src->get_timestamp() // '';
+    $f->{Timestamp} = $src->get_timepiece->epoch // '';
     $f->{Changes} = $src->get_dpkg_changes();
 
     # handle optional fields
@@ -550,6 +551,7 @@ sub _format_rfc822 {
 	$f->{Distribution} = join(' ', $entry->get_distributions());
 	$f->{Maintainer} = $entry->get_maintainer() // '';
 	$f->{Date} = $entry->get_timestamp() // '';
+	$f->{Timestamp} = $entry->get_timepiece->epoch // '';
 	$f->{Changes} = $entry->get_dpkg_changes();
 
 	# handle optional fields
@@ -613,6 +615,10 @@ person that created the (selected) entry
 
 date of the (selected) entry
 
+=item Timestamp
+
+date of the (selected) entry as a timestamp in seconds since the epoch
+
 =item Closes
 
 bugs closed by the (selected) entry/entries, sorted by bug number
@@ -766,6 +772,8 @@ New method: $c->format_range().
 
 Deprecated methods: $c->dpkg(), $c->rfc822().
 
+New field Timestamp in output formats.
+
 =head2 Version 1.00 (dpkg 1.15.6)
 
 Mark the module as public.

+ 4 - 1
scripts/Dpkg/Control/FieldsCore.pm

@@ -332,6 +332,9 @@ our %FIELDS = (
         allowed => ALL_SRC,
         separator => FIELD_SEP_COMMA,
     },
+    'Timestamp' => {
+        allowed => CTRL_CHANGELOG,
+    },
     'Triggers-Awaited' => {
         allowed => CTRL_FILE_STATUS,
         separator => FIELD_SEP_SPACE,
@@ -425,7 +428,7 @@ our %FIELD_ORDER = (
     ],
     CTRL_CHANGELOG() => [
         qw(Source Binary-Only Version Distribution Urgency Maintainer
-        Date Closes Changes)
+        Timestamp Date Closes Changes)
     ],
     CTRL_FILE_STATUS() => [ # Same as fieldinfos in lib/dpkg/parse.c
         qw(Package Essential Status Priority Section Installed-Size Origin

+ 4 - 0
scripts/t/Dpkg_Changelog.t

@@ -172,6 +172,7 @@ Version: 2.0-0etch1
 Distribution: stable
 Urgency: high
 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
+Timestamp: 1200235759
 Date: Sun, 13 Jan 2008 15:49:19 +0100
 Closes: 1000000 1111111 2222222
 Changes:
@@ -214,6 +215,7 @@ Version: 2.0-1
 Distribution: unstable frozen
 Urgency: medium
 Maintainer: Frank Lichtenheld <djpig@debian.org>
+Timestamp: 1200149359
 Date: Sun, 12 Jan 2008 15:49:19 +0100
 Closes: 1111111 2222222
 Changes:
@@ -246,6 +248,7 @@ Version: 2.0~b1-1
 Distribution: unstable
 Urgency: low
 Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
+Timestamp: 1200062959
 Date: Sun, 11 Jan 2008 15:49:19 +0100
 Changes:
  fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
@@ -258,6 +261,7 @@ Version: 1.0
 Distribution: experimental
 Urgency: high
 Maintainer: Frank Lichtenheld <djpig@debian.org>
+Timestamp: 1199976559
 Date: Sun, 10 Jan 2008 15:49:19 +0100
 Closes: 1000000
 Changes: