From patchwork Fri Feb 21 16:31:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: util: set the hidden attribute on .hg/ during creation on windows (issue4178) From: Ed Morley X-Patchwork-Id: 3731 Message-Id: To: mercurial-devel@selenic.com Date: Fri, 21 Feb 2014 16:31:05 +0000 # HG changeset patch # User Ed Morley # Date 1392999130 0 # Fri Feb 21 16:12:10 2014 +0000 # Node ID e74d0479759cbea6edb632273345d55f96374d70 # Parent 0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd util: set the hidden attribute on .hg/ during creation on windows (issue4178) Windows has no concept of dotfiles/directories being hidden - instead, it requires that a file-is-hidden attribute be set. This patch adds an optional parameter to util.makedir/util.makedirs - which is used to set the hidden attribute when the .hg directory is created on Windows. This has the advantage that both the OS filesystem search & also editors grepping repositories can easily exclude the .hg directory, without needing to exclude it manually every time. diff -r 0e2877f8605d -r e74d0479759c mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -157,7 +157,7 @@ def share(ui, source, dest=None, update= if not os.path.isdir(root): os.mkdir(root) - util.makedir(roothg, notindexed=True) + util.makedir(roothg, notindexed=True, hidden=True) requirements = '' try: @@ -326,7 +326,7 @@ def clone(ui, peeropts, source, dest=Non cleandir = hgdir try: destpath = hgdir - util.makedir(destpath, notindexed=True) + util.makedir(destpath, notindexed=True, hidden=True) except OSError, inst: if inst.errno == errno.EEXIST: cleandir = None diff -r 0e2877f8605d -r e74d0479759c mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -197,7 +197,7 @@ class localrepository(object): if create: if not self.wvfs.exists(): self.wvfs.makedirs() - self.vfs.makedir(notindexed=True) + self.vfs.makedir(notindexed=True, hidden=True) requirements = self._baserequirements(create) if self.ui.configbool('format', 'usestore', True): self.vfs.mkdir("store") diff -r 0e2877f8605d -r e74d0479759c mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -459,7 +459,7 @@ def termwidth(): pass return 80 -def makedir(path, notindexed): +def makedir(path, notindexed, hidden): os.mkdir(path) def unlinkpath(f, ignoremissing=False): diff -r 0e2877f8605d -r e74d0479759c mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -181,8 +181,8 @@ class abstractvfs(object): def lstat(self, path=None): return os.lstat(self.join(path)) - def makedir(self, path=None, notindexed=True): - return util.makedir(self.join(path), notindexed) + def makedir(self, path=None, notindexed=True, hidden=False): + return util.makedir(self.join(path), notindexed, hidden) def makedirs(self, path=None, mode=None): return util.makedirs(self.join(path), mode) diff -r 0e2877f8605d -r e74d0479759c mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -886,10 +886,10 @@ class atomictempfile(object): if safehasattr(self, '_fp'): # constructor actually did something self.discard() -def makedirs(name, mode=None, notindexed=False): +def makedirs(name, mode=None, notindexed=False, hidden=False): """recursive directory creation with parent mode inheritance""" try: - makedir(name, notindexed) + makedir(name, notindexed, hidden) except OSError, err: if err.errno == errno.EEXIST: return @@ -898,8 +898,8 @@ def makedirs(name, mode=None, notindexed parent = os.path.dirname(os.path.abspath(name)) if parent == name: raise - makedirs(parent, mode, notindexed) - makedir(name, notindexed) + makedirs(parent, mode, notindexed, hidden) + makedir(name, notindexed, hidden) if mode is not None: os.chmod(name, mode) diff -r 0e2877f8605d -r e74d0479759c mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -62,7 +62,9 @@ class _BY_HANDLE_FILE_INFORMATION(ctypes _FILE_FLAG_BACKUP_SEMANTICS = 0x02000000 # SetFileAttributes +# http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117%28v=vs.85%29.aspx _FILE_ATTRIBUTE_NORMAL = 0x80 +_FILE_ATTRIBUTE_HIDDEN = 0x2 _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000 # Process Security and Access Rights @@ -469,7 +471,9 @@ def unlink(f): # leaving some potentially serious inconsistencies. pass -def makedir(path, notindexed): +def makedir(path, notindexed, hidden): os.mkdir(path) if notindexed: _kernel32.SetFileAttributesA(path, _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) + if hidden: + _kernel32.SetFileAttributesA(path, _FILE_ATTRIBUTE_HIDDEN)