[wishlist] Configure default basedir for checkout

Bug #790553 reported by Alexander Belchenko
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
QBzr
Fix Released
Wishlist
André Bachmann

Bug Description

In bzr-explorer when I go to Bazaar, Start, Checkout, it would be nice to have a standard checkout folder set. Currently it is only set to the last checkout location if I did a checkout first. But if I create a new project and go to Bazaar, Start, Checkout and browse to my branch to checkout from (e.g. W:\BZR-Repository\projectname\trunk), Bazaar Explorer did suggest a checkout location on W:\BZR-Repository\projectname\trunk\trunk or elsewhere (I couldn't yet figure out on which base the suggestions come from).

I would like to have an option to set the default checkout location to E:\project\projectname for example. How can I do this?

Tags: qcheckout
Revision history for this message
Alexander Belchenko (bialix) wrote :

Andre, it should be easy enough to store such location in qbzr.conf and then load it from qbzr.conf when dialog starts. If you want to add such feature I can mentor you how to do so.

Of course, for the sake of completeness we need to add support for editing such location to qconfig, but it could be done later.

tags: added: qcheckout
Changed in qbzr:
status: New → Confirmed
importance: Undecided → Wishlist
Revision history for this message
André Bachmann (andrebachmann-dd) wrote :

I really appreciate your help! Please give me more information on how to do this myself.

Revision history for this message
Alexander Belchenko (bialix) wrote :

OKay, the first step will be: determine what command is in charge of checkout for bzr-explorer. For this we need to run command in debug mode (in bzr-explorer main menu -> View -> check Diagnostic Mode. Run Checkout again, and discover that

Internal dialog for: checkout.

Oops. Seems to be checkout dialog from explorer itself. Searching for checkout dialog in explorer. Found one in explorer/lib/checkout_dialog.py

We need to set the default to_location in the constructor (__init__ method). We can see there following:

        if to_location is None:
            to_location = u'.'

Looks like the good candidate to hook in. That will be really easy to put instead of u'.' your predefined location.

But then to_location passed to GetNewWorkingTreeWindow dialog from qbzr/lib/getnew.py. And there starts a bit more complex solution.

It seems we have 2 codebases involved here. I was a bit wrong when said it will be easy.

OK, let's look how destination location suggestion is created. The following method is onvoked when user changed source location of the checkout.

    def from_location_changed(self, new_text):
        new_val = self.to_location
        tail = re.split("[:$#\\\\/]", unicode(new_text))[-1]
        if tail:
            new_val = os.path.join(new_val, tail)
        self.ui.to_location.setText(new_val)

So, this method looks like better place to hook into. We need to change

        if tail:
            new_val = os.path.join(new_val, tail)

To use predefined base location.

That would be a bit hard to extract projectname from source location, IMO.

To read predefined basedir value from qbzr.conf you need something like

from bzrlib.plugins.qbzr.lib.util import get_qbzr_config
config = get_qbzr_config()
basedir = config.get_option("checkout_basedir")

The code above will try to read checkout_basedir option from qbzr.conf (DEFAULT section). If it's not empty then you can use it to create new to_location. If it's empty then it will be better to keep doing as old code does.

I should admit it turns to be not so easy as I thought at first. If you're willing to try taking a stab on this, feel free to ask more question about codebase.

Revision history for this message
André Bachmann (andrebachmann-dd) wrote :

Ok, with your hints it is quite easy to change this. Maybe tomorrow I will try to extract the project name to use it in my to_location. It shouldn't be too difficult, because my co-workers can/should only branch from a certain location. I will keep you informed!

Now I know how I come from the information about the internal dialog to the file checkout_dialog.py - all dialogs seems to be in C:\Program Files\Bazaar\plugins\explorer\lib. There I see the __init__ method. Ok, it is quite logical that I want to change something with the to_location.

After looking some minutes on the source code, I realized that I should look to qbzr\lib\getnew.py. Ok.

What I didn't get yet is how I should know that I have to look to 'from_location_changed'. My first guess would be to change to_location in __init__. Could you please explain?

Revision history for this message
Alexander Belchenko (bialix) wrote : Re: [Bug 790553] Re: [wishlist] Configure default basedir for checkout

31.05.2011 17:23, André B. пишет:
> Ok, with your hints it is quite easy to change this. Maybe tomorrow I
> will try to extract the project name to use it in my to_location. It
> shouldn't be too difficult, because my co-workers can/should only branch
> from a certain location. I will keep you informed!

That' good.

> Now I know how I come from the information about the internal dialog to
> the file checkout_dialog.py - all dialogs seems to be in C:\Program
> Files\Bazaar\plugins\explorer\lib. There I see the __init__ method. Ok,
> it is quite logical that I want to change something with the
> to_location.
>
> After looking some minutes on the source code, I realized that I should
> look to qbzr\lib\getnew.py. Ok.

For experiments with plugins it's worth to get the branch of qbzr and
explorer plugins from the Launchpad and put them either into
C:\Documents and Settings\USERNAME\Application
Data\bazaar\2.0\plugins\ (on Vista/7 the path could be a bit
different), or to put them into any suitable directory and tell bzr
about your plugins directory with environment variable
BZR_PLUGIN_PATH. For example, all my plugins live in
C:\work\Bazaar\plugins, so I have added
BZR_PLUGIN_PATH=C:\work\Bazaar\plugins
to my environment variables.

Plugins from Documents and Settings or from BZR_PLUGIN_PATH will be
used instead of installed ones in Program Files.

Such setup allows you to change the plugins easily, but still keep
installed plugins intact. So, if you will break some plugin you can
always switch back to standard installation simply by moving your copy
of the plugin from your local plugins folder. For example I have
C:\work\Bazaar\plugins\_DISABLED directory where I can keep disabled
plugins (bzr won't recurse into _DISABLED subdirectory while searching
for plugins).

> What I didn't get yet is how I should know that I have to look to
> 'from_location_changed'. My first guess would be to change to_location
> in __init__. Could you please explain?

If you know a little bit about Qt then you may know about
signals/slots in Qt. For every event (signal) we can assign some
handler (slot) and when such event occurs Qt will call our handler back.

In the __init__ you can see installation of our handler:

        # signal to manage updating the 'location' on the fly.
        self.connect(self.ui.from_location,
QtCore.SIGNAL("editTextChanged(const QString &)"),
                     self.from_location_changed)

I.e. when user changes "from_location" then self.from_location_changed
method will be called back.
It's not very obvious, I know. You can put some print statements in
the code to see how it works. Just remember to run qbzr/explorer from
the console as

bzr explorer

or

bzr qgetnew

instead of

bzrw explorer
bzrw qgetnew

Otherwise you won't see printed strings.

qgetnew is the checkout dialog from qbzr which is customized in explorer.

--
All the dude wanted was his rug back

Revision history for this message
André Bachmann (andrebachmann-dd) wrote :

Thanks for your hints about the plugin paths and Qt!

Now my from_location_changed looks like so:

    def from_location_changed(self, new_text):
        new_val = self.to_location
        tail = re.split("[:$#\\\\/]", unicode(new_text))[-1]
        projectname = re.split("[:$#\\\\/]", unicode(new_text))[-2]
        if tail:
            config = get_qbzr_config()
            basedir = config.get_option("checkout_basedir")
            if basedir and projectname:
                new_val = os.path.join(basedir, projectname)
            else:
                new_val = os.path.join(new_val, tail)
        self.ui.to_location.setText(new_val)

It does the job well and it shouldn't have any problems. What do you think?

Revision history for this message
Alexander Belchenko (bialix) wrote :

Answered to qbzr ML.

Revision history for this message
André Bachmann (andrebachmann-dd) wrote :

Implemented since qbzr rev. 1430.

Changed in qbzr:
assignee: nobody → André Bachmann (andrebachmann-dd)
status: Confirmed → Fix Released
milestone: none → 0.22.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.