14

In a rather large project, I would like to put the same file (or folder) in different locations. When it is changed in one location, the changes should be propagated. In Subversion, I could use externals to achieve this behavior.

I tried to solve this by using hard links and symbolic links, but Mercurial seems to not track any of them. Instead, it commits the content of the files to its repository instead of the link property. When I clone the repository, the information is lost.

Is this a Windows-specific behavior of Mercurial or can't it track links at all? Is there another way to track a file that is accessible from different locations in Mercurial?

fschoenm
  • 1,391
  • 13
  • 32

1 Answers1

16

Mercurial can track symbolic links, but they look strange when checked out on Windows. What happens is that Mercurial creates a file with the link target as the file content. There is unfortunately no support for creating real symbolic links on Windows systems that support them, such as Windows Vista. The result of this is that you cannot use symbolic links in a repository that is supposed to be portable between both systems. Please see the discussion in Issue1825 for more on this feature.

The closest match for svn:externals is Mercurial subrepositories. Depending on how you used svn:externals, subrepos may or may not be what you want. Please see my answer to another question about subrepos for some advice. I wrote part of the code for subrepos and off the top of my head, I think mounting a subrepo several times in the same main repository sounds like a recipe for confusion. But maybe you can make it work — just be aware that subrepos are a tricky part of Mercurial.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • 2
    But NTFS does support symbolic links since Windows Vista. – fschoenm Jan 03 '12 at 12:29
  • Right, I'd forgotten that Windows recently added symlink support. We have no support for creating them, unfortunately. [Issue1825](http://mercurial.selenic.com/bts/issue1825) is related to this. – Martin Geisler Jan 03 '12 at 12:36
  • Recently? Vista was release 5 years ago ;) – fschoenm Jan 03 '12 at 12:37
  • 2
    Wow, it's already been 5 years? :-) It's strange that we don't create them then. I'll encourage you to use [this answer](http://stackoverflow.com/a/1447651/110204) with the [hackable Mercurial](http://mercurial.selenic.com/wiki/HackableMercurial) and see if you can come up with something. The relevant starting point is `mercurial.windows.checklink` and the places that call `checklink` to determine if they can call `os.symlink`. – Martin Geisler Jan 03 '12 at 12:51
  • 3
    It turns that Python added support for Windows symlinks in [changeset 730b728e5aef](http://hg.python.org/cpython/rev/730b728e5aef/). However, that only helps on Python 3, and Mercurial only runs on Python 2. – Martin Geisler Jan 03 '12 at 13:22
  • Ehm, why the down vote? I'm sorry that the answer is negative, but we don't support symbolic links on Mercurial today and it's not something I have the time to fix right now. Even though the answer doesn't provide a solution, I still believe its helpful and gives good pointers to more information. – Martin Geisler Jan 03 '12 at 15:11
  • The downvote didn't come from me, you were very helpful :-) So I assume support for links on NTFS depends on when Mercurial will work with Python 3? I suppose I have to search another solution then. I think the subrepo feature would be too complex for our project unless we get rid of most externals we use. – fschoenm Jan 03 '12 at 15:58
  • fschoenm: thanks for the kind words, I didn't think you down-voted me. Regarding Python 3, then don't wait for that: Mercurial will probably not support it since Python 2.x has been enough for us so far. However, more situations could perhaps change things in the long run (we're talking years here). – Martin Geisler Jan 03 '12 at 16:27
  • @fschoenm: no need for Python 3, mg pointed out a workaround by calling the Windows API using ctypes. Maybe a good opportunity/motivation for a contribution to Mercurial? :) – Laurens Holst Jan 03 '12 at 17:15
  • @MartinGeisler: Because the first paragraph of the answer was incorrect, as pointed out by fschoenm. However, I decided to undo the downvote and edit your answer as a more constructive way to address the problem :). – Laurens Holst Jan 03 '12 at 17:24
  • @LaurensHolst: thanks for the explanation, I've updated the answer. You're of course correct that newer Windows systems can handle symlinks — I guess the developer community has just not caught up with the fact yet :-) – Martin Geisler Jan 03 '12 at 18:07
  • 8
    Windows symlinks require administrator privileges, which makes them completely unsuitable for day-to-day usage in a user-level tool like Mercurial. Python 3 has nothing to do with it. – mpm Jan 03 '12 at 18:12
  • 4
    @mpm: yes, you require a "Create symbolic links" privilege and administrators have that by default. As I understand it, normal users can also be granted the priviledge without making them administrators. – Martin Geisler Jan 03 '12 at 19:09