Blog Some posts...

ncdu: disk usage utility

2014-08-28T10:09:25Z linuxclidu

A note not to forget: ncdu is a very convenient way to see what files and directories use the disk space. Command line ncurses interface.

ncdu -x / - shows information about the whole root partition.

Better links with Python Markdown

2014-01-04T14:24:23Z homepage

Python Markdown package renders links like <> as <a href=""></a>, i.e. with http:// in the text. As for me, it doesn't have any use and just adds visual clutter. Luckily, this markdown processor is easily extensible, and with a couple lines of code you can make such links to render as <a href=""></a>. The corresponding Python code, which adds a postprocessing step:

import re
from markdown import Markdown
from markdown.postprocessors import Postprocessor

class LinkPostprocessor(Postprocessor):
    def run(self, text):
        return re.sub(r'(<a [^>]+>)https?://', r'\1', text)

md = Markdown(...)
md.postprocessors.add('links', LinkPostprocessor(md), '_end')

Fix addresses starting with "www"

2014-01-04T00:34:15Z homepage

For a long time I didn't notice that addresses like returned 404 - Not Found, as I myself never use them. Recently I was told about this issue and fixed it - now you can use such addresses as well. Old domain name also works, like this: All these URLs redirect to the "canonical" one, at and without www.

The related piece of my Nginx configuration, to make this post useful for more people :) is below:

server {
    rewrite ^$request_uri? permanent;

server {
    server_name ~^(?<subdomain>.+)\.aplavin\.ru$;
    rewrite ^ http://$$request_uri? permanent;

server {
    rewrite ^$request_uri? permanent;

server {
    server_name ~^www\.(?<subdomain>.+)\.plav\.in$;
    rewrite ^ http://$$request_uri? permanent;

Requested changes and comments

2013-08-13T02:28:11Z mercurialgsoc

In this post, and may be other such posts in the future, I will list important comments received in response to my sent patches, not to forget something. As for now, they are:

  • search mode indication: wrap "Assuming ..." in <p>...</p>
  • search mode indication: make mode descriptions localisable
  • revset tree depth: clearer commit message
  • revset search: blacklist regexps usage
  • makeRequest (js): get rid of all the ActiveXObject IE-related magic
  • ajax infinite scroll: don't strip one entry in the backend explicitly
  • ajax infinite scroll: indicate when there are no more items
  • ajax infinite scroll: get rid of shortlogajax template

Infinite scrolling

2013-07-24T00:23:05Z mercurialgsoc

I've started implementing 'infinite scrolling' feature, and now it's already available in action for shortlog view at my running hgweb instance.

Upcoming plan

2013-07-24T00:02:17Z mercurialgsoc

Some things I'm going to implement/extend in hgweb soon as part of the GSoC project:

  • search field looks also for file names (not sure if it's wanted through)
  • 'infinite scrolling' with AJAX for {short,change}log, graph, search
  • dynamic search results (without page reload)

Hgweb search - extended

2013-07-23T13:42:22Z mercurialgsoc

Currently hgweb supports only simple keyword search and matching exact revisions by number or hash, and you can't control it: i.e. there is no ability to search for string '1234' in commit descriptions, if revision #1234 is in the repo, or to search for 'abc' if a changeset hash starts with 'abc' (and if there are multiple such changesets, you will just see an error).

My patches extend the search in several ways:

  • no matter what you type, you get only the matching revisions (querying for an exact revision in current hg works like a goto to the place in log, which is less intuitive)
  • full revset expressions syntax is supported (with a configurable restriction of certain functions, e.g. heavyweight 'contains()')
  • the current search mode (exact revision, keyword, or revset) is shown along with the results, and you can always force using literal keyword matching, which is useful to search literally for strings like 'abc', '1234', or 'keyword(a)'

As usual, all the patches can be found at, and they are actually enabled there so you can see all the new features in action.

My commits list

2013-07-12T16:47:09Z mercurialgsoc

From now you can see all my commits to Mercurial (both accepted and not yet) grouped by repo they are currently in at

Revset search syntax in hgweb

2013-07-09T14:36:50Z mercurialgsoc

Another part of my summer project is improving hgweb search by adding revset syntax to it, which is extensively used in Mercurial CLI commands. According to the feedback at ML, I'm going to change the search behaviour to use revset syntax, if the query string can be parsed as a revset tree.

Another obligatory thing here is to deny usage of some heavy revset functions. The whitelist of them, used at BitBucket seems reasonable here too.

Hgweb source views

2013-07-06T16:05:01Z mercurialgsoc

First part of my plan is improving source display and code cut&paste all over the hgweb, and it is going to be finished. The implementation strategy is accepted by the community, and I've patchbombed versions of several patches, which modify single file, diff and changeset views.

About the highlight extension

2013-06-27T19:39:08Z mercurial

Mercurial has a nice highlight extension, which provides syntax highlighting for many languages at hgweb (example in Python).

While its output looks nice, there is quite an ugly hack in the implementation. The extension needs to intercept into the process of generating HTML page from templates, and it approaches this by defining an extra template filter called highlight (nothing bad so far), and then replacing (as a string) line|escape with line|highlight in the template. And here is the problem: if you change line|escape to e.g. line|process|escape or even just to line | escape – the highlighting will not work! Because of this it's not that easy to change some aspects of file source display, without losing compatibility with the extension.

Actually, the extension has another, less important issue: when the actual source line is just a space or multiple spaces, the highlight'ed version of it is just empty.

Start of development

2013-06-01T00:49:57Z mercurialgsoc

I've started implementing proposed features from the beginning and the first item is improving the way hgweb display file content. By this I mean allowing to select code without line numbers and with consistent indents, and highlighting the lines which were linked at (as the hash part of the URL). Actually, these things are already partly implemented, and I'm going to tidy up, organize them and patchbomb to Mercurial.

You can always see how the code performs at (it usually runs the version of code which is in the last patchbombed patch), and of course at the official Mercurial repo after corresponding patches are accepted into upstream.

GSoC has started

2013-05-29T17:05:10Z mercurialgsoc

As I'm selected for Google Summer of Code 2013 at Mercurial project, I'm going to publish short posts here related to my coding. Now there is community bonding period on the timeline, until the June 17.

My latest development (even what is not yet accepted to upstream) will hopefully be always available as a Mercurial repo The whole is running the last code from this repository.