1

Here's my shell command:

hg log --rev 'max(removes('\''**/all_the_things.js'\''))' --template '\{"files":[{join(file_dels % '\''{file|json}'\'','\'','\'')}],"node":{p1node|json}}'   

This spits out something like this (formatted for legibility):

{
  "files": [
    ...
    "www/js/MozCompatibility.js",
    "www/js/all_the_things.js",
    "www/js/autosuggest.css",
    ...
  ],
  "node": "b59fd118983e6c52b3a267ab8de305d0a73d4f06"
}

My question is: how can I filter the result of file_dels to only list files that match my glob?

i.e., I'm trying to find the parent of the revision that deleted a specific file, searching via glob, so that I can recover it. My --rev finds said revision, but the template lists out too many files -- I only want to find the one(s) that match my search criteria.

mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • I'm not sure that this is possible within a single template. It would be simpler to extract the revision ID only and pipe that through a post-processing filter. Annoyingly, while `files` is both a keyword *and* a function that lets you match patterns, `file_dels` is not. Even if it were, the function version of `files` matches against files *in* the selected revision and since the file is deleted, the glob could not match the file that was deleted (!). – torek Apr 18 '17 at 02:45
  • @torek I thought about post-processing it, but then I need a `glob` function in PHP (what I'm writing my script in) that exactly matches the behaviour of Mercurial's glob function. – mpen Apr 18 '17 at 16:23
  • I think you need to write an extension that defines a `glob` templatefilter. See e.g. http://stackoverflow.com/questions/7202052/write-custom-log-keyword-filter-as-extension-in-mercurial – ngoldbaum Apr 18 '17 at 20:46
  • Why not use logic operand *inside template*? – Lazy Badger Dec 02 '22 at 02:48

0 Answers0