Merge lp:~vila/bzr-update-copyright/506041-copyright-5-first-lines into lp:bzr-update-copyright

Proposed by Vincent Ladeuil
Status: Merged
Merged at revision: 13
Proposed branch: lp:~vila/bzr-update-copyright/506041-copyright-5-first-lines
Merge into: lp:bzr-update-copyright
Diff against target: 101 lines (+46/-7)
3 files modified
__init__.py (+1/-2)
test_update_copyright.py (+31/-0)
update_copyright.py (+14/-5)
To merge this branch: bzr merge lp:~vila/bzr-update-copyright/506041-copyright-5-first-lines
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+215101@code.launchpad.net

Commit message

Support copyright line in the 5 first lines of the project.

Description of the change

This fix allows the copyright lines to be in the 5 first lines of a file.

It also fixes compatibility with recent bzr versions.

I've been using this fix for quite some time now (uncommitted in my local version, bad vila ;)

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Forget the compatibility bit, I didn't noticed the same fix was already in trunk (which I discovered when fixing the conflicts ;-)

14. By Vincent Ladeuil

Merge trunk resolving conflicts.

Revision history for this message
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2013-05-02 16:17:25 +0000
3+++ __init__.py 2014-04-10 08:19:04 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (C) 2010 Canonical Ltd
6+# Copyright (C) 2010, 2014 Canonical Ltd
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10@@ -67,7 +67,6 @@
11
12 tree, relpaths = workingtree.WorkingTree.open_containing_paths(
13 path_list)
14-
15 if relpaths == ['']:
16 # Selecting just the root selects everything
17 relpaths = None
18
19=== modified file 'test_update_copyright.py'
20--- test_update_copyright.py 2010-01-12 16:05:09 +0000
21+++ test_update_copyright.py 2014-04-10 08:19:04 +0000
22@@ -160,6 +160,37 @@
23 self.assertFileEqual('Copyright (c) 2008, 2009, %d Foo Bar\n'
24 'different content\n' % (year,), 'file')
25
26+ def test_update_copyright_not_first_line(self):
27+ t, rev_ids = self.make_old_modified_tree()
28+ self.build_tree_contents([('file',
29+ '\n\n\nCopyright (c) 2008 Foo Bar\nultimate content\n')])
30+ rev_ids.append(
31+ t.commit('remod file', timestamp=1231353864, timezone=0)) # 2010
32+ bt = t.basis_tree()
33+ bt.lock_read()
34+ self.addCleanup(bt.unlock)
35+ self.assertEqual('updated',
36+ update_copyright.update_copyright(t, bt, 'file'))
37+ year = datetime.datetime.now().year
38+ self.assertFileEqual(
39+ '\n\n\nCopyright (c) 2008, 2009, %d Foo Bar\n'
40+ 'ultimate content\n' % (year,), 'file')
41+
42+ def test_update_copyright_after_max_line(self):
43+ t, rev_ids = self.make_old_modified_tree()
44+ self.build_tree_contents([('file',
45+ '\n\n\n\n\nCopyright (c) 2008 Foo Bar\nultimate content\n')])
46+ rev_ids.append(
47+ t.commit('remod file', timestamp=1231353864, timezone=0)) # 2010
48+ bt = t.basis_tree()
49+ bt.lock_read()
50+ self.addCleanup(bt.unlock)
51+ self.assertEqual('no-copyright',
52+ update_copyright.update_copyright(t, bt, 'file'))
53+ self.assertFileEqual(
54+ '\n\n\n\n\nCopyright (c) 2008 Foo Bar\n'
55+ 'ultimate content\n', 'file')
56+
57 def test_no_copyright(self):
58 t, rev_ids = self.make_old_modified_tree()
59 self.build_tree_contents([('file', 'No cc line\n')])
60
61=== modified file 'update_copyright.py'
62--- update_copyright.py 2010-01-12 16:05:09 +0000
63+++ update_copyright.py 2014-04-10 08:19:04 +0000
64@@ -1,4 +1,4 @@
65-# Copyright (C) 2010 Canonical Ltd
66+# Copyright (C) 2010, 2014 Canonical Ltd
67 #
68 # This program is free software; you can redistribute it and/or modify
69 # it under the terms of the GNU General Public License as published by
70@@ -143,10 +143,19 @@
71 return 'not-versioned'
72 this_year = datetime.datetime.now().year
73 f = tree.get_file(file_id, path=filename)
74+ max_lines = 5
75+ cur_line = 0
76+ before_copyright = ''
77+ copyright_line = None
78 try:
79- copyright_line = f.readline()
80- m = copyright_re.match(copyright_line)
81- if m is None:
82+ while copyright_line is None and cur_line < max_lines:
83+ copyright_line = f.readline()
84+ cur_line += 1
85+ m = copyright_re.match(copyright_line)
86+ if m is None:
87+ before_copyright += copyright_line
88+ copyright_line = None
89+ if copyright_line is None:
90 return 'no-copyright'
91 # Determine the actual dates that this file was modified
92 # There really should be a better way to determine the revision of a
93@@ -178,7 +187,7 @@
94 # It seems this may already be updated
95 if copyright_line == new_copyright_line:
96 return 'copyright-correct'
97- new_content = new_copyright_line + f.read()
98+ new_content = before_copyright + new_copyright_line + f.read()
99 finally:
100 f.close()
101 # TODO: We could probably do this 'safer' with a big TreeTransform over

Subscribers

People subscribed via source and target branches