{"id":194,"date":"2008-03-06T18:15:34","date_gmt":"2008-03-06T22:15:34","guid":{"rendered":"http:\/\/benjamin.smedbergs.us\/blog\/2008-03-06\/things-i-learned-from-writing-a-mercurial-extension\/"},"modified":"2008-03-06T18:15:34","modified_gmt":"2008-03-06T22:15:34","slug":"things-i-learned-from-writing-a-mercurial-extension","status":"publish","type":"post","link":"https:\/\/benjamin.smedbergs.us\/blog\/2008-03-06\/things-i-learned-from-writing-a-mercurial-extension\/","title":{"rendered":"Things I Learned From Writing a Mercurial Extension"},"content":{"rendered":"<p>I <a href=\"http:\/\/www.selenic.com\/mercurial\/wiki\/index.cgi\/WritingExtensions\">wrote<\/a> my first <a href=\"http:\/\/www.selenic.com\/mercurial\/wiki\/index.cgi\/UsingExtensions\">mercurial extension<\/a> today. It will <a href=\"http:\/\/hg.mozilla.org\/users\/bsmedberg_mozilla.com\/hgpoller\/?file\/d043e5ef0c9b\/newchanges.py\">print a log<\/a> of all the commits you need to get from a changeset A which used to be the only head of a repository to a changeset B which is now the only head of the repository.It&#8217;s part of a project to get our buildbots hooked up to mercurial in a sane way. I need to make the same logic available via HTTP. It wasn&#8217;t too hard, but there are some tricky\/undocumented things in the mercurial API that made life difficult.<\/p>\n<ul>\n<li>The <a href=\"http:\/\/www.selenic.com\/mercurial\/wiki\/index.cgi\/WireProtocol\">wire protocol<\/a> is a pretty elegant way to ask a server for changesets when you don&#8217;t know what the graph looks like yet with relatively few queries.\n<li>The HTTP version of the protocol returns all the results in a plain-text format, <em>except<\/em> for the actual changesets which come across as a relatively opaque &#8220;bundle&#8221;.\n<li>The <code>between<\/code> command in the wire protocol doesn&#8217;t do what you think it does, or what the documentation seems to say it does. Instead of returning all the changesets between point A and point B, it walks backward through the list returning a selection of changesets along the line. The farther you go back the less often it will pick a changeset to return.\n<li>There is currently no way to query hgweb for metadata about a particular commit, such as the author, date, or commit message. This is trivial to add, and I will be submitting a patch shortly.\n<li>With a few extra functions, it should be relatively trivial to write a web repository browser which allows you to nagivate the revision graph graphically and dynamically load information about history as you need it.\n<li><code>cmdutil.show_changeset<\/code> can be used to show changesets the same way <tt>hg log<\/tt> does. I haven&#8217;t yet figured out how to expose all of the formatting options it accepts as options accepted by my extension.\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I wrote my first mercurial extension today. It will print a log of all the commits you need to get from a changeset A which used to be the only head of a repository to a changeset B which is now the only head of the repository.It&#8217;s part of a project to get our buildbots [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[82,41,81],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-mozilla","tag-buildbot","tag-mercurial","tag-mercurial-extensions"],"_links":{"self":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":0,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"wp:attachment":[{"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benjamin.smedbergs.us\/blog\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}