Merge lp:~jelmer/bzr-builder/revtime into lp:bzr-builder

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 134
Merged at revision: 135
Proposed branch: lp:~jelmer/bzr-builder/revtime
Merge into: lp:bzr-builder
Diff against target: 95 lines (+53/-1)
2 files modified
recipe.py (+35/-1)
tests/test_recipe.py (+18/-0)
To merge this branch: bzr merge lp:~jelmer/bzr-builder/revtime
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+64169@code.launchpad.net

Description of the change

Add {revtime}, {revdate} substitution variables.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/10/2011 02:31 PM, Jelmer Vernooij wrote:
> Jelmer Vernooij has proposed merging lp:~jelmer/bzr-builder/revtime into lp:bzr-builder.
>
> Requested reviews:
> bzr-builder developers (bzr-builder-devs)
> Related bugs:
> Bug #793072 in bzr-builder: "Provide deb-version variables for revision commit time/date"
> https://bugs.launchpad.net/bzr-builder/+bug/793072
>
> For more details, see:
> https://code.launchpad.net/~jelmer/bzr-builder/revtime/+merge/64169
>
> Add {revtime}, {revdate} substitution variables.

It seems like dates are often spelled out as %Y-%m-%d rather than
%Y%m%d. I don't know where this would explicitly matter, but the former
is always obviously a date, while the latter can sometimes just be a
number, or something else.

Just a thought,
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3yK/4ACgkQJdeBCYSNAAMivwCglVryPsEbWTimiGQL/MlbMkmH
llUAnjyjHa1dAvmfC4pCXKgheporT7NH
=i2bI
-----END PGP SIGNATURE-----

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On 06/10/2011 04:36 PM, John Arbash Meinel wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 06/10/2011 02:31 PM, Jelmer Vernooij wrote:
>> Jelmer Vernooij has proposed merging lp:~jelmer/bzr-builder/revtime into lp:bzr-builder.
>>
>> Requested reviews:
>> bzr-builder developers (bzr-builder-devs)
>> Related bugs:
>> Bug #793072 in bzr-builder: "Provide deb-version variables for revision commit time/date"
>> https://bugs.launchpad.net/bzr-builder/+bug/793072
>>
>> For more details, see:
>> https://code.launchpad.net/~jelmer/bzr-builder/revtime/+merge/64169
>>
>> Add {revtime}, {revdate} substitution variables.
> It seems like dates are often spelled out as %Y-%m-%d rather than
> %Y%m%d. I don't know where this would explicitly matter, but the former
> is always obviously a date, while the latter can sometimes just be a
> number, or something else.
>
"-" has special meaning in Debian versions, so we usually try to avoid
it. %Y%m is consistent with the existing {time} and {date} substitution
variables.

That said, I think timestamps should generally be avoided as they can be
ambiguous (which of the 5 commits that date was built?).

Cheers,

Jelmer

Revision history for this message
James Westby (james-w) wrote :

Hi,

Perhaps a base class would be useful here as the only difference
is the format string?

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'recipe.py'
2--- recipe.py 2011-06-09 12:47:24 +0000
3+++ recipe.py 2011-06-10 12:32:59 +0000
4@@ -16,6 +16,7 @@
5 import os
6 import signal
7 import subprocess
8+import time
9
10 from bzrlib import (
11 branch,
12@@ -220,6 +221,34 @@
13 return revno
14
15
16+class RevtimeVariable(BranchSubstitutionVariable):
17+
18+ basename = "revtime"
19+
20+ def __init__(self, branch_name, branch, revid):
21+ super(RevtimeVariable, self).__init__(branch_name)
22+ self.branch = branch
23+ self.revid = revid
24+
25+ def get(self):
26+ rev = self.branch.repository.get_revision(self.revid)
27+ return time.strftime("%Y%m%d%H%M", time.gmtime(rev.timestamp))
28+
29+
30+class RevdateVariable(BranchSubstitutionVariable):
31+
32+ basename = "revdate"
33+
34+ def __init__(self, branch_name, branch, revid):
35+ super(RevdateVariable, self).__init__(branch_name)
36+ self.branch = branch
37+ self.revid = revid
38+
39+ def get(self):
40+ rev = self.branch.repository.get_revision(self.revid)
41+ return time.strftime("%Y%m%d", time.gmtime(rev.timestamp))
42+
43+
44 def extract_svn_revnum(rev):
45 try:
46 foreign_revid = rev.foreign_revid
47@@ -321,7 +350,8 @@
48 simple_vars = [TimeVariable.name, DateVariable.name, RevnoVariable.name,
49 SubversionRevnumVariable.name, DebUpstreamVariable.name,
50 DebUpstreamBaseVariable.name, GitCommitVariable.name,
51- LatestTagVariable.name, DebVersionVariable.name]
52+ LatestTagVariable.name, DebVersionVariable.name, RevdateVariable.name,
53+ RevtimeVariable.name]
54
55
56 def check_expanded_deb_version(base_branch):
57@@ -944,6 +974,10 @@
58 self.deb_version = git_commit_var.replace(self.deb_version)
59 latest_tag_var = LatestTagVariable(branch_name, branch, revid)
60 self.deb_version = latest_tag_var.replace(self.deb_version)
61+ revdate_var = RevdateVariable(branch_name, branch, revid)
62+ self.deb_version = revdate_var.replace(self.deb_version)
63+ revtime_var = RevtimeVariable(branch_name, branch, revid)
64+ self.deb_version = revtime_var.replace(self.deb_version)
65
66 def substitute_time(self, time):
67 """Substitute the time in to deb_version if needed.
68
69=== modified file 'tests/test_recipe.py'
70--- tests/test_recipe.py 2011-06-05 13:56:06 +0000
71+++ tests/test_recipe.py 2011-06-10 12:32:59 +0000
72@@ -1121,6 +1121,24 @@
73 self.assertTrue(str(e).startswith("No tags set on branch None mainline"),
74 e)
75
76+ def test_substitute_revdate(self):
77+ br = self.make_branch("source")
78+ source = br.create_checkout("checkout")
79+ source.commit("one")
80+ source.commit("two", timestamp=1307708628, timezone=0)
81+ branch1 = BaseRecipeBranch("source", "foo-{revdate}", 0.2)
82+ resolve_revisions(branch1)
83+ self.assertEqual("foo-20110610", branch1.deb_version)
84+
85+ def test_substitute_revtime(self):
86+ br = self.make_branch("source")
87+ source = br.create_checkout("checkout")
88+ source.commit("one")
89+ source.commit("two", timestamp=1307708628, timezone=0)
90+ branch1 = BaseRecipeBranch("source", "foo-{revtime}", 0.2)
91+ resolve_revisions(branch1)
92+ self.assertEqual("foo-201106101223", branch1.deb_version)
93+
94
95 class StringifyTests(TestCaseInTempDir):
96

Subscribers

People subscribed via source and target branches