Mercurial: ignore files if the file with different extension is present - mercurial

In my mercurial repository I have a lot of different files. For example .org and .tex files. Exporting the .org file generates a .tex file. Normally I do not want to ignore .tex files since these are usually source files. But I am looking for something like:
foo.org present => ignore foo.tex
foo.org absent => do not ignore foo.tex

There is no such option available in Mercurial.
What you could do is create an extension of your own to make some kind of 'hg customstatus' command available. This could be a wrapper around the 'hg status' command that executes the filtering you want.

Related

How can i make mercurial to add wildcard for file name

we are working on a project, where the angularjs web project is compiled and binaries are stored in hg repo. The problem is angularjs js files are usually compiled with hashing for all binary files. Ex: binary files are suffixed with unique extensions for each file
main.1cc794c25c00388d81bb.js,
polyfills.eda7b2736c9951cdce19.js,
runtime.a2aefc53e5f0bce023ee.js,
common.7d1522841bf85b01f2e6.js,
1.620807da7415abaeeb47.js,
2.93e8bd3b179a0199a6a3.....etc.
The problem is every time a new binary in checkin in hg repo, it is being detected as new file and retained along with old file of same name. So, i need a way to fool the hg repo, to retain the file name but still consider them as old file replacing the previous one.
main.1cc794c25c00388d81bb.js ==> overwrite old main.js
polyfills.eda7b2736c9951cdce19.js ==> overwrite old polyfill.js
runtime.a2aefc53e5f0bce023ee.js ==> overwrite old polyfill.js
common.7d1522841bf85b01f2e6.js ==> overwrite old commom.js
1.620807da7415abaeeb47.js ==> overwrite old 1.js
2.93e8bd3b179a0199a6a3 ==> overwrite old 2.js
Could any one point out a way, to fool the hg to consider these files are just modification of previous files and not as new files ?
Can hgignore or some other extension be used...
A VCS shall track the state of files. And those are indeed new files. One can argue that those are the old files renamed - which can be recorded by the VCS.
So there are two solutions I see:
Record moving the old filenames to the new filenames. hg addremove --similarity XX might be of big help here. It will result in all the files having the new names each time - but if the similarity is good enough it will work nicely. You might need to adjust the XX to get a similarity measure (0 ... 100) which works for you best. Adding --dry-run for testing purposes might make testing easy. You WILL need to delete the old files before you run hg addremove though.
Have a pre-commit hook which iterates over *.js files and moves via an appropriate regex ..js to *.js omitting the hashing code, effectively overwriting the generic filenames with the newly generated hashed filenames.

Swap a file in Perfoce

In perforce, I can mark for add/mark for delete files. However how can i swap files: replacing an old file with a new file with the same name? I have a couple binary files controlled by Perforce and I would like to replace. It's not a normal change/update case...
Newbie in Perforce. Many thanks!
Isn't this just the normal change/update case? It's just that the change to that particular file is rather extensive:
check out the file in Perforce
copy the new data over that file
commit the changed file to Perforce

mercurial: ignore .h generated from .idl

is it possible to use .hgignore in mercurial to ignore header files generated from idl files?
I have a very large project in VS2008 and, by default, the midl tool generates .h files from .idl files in the same folder and with the same name. Naturally, I do not want the generated files controlled. Is it possible to configure mercurial to ignore a xxx.h file if there is xxx.idl file in the same folder?
Is there any other solution to my problem? Renaming the files for those ~100 projects would take ages and is not really an option I want to consider...
As stevevls pointed out you can just ignore all .h files and then manually add the .h files you do want tracked (hg add overrides ignores).
Another option would be to put something like this in your .hg/hgrc
[ui]
ignore.generated = .hgignore-generated
and then create that file either manually or with a hook so that it lists all the generated .h files. The file could be tracked or untracked at your option. On unix this would auto create that file:
find . -name '*.idl' | sed 's/\.idl$/.h/ >| .hgignore-generated
I've no idea how to script that on windows, but one imagines powershell can do it.
Yes, this is possible. .hgignore is very flexible and accepts globs and regexes. You could probably get away with :
syntax:glob
*.h
See here for more details: http://www.selenic.com/mercurial/hgignore.5.html.

How do I make mercurial ignore any file with .xxx extension

I want Mercurial to ignore any file with a certain extension.
For example, I wanted to ignore files with a .SUO extension. (There's no need to version-control Visual Studio user settings.)
So I changed my .hgignore file to this:
syntax: glob
*.suo
However, this has no effect, and Mercurial still sees my .suo file.
What am I doing wrong here?
If, when running hg status before altering your .hgignore file, the .suo file had a ? in front of it, then it should be ignored now. If anything else (M or A for example) it is already tracked by the repository and will not magically stop being tracked. In such a case you'll need to do hg remove on the file to delete it and have hg stop tracking it, or just do hg forget on it to have hg stop tracking it but keep the file. Either should be followed by a commit.
The only files that will be omitted from the status listing if their path matches a pattern in the .hgignore file are files that are not tracked. It would make no sense to omit a file that is tracked, because you would never see whether it had been modified, added, or removed.
Edit: Mercurial does only track files (you can't make it track empty directories), but the patterns in .hgignore are simply run against strings of the file paths relative to the root of the repository. The very same relative paths that it shows you when you run hg status. So it does work how you say you want it to work because the following lines are a standard part of my own .hgignore files:
syntax: glob
*\obj\*
*\bin\*
*.csproj.user
*.suo
Again, when you run hg status and it shows a .suo file, what single character is at the beginning of that line? Is it a M, A, R, ! or ? character? What is the path after it?
Mercurial uses entries in a file called .hgignore to determine what files it completely ignores. It is normally located in the root file for your repository (and not in the .hg directory, which you might think).
You can find out more here:
http://www.selenic.com/mercurial/hgignore.5.html
Normally, we use regular expression syntax to ensure that case is not a factor in extensions:
# use regexp syntax.
syntax: regexp
(?i)\.dcu
(?i)\.identcache
(?i)\.dof
(?i)\.dsk
(?i)\.bak
(?i)\.old
That way, it ensures that even if for some reason the case of the extension changes, it is still ignored.
Example for ignoring/excluding files with .o extension:
.*\.o$
should translate to .*\.suo$ for .suo extensions.
I have used this method successfully
Check where .hgignore file is located and ensure it is either in $HOME or project root folder. Check the CASE (vs case) of the extension. I doubt if pattern matching is case insensitive.
edit: tested, the pattern matching is NOT case sensitive. Hence, add "*.SUO" if you want to ignore files with ".SUO" extension.

Ignore specific line in files

My question is very similar to this one.
I have the files under Mercurial version control and each file have a string:
<modified-time>some time</modified-time>
This line have created the an external tool, and the tool change this line periodically. I don't want to know about changes in this line and want to ignore the changes in this line when I doing 'diff', 'commit' and 'status' commands.
So, if a file has only one change and the change is that line I need to skip this file in the output of 'hg status' command.
If the file has another changes in the other lines I need to get this file in the output of 'hg status' command.
If I commit the file I need to commit all the changes.
(UPDATE sorry to misread the question and mislead OP.)
If all your files are generated by the external tool, track the source files instead.
If not, and if you can modify the generator, make it use the date keyword as with the bundled keyword extension.
If not (OP's comment indicated so), you could use pre-* hooks to ignore the time change (when it's the only change). It'd be a pain, though, since you have to have a hook for every command that would see the file difference.
Or as OP's comment suggested, revert the file when it has only time change, either manually or automatically (on a timer or subscribe to file system notification).