Search code examples
mercurial

Listing only working directory files and dirs in hg manifest?


I'm trying to get a list of the current files and dirs using the following command:

hg manifest -r tip

However, this brings a list like this:

.hgtags
folder1/blah.c
folder1/blah.h
foo.json
folder2/bleh.c
folder2/bleh.h
test.json

How can I list only the following?

.hgtags
folder1
foo.json
folder2
test.json

Solution

  • On Unix machine you could try:

    hg manifest -r tip | cut -d "/" -f 1 | sort -u
    

    or

    hg manifest -r tip | cut -d "/" -f 1 | uniq
    
    1. cut -d "/" -f 1: select first portion delimited by '/'
    2. uniq: filter out repeated lines

    Or using Python (more cross-platform):

    You need to have python-glib installed (via pip)

    import hglib
    repo = hglib.open("/path/to/repo")
    manifest = repo.manifest("tip")
    files = set(f[4].split('/')[0] for f in manifest)