Mercurial "hginclude"? (globbing syntax to specify which files to track) - mercurial

I was wondering if Mercurial or any of its extensions support a mechanism to specify with globbing rules what files to track (i.e. a file that serves the opposite purpose of .hgignore).
I understand that I can use regular expressions in .hgignore to specify files to ignore (and hence, by exclusion, which ones to track), but I like the globbing sintax Mercurial supports for .hgignore, and was wondering if I could use the same syntax to specify which files to track.

Use a negative look-ahead assertion in .hgignore. For example, you could use the following to only include C++ source files. Note that all files you intend to match must be in the one regex.
(?!.*\.([ch](pp|xx)?|C|H))
However, I don't think you can do this with the globbing syntax.

Related

Mercurial -- Ignore certain files based on the existence of other files

I use mercurial to keep track of a repository which contains both PDF files (generated by others, which I need to keep track of), and latex files, written by me.
For instance, assume a directory structure like this:
root
- Requirements.pdf
- MyReport.tex
- MyReport.pdf
In this case, MyReport.pdf changes every time MyReport.tex does, and can be wholly determined by the contents of the tex file, so it should not be under version control.
I am looking for a way to tell mercurial to ignore such files. Obviously I can add a rule to .hgignore like this (http://www.selenic.com/mercurial/hgignore.5.html)
syntax: glob
*.pdf
But that will ignore the PDFs that I do need to keep version controlled.
There's also this link: https://www.mercurial-scm.org/wiki/TipsAndTricks#Avoid_merging_autogenerated_.28binary.29_files_.28PDF.29 but that doesn't really solve my problem either, because while it handles building the PDFs, it does not handle telling hg which files are important.
Or I could just do this manually, but I would like a way to script it, to make it more general, since these repositories can have several dozen tex and pdf files and manually managing this has become cumbersome.
It seems like quite a simple rule: If there is a file by the name of "blah.pdf", check to see if there is also a file name "blah.tex" and if so, ignore it, otherwise, pay attention to it. But I can't find anything about that.
There is no such feature in Mercurial, nor in Git, nor will there likely ever be such a feature because it's extremely niche. However, you might consider simply putting your "generated" files into a separate output subdirectory, and then ignoring all such directories. For example, if you have an input like foo/bar.tex, the output could be foo/gen/bar.tex, and you could ignore gen/.
Obviously I can add a rule to .hgignore like this
(http://www.selenic.com/mercurial/hgignore.5.html) ... But that will
ignore the PDFs that I do need to keep version controlled.
.hgignore ignore all newly added or existing not versioned files, matching pattern, but bolded texts give you at least two usable solutions:
Write regexp, which means "all pdf, except some filename(s)" (with manually added filenames, most probably)
use wide pattern, but add needed files into repository explicitly (hg add FILENAME)

How do I make mercurial ignore symbolic links?

Can I add options to .hgignore or .hgrc such that symbolic links are automatically ignored in order to avoid clutter of hg status?
A solution like find -type l >> .hgignore is infeasible as it tends to become slow, unmanageable and ugly.
No, there is no options for ignoring certain types of files. The only thing you can match on it the filename.
People typically handle this by making sure that the files they want ignored follow a pattern so they can be matched with a glob or regex pattern — or they make sure that these files are in a common subdirectory and ignore that.

Is the glob syntax used by Mercurial cross-platform?

I started getting creative with my glob syntax in my .hgignore file to compress groups of lines (similar extensions, etc) into one. However, in reading the WP Glob syntax article section, I'm left with the question if this will break on my colleagues' Windows boxes.
Is Mercurial parsing the globs itself or does it leave it to the OS?
Mercurial does the parsing itself, or at least in a cross-platform way through its python code. I've shared complex ignores across platforms without problems.

prevent merge of ascii file in Mercurial

Is there a way to tell Mercurial that a specified ascii file should be completely overwritten rather than merged during future updates, similar to the treatment of a binary file?
Git handles this using .gitattribues, as described here: Git mark file as binary to avoid line separator conversion. Is there a Mercurial equivalent?
Have a look at merge-patterns (in the hgrc). This allows you to specify internal:other as the merge action.

hgignore multi line regex

I googled a bit, but didn't find any suggestions on that topic. Is multi line regex possible in .hgignore?
I'm writing a magento module, and wan't to include only my module code in repository, so I came up with this regex, but it would a be mess, if I had to write it in one line.
syntax: regexp
^(?!(
app/code/local/Mage/Myreviews/|
app/design/frontend/default/default/layout/myreviews\.xml|
app/design/frontend/default/default/template/myreviews/|
app/etc/modules/Mage_Myreviews\.xml|
skin/frontend/default/default/css/myreviews/|
skin/frontend/default/default/myreviews/|
js/myreviews/
)).*
As for the canonical answer to your question, are multi-line regular expressions supported? No. For confirmation, take a look at the ignorepats function in ignore.py in the mercurial Python package—it iterates over the lines in the file one by one.
As for what you should do instead, #jk.'s answer is good (and the glob: * that you've come up with).
You can add files to a repository and have mercurial track them even if they match an ignore rule, so usually the best way to do this sort of thing is to ignore a bit too much e.g. (don't know anything about magneto modules so this may be wrong)
syntax: glob
app/*
skin/*
js/myreviews/*
and then explicitly hg add the files you do want.
As Joel points out hg adds --include and --exclude options are also useful in these scenarios
pre-emptive additional info: hg forget will undo tracking a file without deleting it