About Blog Dev | Alfa Romeo SZ Conkeror wishlist

Hgshelve

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.

Add post to: Delicious Reddit Slashdot Digg Technorati Google
Comment

Pingbacks

bzrshelve, a punchline to a bad joke « A man without a goal is like a ship without a rudder. @ship.quadhome.com 17.06.2008 11:05
A few days later, of course, hgshelve came into existence.
Blue Sky On Mars » links for 2008-05-20 @www.blueskyonmars.com 20.05.2008 12:36
Amazon byteflow: Hgshelve

Comments

Хрюндель 19.05.2008 12:33

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

reply
Всеволод Соловьёв 19.05.2008 14:02

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

reply
Foo 19.05.2008 18:39

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;)

reply
Eric Larson 19.05.2008 18:53

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 ;)

reply
Foo 20.05.2008 15:09

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.

reply
Александр Соловьёв 19.05.2008 21:14

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!

reply

Comment form for «Hgshelve»

Required. 30 chars of fewer.

Required.