Sunday, June 10, 2007

Dear Lazyweb: Mercurial Python API

So, in the midst of trying to convert some Darcs repositories to Mercurial repositories (see here for the reason), I hit an "interesting" bug: tailor processes "rename" patches by deleting the renamed file. A little debugging later, I get to this simulation of what tailor does:


>>> from mercurial import hg,ui
>>> uio = ui.ui(debug=True,verbose=True)
>>> r = hg.repository(ui=uio, path='.', create=True)
>>> f = file('A', 'w')
>>> f.write('Some data\n')
>>> f.close()
>>> r.add('A')
>>> r.commit(text='Add A')
A
'i\xe9\xb4\xc8\x9d\xb8\xeb<\xbe\xb1k\xae\xb1\x182\xa9ao\x80\xd0'
>>> r.copy('A', 'B')
B does not exist!


Huh? Of course B doesn't exist, that's why I want to create it! So, we look at the code in localrepo.py to handle copying...


def copy(self, source, dest, wlock=None):
p = self.wjoin(dest)
if not os.path.exists(p):
self.ui.warn(_("%s does not exist!\n") % dest)
elif not os.path.isfile(p):
self.ui.warn(_("copy failed: %s is not a file\n") % dest)
else:
if not wlock:
wlock = self.wlock()
if self.dirstate.state(dest) == '?':
self.dirstate.update([dest], "a")
self.dirstate.copy(source, dest)


Double huh?


  1. Why is this method checking whether the destination exists before it does anything? It appears to me that this is actually necessary; just disabling this test leads to a crash later.
  2. How does mercurial work at all with such huge breakage in its core code? Does /usr/bin/hg use a different implementation of the repository code than mercurial.hg?
  3. Why, in the name of $DEITY, is this a warning and not a fatal exception? One example of what happens when you don't signal to your users that you're ignoring them is this bug: tailor happily goes ahead and removes the original file, safe in the knowledge that mercurial has copied it to the new location. Except, of course, that mercurial hasn't actually copied it. Whoops.


I'm hoping that someone will tell me that it's just too late at night for me and I'm being an idiot. Please tell me this. It would make me very sad if code like that was in my VCS.


:-( <--- sad Daniel

11 Comments:

At 11:43 PM, Anonymous Anonymous said...

1. localrepository.copy only marks dest as a copy of source. The caller is supposed to do the actual "cp source dest" before calling this function (e.g. using the copyfile function in util.py).

2. util.copyfile is used by the docopy function in commands.py to copy the bytes.

3. yes, that function should return some kind of error code.

 
At 8:53 AM, Anonymous Anonymous said...

I'm looking for an application of some sorts that can save all my contact details and such from my iPhone to my computer and then after put them all back onto another iPhone (well the same one actually, as I'm getting it reset) Any suggestions?
[url=http://www.provenworkfromhomejobs.com/2009/02/blogging-for-fun-and-profit-earn-income-posting-about-your-hobby/#comment-5357]unlock iphone[/url]

 
At 2:40 PM, Anonymous Anonymous said...

With hаvin so muсh contеnt do уоu evеr run іnto any issueѕ οf plagorism
oг coρyright infringement? Mу site has a lot of unique content I've either authored myself or outsourced but it seems a lot of it is popping it up all over the web without my authorization. Do you know any techniques to help prevent content from being stolen? I'd genuinely appreсіate it.


http://cctvsecuгitypгos.buzznеt.cοm/uѕeг/
Feel free to surf my weblog : buzznet.com

 
At 5:33 AM, Anonymous Anonymous said...

Rіght away I am going tο dο mу
breakfast, аfter havіng my breakfast coming yеt again to read more news.


Heгe is my ωebpаge; http://www.biggreeneggmanual.com/super-smoked-spicy-chicken-wings/
Feel free to surf my web page : www.biggreeneggmanual.com/blog/

 
At 5:33 AM, Anonymous Anonymous said...

Right aωаy ӏ am going to ԁo my brеakfast, after haνіng my brеаκfаst сoming
уеt аgaіn to read moге
neωs.

My webρаge - http://www.biggreeneggmanual.com/super-smoked-spicy-chicken-wings/
My web page > www.biggreeneggmanual.com/blog/

 
At 3:21 PM, Anonymous Anonymous said...

Hi, i belieѵe that i ѕaω уоu visited my site thus i got herе to
go bacκ the favor?.I am tгying to to find issues tо impгoνe my ωeb sitе!
I guess іtѕ ok to make use of some of youг idеas!

!

Also viѕit my рage :: how to make money flipping cars for profit

 
At 10:11 PM, Anonymous Anonymous said...

Hi theгe just wanted to give you a quick heаds uр.
The text in your content sеem to be running οff
the scrеen in Firefox. Ι'm not sure if this is a formatting issue or something to do with internet browser compatibility but I figured I'ԁ post to let
yοu know. The deѕign lоok great though! Hope you
get the iѕsue fixeԁ soоn. Сhеers

mу web page: search engine optimization dallas

 
At 5:57 AM, Anonymous Anonymous said...

Todaу, I went to the beach front with my kidѕ.
I fοund a sea shell аnԁ gave it to my
4 yеar old daughter and said "You can hear the ocean if you put this to your ear." Ѕhе ρlacеd the shеll to her eаr and sсreamed.
Τhегe waѕ а hеrmit сrаb insidе and it pinched her еaг.
Shе never wants to go baсk! LоL
Ι know this is entіrеly off topic but Ι had to tell someone!


Аlso visit my homepagе :: dallas seo

 
At 6:05 AM, Anonymous Anonymous said...

Intercombase - professional translation complex text in different fields more than 140 languages. Media Translation, Manufacturing Translation, Automotive Translation - first class affordable.

Hebrew Translation - [url=http://www.intercombase.com]Spanish[/url]

 
At 8:26 PM, Blogger oakleyses said...

uggs outlet, uggs on sale, ray ban sunglasses, ray ban sunglasses, louis vuitton, michael kors outlet online, oakley sunglasses wholesale, christian louboutin outlet, louis vuitton, uggs outlet, louis vuitton outlet, polo outlet, prada handbags, nike free, chanel handbags, longchamp outlet, michael kors outlet, replica watches, louis vuitton outlet, oakley sunglasses, michael kors outlet online, prada outlet, michael kors outlet online, longchamp outlet, burberry handbags, michael kors outlet, kate spade outlet, ray ban sunglasses, longchamp outlet, louis vuitton outlet, oakley sunglasses, nike air max, oakley sunglasses, replica watches, ugg boots, polo ralph lauren outlet online, ugg boots, gucci handbags, jordan shoes, cheap oakley sunglasses, michael kors outlet online, christian louboutin uk, burberry outlet, tory burch outlet, tiffany and co, christian louboutin shoes

 
At 8:57 PM, Anonymous Cara Mengobati Prurigo said...


Thanks for the information, this is very useful. Allow me to share a health article here, which gods are beneficial to us. Thank you :)

Solusi untuk Menanggulangi Osteoporosis
Cara Mengobati Abses Payudara Tanpa Operasi
Obat Ampuh Sembuhkan Flu Berkepanjangan
Obat Pereda Nyeri Dada Sebelah Kiri
Cara Menghilangkan ambeien/Wasir Secara Permanen
Pengobatan Alami & Efektif untuk Ginjal Bengkak

 

Post a Comment

<< Home