Hgshelve

NOTE: Not to be confused with a mercurial extension, named shelve.

Few days ago there was a lot links on the Internet to gitshelve, which implements persistent versioned storage of objects in the git. I’ve read it description and realized that there are few serious design flaws:

  • Can store only strings
  • Uses subprocess.PIPE for interconnection with git
  • Uses bunch of C+Perl+Shell code in Python library instead of using another Python library ;-)

History

We’ve discussed it with Pythy, and I’ve convinced him to write hgshelve, which should be easy and pain-free to implement. First thing which we came to is storage of objects through usage of simplejson, which generates (opposing to pickle) easy-readable string representation of objects. Plus objects, dumped by simplejson, can be edited by hands without fear of occasional corruption caused by newline or space.

While I was theorizing, he just wrote code and got hgshelve working. ;-) And from starts all mentioned flaws of gitshelve was fixed. ;-)

Usage

It’s really simple to use, just as usual shelve:

>>> import hgshelve
>>> data = hgshelve.open('path/to/repo') # repository is opened/created here
>>> data['key'] = {1: "Hello, world!", 'b': 'just test'}
>>> data.sync()
>>> data
{'key': {u'1': u'Hello, world!', u'b': u'just test'}}

Additionally you can use data.commit, which optionally accepts two arguments: commit message and key to commit (if you want to commit single key).

There are no support of advanced mercurial features, like branches1 and named branches, though it can arise lately. get_data method can return data from another revision through getting optional argument called rev, which can be one of: revision number, partial (or full) revision hash, mercurial tag.

Dependecies

There are only two of them:

  • Mercurial
  • simplejson

Where to get

Just clone repository:

hg clone http://hg.piranha.org.ua/hgshelve/
1

Branches in mercurial are the same as they are in git (where they are called named branches), but instead they can be created implicitly and they don’t carry names.

Pingbacks: 2

bzrshelve, a punchline to a bad joke « A man without a goal is like a ship without a rudder.
A few days later, of course, hgshelve came into existence.
ship.quadhome.com, 08:05 (after 29 days)
Blue Sky On Mars » links for 2008-05-20
Amazon byteflow: Hgshelve
www.blueskyonmars.com, 09:36 (after 1 day)

Comments: 12 (already: 3) Comment post

Снова какую то херню сделали.. Ща опен айди к нему прекрутят как пить дать..

Хрюндель , 09:33

Ha, in fact I’ve already thought how and where I can use it :)

Всеволод Соловьёв , 11:02

Neat. Lets not let anyone implement X without forcing them to also implement it in my favour DVCS/FOOD/IDE.

All must be represented. All must be reimplemented.

Heck, Why dont we all just use hg and then we wouldn’t have to convince developers to reimplement everything just to suit hg users… because there can be only one!

(design deficiencies not withstanding! cough;)

Foo , 15:39

OK, I see where you are coming from. But, without doing a specific version for a specific DVCS, some kind of abstracted DVCS agnostic shelving mechanism is probably going to be poorly implemented. Sure, it seems crappy not reusing more code, but I personally think it is better to reuse the good code than reuse all code.

Just my two cents :)

I’m probably biased b/c I use mercurial ;)

Eric Larson , 15:53

I am waiting for the BZR version now. bzrshelve will rock, whats more it will be implemented in twisted or pypypypy and be even more pythonic and pythony than hgshelve.

mark my words, its a matter of days until we see bzrbookshelf.

Foo , 12:09 (after 1 day)

Honestly saying code from gitshelve is not that good. And I, looking at both modules, think that design of our is much better.

P.S. And compare 480 SLOC of gitshelve versus 200 SLOC of hgshelve!

Alexander Solovyov , 18:14

Cool, but there’s some bugs:

You call get_persisted_objects_keys() before you init hg_book_re, which the method relies on. Move the hg_book_re init above the call to get_persisted_object_keys() and you’re good.

It would be cool if you moved the project to Bitbucket so there would be an open issue tracker.

Jesper Noehr , 13:40 (after 55 days)

Thanks, fixed.

It would be cool if you moved the project to Bitbucket so there would be an open issue tracker.

Heh, there are a lot of sites like Bitbucket and I’m not sure that it is better than something else. :)

Alexander Solovyov , 18:52 (after 55 days)

Bitbucket’s mercurial and it has an issue tracker. But anything would do. Just easier keeping track of issues that way.

Jesper Noehr , 19:04 (after 55 days)

Ahh, bitbucket is a hosting for mercurial… Very interesting. :)

Alexander Solovyov , 19:13 (after 55 days)

Any specific reason why you user your own create_dir_with_parents instead of os.makedirs()?

claimid , 12:47 (after 89 days)

You are completely right. :-)

Alexander Solovyov , 15:52 (after 89 days)

Comment form for «Hgshelve»

Required. 30 chars of fewer.

Required.

Comment post