Why is json not shown in Mercurial's template list? - mercurial

hg log --template list shows available styles: bisect, changelog, compact, default, phases, status, xml, but not json.
Yet hg log --template json works fine.
Why is json not shown in the the list?

I suppose, just because now json-style is dirty hack. Template list lists all styles for files with
predefined name pattern map-cmdline.STYLE
in predefined location %THG%\templates
(see my dir output and list of styles, note customcolorlog style)
TortoiseHg\templates>dir /B
...
map-cmdline.bisect
map-cmdline.changelog
map-cmdline.colorlog
map-cmdline.compact
map-cmdline.default
map-cmdline.phases
map-cmdline.status
map-cmdline.xml
...
>hg log -T list
available styles: bisect, changelog, colorlog, compact, default, phases, status, xml
but yes, I can also use -T json

Related

how to remove a folder from tracking in mercurial

To ignore ./node_modules/ folder and .idea folder into .hgignore file so that I don't want to track them.
Currently I have the following rules on my .hgignore file.
*.orig
*./node_module/
*.idea/
*.rej
*~
*.o
tests/*.err
But abort error on hg status.
Well, hg help hgignore points to have a look at hg help patterns. I can't quite explain it better:
Mercurial accepts several notations for identifying one or more files at a
time.
By default, Mercurial treats filenames as shell-style extended glob
patterns.
Alternate pattern notations must be specified explicitly.
Note:
Patterns specified in ".hgignore" are not rooted. Please see 'hg help
hgignore' for details.
To use a plain path name without any pattern matching, start it with
"path:". These path names must completely match starting at the current
repository root.
To use an extended glob, start a name with "glob:". Globs are rooted at
the current directory; a glob such as "*.c" will only match files in the
current directory ending with ".c".
The supported glob syntax extensions are "**" to match any string across
path separators and "{a,b}" to mean "a or b".
(...)
Plain examples:
path:foo/bar a name bar in a directory named foo in the root
of the repository
path:path:name a file or directory named "path:name"
There are alternate ways to specify paths using regex as well as also explained in the available command line help.
So, use something like
node_module/**
.idea/**
or
path:node_module
path:.idea
provided you quoted your entire .hgignore and thus use the default glob pattern matching.
finally i found tip . here is how to .
Foradding node_modules/ and .idea/ folder you need to specify the following.N.B > is refers terminal.
touch .hgignore
nano .hgignore
add the following
^node_modules/
^.idea/
Done !

Can I use wildcards in the filemap of hg convert

I have a repository with one file (subdir/a.txt), and the one revision, adding it.
If I run hg convert with a filemap consisting of include subdir/a.txt, it works just fine.
But if the filemap is include subdir/*.txt, include */a.txt, or include **/*.txt, the resultant repository has no revisions in it.
Is it possible do use wildcards in the filemap of hg convert?
--
The reason I want to do this is so that I can create a new repository with history, but without any binary files. I want to be able to do something like exclude **/*.dll. Is there any way to do that?
Wildcards do not seem to be supported, but you can use hg manifest --all to get a list of all files present in all changesets, and do some filtering and editing of the output to generate what to exclude. Something like the following to list all the DLL file paths on Windows:
hg manifest --all | findstr \.dll

How can I grep a specific file in a specific revision (unchanged in that revision) in Mercurial

I have several repositories that I am building a tool to interact with. I have not been able to find a way to grep a specific file in a specific revision that was unchanged in that revision.
The help for hg grep says that the -r option -r --rev REV [+] only search files changed within revision range. If I update the revision in question, I can grep appropriately, and I get the desired results. Because my file in question is unchanged in that revision, it will not get grepped. Does anyone know a way to do this?
My end goal is that I would like to ignore files that meet a certain pattern matching. I am not sure that using the --all option would be feasible, because I would have to parse the revisions that the pattern appeared and disappeared in.
Thanks in advance.
edit:
Actual problem I'm trying to solve:
There are several tagged revisions in a repository.
For each of those tagged revisions, I would like to extract a particular file (assume source/a.c or something like that) to a folder structure that others can access (a website for those outside of our group, whom we cannot give repository access to).
But, I would only like to extract the file if it does not contain a particular pattern. This is why I would like to check the file at a specific revision, even if it has been unchanged.
Right, hg grep indeed does not analyse the file contents at a particular revision but only when the file actually changes. Thus I suggest a slightly different way:
Get the revisions to check as a nice list:
hg log -r"tag()" --template="{rev}\n"
Using it this way (instead of tags) allows to also look at revisions which are not tagged. If it's really only tags, you might resort to the hg tags command directly: `hg tags --template="{tag}\n". It would make the $i in the small script below a nice tag name instead of a revision :)
You can use this list to get the file FILENAME at those respective revisions and then you need some small script which actually checks that file for the content in question:
for i in $(hg log -r"tag()" --template="{rev}\n"); do
if hg cat FILENAME -r$i 2>/dev/null | grep PATTERN > /dev/null; then
hg cat FILENAME -r$i > path/to/whereever/FILENAME.$i
fi
done

