Merge lp:~coopebm1/sloecode/add-wiki-branch into lp:sloecode/wiki

Proposed by Brendan Cooper
Status: Needs review
Proposed branch: lp:~coopebm1/sloecode/add-wiki-branch
Merge into: lp:sloecode/wiki
Diff against target: 83 lines (+35/-5)
4 files modified
sloecode/bzr/factory.py (+8/-4)
sloecode/controllers/admin/project.py (+4/-1)
sloecode/controllers/project.py (+13/-0)
sloecode/templates/project-wiki.html (+10/-0)
To merge this branch: bzr merge lp:~coopebm1/sloecode/add-wiki-branch
Reviewer Review Type Date Requested Status
Thomi Richards (community) Needs Fixing
Review via email: mp+100900@code.launchpad.net

Description of the change

Creates a wiki folder and wiki page.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :
Download full text (4.0 KiB)

Hi,

Sorry for the delay here - I intended to do this last week, but I completely forgot about it.

I'd like you to make some changes to this branch. There are two main things that need fixing:

1) You have duplicated code. In your branch, factory.py lines 72 - 100 look like this:

    def create_shared_repository_for_project(self, project_name):
        """Create a repository for the project with a trunk branch."""
        dir_name = self.get_project_repo_dir(project_name)
        repo = create_shared_repo(dir_name)
        # Now to create the trunk.
        try:
            to_transport = repo.user_transport.clone('trunk')
        except AttributeError:
            # Fixes lp:948483 bzrlib version 2.1 (which is current in debian
            # squeeze) uses a different name for this:
            to_transport = repo._transport.clone('trunk')
        format = bzrdir.format_registry.make_bzrdir('default')
        branch = bzrdir.BzrDir.create_branch_convenience(
            to_transport.base, format=format,
            possible_transports=[to_transport])
        branch.set_append_revisions_only(True)

        # Trying to create a wiki branch (at this stage, identical to trunk)
        try:
            to_transport = repo.user_transport.clone('wiki')
        except AttributeError:
            # Fixes lp:948483 bzrlib version 2.1 (which is current in debian
            # squeeze) uses a different name for this:
            to_transport = repo._transport.clone('wiki')
        format = bzrdir.format_registry.make_bzrdir('default')
        branch = bzrdir.BzrDir.create_branch_convenience(
            to_transport.base, format=format,
            possible_transports=[to_transport])
        branch.set_append_revisions_only(True)

Repeated code is almost always a bad thing. The code to create the branch should be put into a method of it's own, something like this:

def create_branch_on_repository(self, repo, branch_name):
        try:
            to_transport = repo.user_transport.clone(branch_name)
        except AttributeError:
            # Fixes lp:948483 bzrlib version 2.1 (which is current in debian
            # squeeze) uses a different name for this:
            to_transport = repo._transport.clone('wiki')
        format = bzrdir.format_registry.make_bzrdir('default')
        branch = bzrdir.BzrDir.create_branch_convenience(
            to_transport.base, format=format,
            possible_transports=[to_transport])
        branch.set_append_revisions_only(True)

...which leads me to my next point: the name of the method is 'create_shared_repository_for_project'. However, what we're actually doing is creating a shared repository AND some branches. I'd be happier if the 'create_shared_repository_for_project' method only created a shared repository, and calling code then called the new "create_branch_on_repository" method as well, in order to create any branches that are needed. One advantage of this is that we can enable or disable the creation of the wiki branch in the web-app code, which is where it belongs. Finally, making methods (and classes, for that matter) as small as possible makes them much easier to test - which leads me nicely to...

Read more...

review: Needs Fixing
152. By Brendan Cooper

Seperated Repo and branch creation

Unmerged revisions

152. By Brendan Cooper

Seperated Repo and branch creation

151. By Sam Bailey

Wiki branch is created with new project alongside trunk

150. By Sam Bailey

project information passed correctly

149. By Sam Bailey

forgot to add project-wiki.html

148. By Sam Bailey

Re-directing /p/<name>/wiki to project-wiki.html

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sloecode/bzr/factory.py'
2--- sloecode/bzr/factory.py 2012-03-07 01:26:25 +0000
3+++ sloecode/bzr/factory.py 2012-04-19 00:27:18 +0000
4@@ -73,18 +73,22 @@
5 """Create a repository for the project with a trunk branch."""
6 dir_name = self.get_project_repo_dir(project_name)
7 repo = create_shared_repo(dir_name)
8- # Now to create the trunk.
9+ return repo
10+
11+
12+ def create_branch_on_repository (self,repo,branch_name):
13+ """Create a branch for the project """
14 try:
15- to_transport = repo.user_transport.clone('trunk')
16+ to_transport = repo.user_transport.clone(branch_name)
17 except AttributeError:
18 # Fixes lp:948483 bzrlib version 2.1 (which is current in debian
19 # squeeze) uses a different name for this:
20- to_transport = repo._transport.clone('trunk')
21+ to_transport = repo._transport.clone(branch_name)
22 format = bzrdir.format_registry.make_bzrdir('default')
23 branch = bzrdir.BzrDir.create_branch_convenience(
24 to_transport.base, format=format,
25 possible_transports=[to_transport])
26- branch.set_append_revisions_only(True)
27+ branch.set_append_revisions_only(True)
28
29 def get_repository_for_project(self, project_name):
30 """Get a bzrlib.repository.Repository object for a given project
31
32=== modified file 'sloecode/controllers/admin/project.py'
33--- sloecode/controllers/admin/project.py 2011-10-23 20:23:56 +0000
34+++ sloecode/controllers/admin/project.py 2012-04-19 00:27:18 +0000
35@@ -59,8 +59,11 @@
36 Session.commit()
37 h.flash("Project Added Successfully")
38 # Create a shared repo for the project.
39- config['bzr.factory'].create_shared_repository_for_project(
40+ repo = config['bzr.factory'].create_shared_repository_for_project(
41 new_project.name)
42+ config['bzr.factory'].create_branch_on_repository (repo,'trunk')
43+ config['bzr.factory'].create_branch_on_repository (repo,'wiki')
44+
45 return redirect(h.url(controller='admin/project', action='retrieve'))
46
47 def retrieve(self):
48
49=== modified file 'sloecode/controllers/project.py'
50--- sloecode/controllers/project.py 2012-03-07 03:36:35 +0000
51+++ sloecode/controllers/project.py 2012-04-19 00:27:18 +0000
52@@ -141,3 +141,16 @@
53
54 return redirect(h.url(controller='project', action='index',
55 project_name=project_name))
56+
57+ @ActionProtector(Any(has_site_role(PROJECT_ADMIN), has_project_write_access()))
58+ def wiki(self, project_name):
59+ """
60+ Render the wiki for the project
61+ """
62+ projects = Project.get(name=project_name)
63+ existing_project = projects[0] if projects else None
64+
65+ if existing_project is None:
66+ abort(404)
67+ else:
68+ return self.render('/project-wiki.html', {'project': existing_project})
69
70=== added file 'sloecode/templates/project-wiki.html'
71--- sloecode/templates/project-wiki.html 1970-01-01 00:00:00 +0000
72+++ sloecode/templates/project-wiki.html 2012-04-19 00:27:18 +0000
73@@ -0,0 +1,10 @@
74+{% extends "base.html" %}
75+
76+{% block title %} Wiki {% endblock %}
77+
78+{% block content %}
79+This is a wiki<br>
80+This is the project's name: {{project.name}}<br>
81+This is the project's display name: {{project.displayname}}<br>
82+This is the project's description: {{project.description}}<br>
83+{% endblock %}

Subscribers

People subscribed via source and target branches