Alastair’s Place

Software development, Cocoa, Objective-C, life. Stuff like that.

Hglist

hglist - an ls command for Mercurial

hglist is an extension that adds an hg list/hg ls command to Mercurial. Why would one want such a thing, I hear you ask? Well, currently you can list the files under Mercurial’s control with hg manifest, but its output is very limited, and worse, while the documentation mentions that you can get revision hashes using --debug, what it doesn’t mention is that those are filelog revision hashes, not changelog revision hashes—that is, they are not change IDs.

To give you a flavour for what this extension can do:

1
2
3
4
5
6
alastair$ ls
COPYING         MANIFEST.in     build           hglist
MANIFEST        README          dist            setup.py
alastair$ hg ls
COPYING         MANIFEST.in     hglist
MANIFEST        README          setup.py

hg ls supports a -l switch that gives similar (but not identical) output to ls -l:

1
2
3
4
5
6
7
alastair$ hg ls -l
-rw-r--r-- alastair 18092  0:c6439c7f9e41 Dec 13 12:11 COPYING
-rw-r--r-- alastair   125  0:c6439c7f9e41 Dec 13 12:11 MANIFEST
-rw-r--r-- alastair    61  0:c6439c7f9e41 Dec 13 12:11 MANIFEST.in
-rw-r--r-- alastair   377  0:c6439c7f9e41 Dec 13 12:11 README
drwxr-xr-x nobody       0 -1:ffffffffffff Jan 01  1970 hglist
-rw-r--r-- alastair   778  0:c6439c7f9e41 Dec 13 12:11 setup.py

It also supports recursive output, though you can’t use -R for that because Mercurial already uses that switch to select a repository:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
alastair$ hg ls --recursive
COPYING         MANIFEST.in     hglist
MANIFEST        README          setup.py

hglist:
__init__.py     filters.py      list_files.py
alastair$ hg ls -l --recursive
-rw-r--r-- alastair 18092  0:c6439c7f9e41 Dec 13 12:11 COPYING
-rw-r--r-- alastair   125  0:c6439c7f9e41 Dec 13 12:11 MANIFEST
-rw-r--r-- alastair    61  0:c6439c7f9e41 Dec 13 12:11 MANIFEST.in
-rw-r--r-- alastair   377  0:c6439c7f9e41 Dec 13 12:11 README
drwxr-xr-x nobody       0 -1:ffffffffffff Jan 01  1970 hglist
-rw-r--r-- alastair   778  0:c6439c7f9e41 Dec 13 12:11 setup.py

hglist:
-rw-r--r-- alastair  1521 0:c6439c7f9e41 Dec 13 12:11 __init__.py
-rw-r--r-- alastair  1484 0:c6439c7f9e41 Dec 13 12:11 filters.py
-rw-r--r-- alastair 23118 0:c6439c7f9e41 Dec 13 12:11 list_files.py

Additionally, hg ls can do its own globbing (that’s shell wildcard expansion, for those who don’t speak UNIX):

1
2
3
4
5
alastair$ hg ls --recursive '*.py'
hglist          setup.py

hglist:
__init__.py     filters.py      list_files.py

and you can specify an arbitrary sort order, e.g.

1
2
3
4
5
6
7
8
9
10
11
12
alastair$ hg ls --recursive --sort 'date,-name'
drwxr-xr-x nobody       0 -1:ffffffffffff Jan 01  1970 hglist
-rw-r--r-- alastair   778  0:c6439c7f9e41 Dec 13 12:11 setup.py
-rw-r--r-- alastair   377  0:c6439c7f9e41 Dec 13 12:11 README
-rw-r--r-- alastair    61  0:c6439c7f9e41 Dec 13 12:11 MANIFEST.in
-rw-r--r-- alastair   125  0:c6439c7f9e41 Dec 13 12:11 MANIFEST
-rw-r--r-- alastair 18092  0:c6439c7f9e41 Dec 13 12:11 COPYING

hglist:
-rw-r--r-- alastair 23118 0:c6439c7f9e41 Dec 13 12:11 list_files.py
-rw-r--r-- alastair  1484 0:c6439c7f9e41 Dec 13 12:11 filters.py
-rw-r--r-- alastair  1521 0:c6439c7f9e41 Dec 13 12:11 __init__.py

There are loads more options, including support for template-based output (--template, like hg log); see hg help ls for the full details.

The source code can be obtained from the mercurial repository, or alternatively from the source archive (see the changelog, below).

To report a bug, drop me an e-mail.

Changelog

Version 0.3 - 2012-12-13

  • Fixed a problem that could occur if you used globbing patterns and the subrepository switch

  • Improved output for the multiple pattern case

Version 0.2 - 2012-12-13

  • Fixed a silly bug that triggered if you specify globbing patterns

Version 0.1 - 2012-12-13

  • Initial version