How can I format the mercurial "hg log" output easily as parsable JSON?

I would like a command-line example on how to easily use hg log, with hg filters, and output it safely to JSON (with an array that contains the files).
Multi platform (windows/unix) would be great.
Mercurial has built-in support for JSON.
You can get log output in JSON format simply by using:
hg log -Tjson
Filters can be used as usual, and to get the files, you can add the '-v' (verbose) parameter.
Note that this is a relatively new feature (see the wiki for more details), which is probably why it's not clearly documented yet.
It's also possible to get xml output using:
hg log -Txml
Edit: this answer here works for any hg version. for newer hg versions (3.1+), see the other answer which is more performant and simpler.
Here is a solid oneliner, as an example.
It uses mercurials hg log, and pipes its output to a python oneliner. The hg log template is configured to output valid python literals. The python oneliner converts it to JSON.
hg log --date ">2014-10-01" --no-merges --keyword "mantis#1953" --keyword "mantis#1955" --template "[\"{node|short}\",\"{author|user|urlescape}\",\"{date|rfc3339date}\",\"{desc|urlescape}\", [{files % '\"{file}\",'}]]\n" --user marinus --user develop | python -c "import sys,ast,json,urllib; x=[[z[0], urllib.unquote(z[1]).decode('utf8'), z[2], urllib.unquote(z[3]).decode('utf8'), z[4]] for z in [ast.literal_eval(y) for y in sys.stdin.readlines()]]; print(json.dumps(x,indent=2))"
The above example is for unix, but you can simply replace \" for "", if you need windows compatibility. It you want unformatted JSON, set 'indent' to None.
The python code is 2/3 compatible (any up-to-date version), and does not use any external modules.
For more explanation of the used hg commands, see:
hg help log
hg help dates
hg help templates
The python code uses nested list comprehensions, google it for more info.

tool to inspect mercurial's internal files

Git has the cat-file command to inspect internal files, e.g. git cat-file blob 557db03 will show the contents of the object whose hash starts with 557db03.
Are there similar tools for mercurial that allow me to look at all the different data files that merfcurial uses internally?
Try hg --debug help and you can see the list of all the debug commands:
debugancestor:
find the ancestor revision of two revisions in a given index
debugbuilddag:
builds a repo with a given DAG from scratch in the current empty repo
debugbundle:
lists the contents of a bundle
debugcheckstate:
validate the correctness of the current dirstate
debugcommands:
list all available commands and options
debugcomplete:
returns the completion list associated with the given command
debugdag:
format the changelog or an index DAG as a concise textual description
debugdata:
dump the contents of a data file revision
debugdate:
parse and display a date
debugdiscovery:
runs the changeset discovery protocol in isolation
debugfileset:
parse and apply a fileset specification
debugfsinfo:
show information detected about current filesystem
debuggetbundle:
retrieves a bundle from a repo
debugignore:
display the combined ignore pattern
debugindex:
dump the contents of an index file
debugindexdot:
dump an index DAG as a graphviz dot file
debuginstall:
test Mercurial installation
debugknown:
test whether node ids are known to a repo
debugpushkey:
access the pushkey key/value protocol
debugrebuildstate:
rebuild the dirstate as it would look like for the given revision
debugrename:
dump rename information
debugrevlog:
show data and statistics about a revlog
debugrevspec:
parse and apply a revision specification
debugsetparents:
manually set the parents of the current working directory
debugstate:
show the contents of the current dirstate
debugsub:
(no help text available)
debugwalk:
show how files match on given patterns
debugwireargs:
(no help text available)
There are a lot of them, and they pretty much expose everything.
The closest commands would be:
hg cat -r rev aFile
hg cat: Print the specified files as they were at the given revision
This is not completely the same than git cat-file though, as the latter can also list SHA1, type, and size for a list of objects.
In that second case, hg manifest might be more appropriate.