bzr-undelete

Parth Malwankar parth.malwankar at gmail.com
Fri Feb 20 13:05:01 GMT 2009


On Fri, Feb 20, 2009 at 1:28 PM, Martin Pool <mbp at sourcefrog.net> wrote:
> 2009/2/20 Parth Malwankar <parth.malwankar at gmail.com>:
>> Hello,
>>
>> I have created a bzr-undelete plugin[1] that tries the last:N
>> revisions of the branch to undelete the specified file(s)/dir(s).
>>
>> As I am new to bzrlib API, I would very much appreciate it if
>> some of the bzr experts here could review it and let me know
>> if something could be improved.
>
> That sounds like a pretty useful thing, probably an answer to a fairly
> frequently asked question.  You should add it to the plugin list on
> bazaar-vcs.org, if you haven't already.
>

Done.

> On the grounds of discoverability I'd think about adding it in to the
> core, maybe as 'bzr revert --undelete'.
>

Sounds like a good idea to me. I can probably look into it once
the plugin matures (is bug free :)) and I develop some more
familiarity with bzr to add test cases and such.

> Anyhow, to have a quick look at the code:
>

Thanks for taking the time to look into the code.

>
>> # Author: Parth Malwankar <parth.malwankar at gmail.com>
>>
>> """Undelete the file(s) deleted using 'bzr rm'"""

<snipped old code>

>>             except:
>>                 pass
>>         return False
>
> So this all looks pretty good, except that there is a better way to find
> the file.  We would probably recommend that you use an extension API
> rather than the command line API, but I can understand that directly
> addressing the commands is easier to translate from a shell script.
>
> Catching a bare 'except': like this is not so good because if any other
> error occurs the program will just keep on running, possibly making things
> worse.  That's one reason it's good to use the extension API.
>
> The kind of API you should use is: get the branch, then get the revision
> by looking up that spec, then get the revision tree.  Ask the revision
> tree if it has the relevant path.  If so, you want to revert to that
> version - I'm not sure off hand if there is a simpler way than using the
> cmd_revert api.
>

I think I sort of get the approach now. The updated version of the
plugin[1]  now uses bzrlib API directly. Please do let me know
if any further improvements can be made.

> This would fix one bug in this which is that if you try to undelete a
> still-present file it will revert it.  And if you do it on '.' it's even
> worse.
>

Fixed. In case a version is preset in the current working tree
the undelete prints a "nothing to do" message.

Thanks,
Parth

[1] http://bazaar.launchpad.net/~parthm/bzr-undelete/trunk/annotate/head%3A/__init__.py

> Hope that helps.
>
>>
>> def vprint(s, verbose):
>>     if verbose == True:
>>         print s
>>
>> register_command(cmd_undelete)
>
> --
> Martin <http://launchpad.net/~mbp/>
>



More information about the bazaar mailing list