在 Windows 上设置 Mercurial 的执行位

发布于 2024-08-30 10:10:06 字数 283 浏览 7 评论 0原文

我使用 Mercurial 存储库,该存储库签出到 Unix 文件系统,例如某些机器上的 ext3,以及其他机器上的 FAT32。

在 Subversion 中,我可以设置 svn:executable 属性来控制在支持此类功能的平台上检出文件时是否应将其标记为可执行。无论我在哪个平台上运行 SVN 或包含我的工作副本的文件系统,我都可以执行此操作。

在 Mercurial 中,如果克隆位于 Unix 文件系统上,我可以 chmod +x 获得相同的效果。但是如何设置(或删除)FAT 文件系统上的文件的可执行位呢?

I work on a Mercurial repository that is checked out onto an Unix filesystem such as ext3 on some machines, and FAT32 on others.

In Subversion, I can set the svn:executable property to control whether a file should be marked executable when checked out on a platform that supports such a bit. I can do this regardless of the platform I'm running SVN on or the filesystem containing my working copy.

In Mercurial, I can chmod +x to get the same effect if the clone is on a Unix filesystem. But how can I set (or remove) the executable bit on a file on a FAT filesystem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄居人 2024-09-06 10:10:06

Mercurial 将执行位作为文件元数据的一部分进行跟踪。无法在 Mercurial 中显式设置它,但它会跟踪 Unix 上的 chmod 所做的更改。默认情况下,在 Windows 上添加的文件将设置执行位,但 windows attrib 命令不允许您设置它们。

hg log -p --git 您将看到显示执行位更改的补丁格式,如下所示:

$ hg log --git -p
changeset:   1:0d9a70aadc0a
tag:         tip
user:        Ry4an Brase <[email protected]>
date:        Sat Apr 24 10:05:23 2010 -0500
summary:     added execute

diff --git a/that b/that
old mode 100644
new mode 100755

changeset:   0:06e25cb66089
user:        Ry4an Brase <[email protected]>
date:        Sat Apr 24 10:05:09 2010 -0500
summary:     added no execute

diff --git a/that b/that
new file mode 100644
--- /dev/null
+++ b/that
@@ -0,0 +1,1 @@
+this

如果您执行 unix 系统来设置它们,你可能可以伪造一个类似的补丁并 hg import 它,但这绝对不是最佳的。

Mercurial tracks the execute bit as part of the file metdata. There's no way to explictly set it in mercurial, but it tracks changes made by chmod on unix. Files added on windows will have the execute bit set by default, but the windows attrib command doesn't let you set them.

If you do a hg log -p --git you'll see the patch format that shows the altering of the execute bit, which looks like this:

$ hg log --git -p
changeset:   1:0d9a70aadc0a
tag:         tip
user:        Ry4an Brase <[email protected]>
date:        Sat Apr 24 10:05:23 2010 -0500
summary:     added execute

diff --git a/that b/that
old mode 100644
new mode 100755

changeset:   0:06e25cb66089
user:        Ry4an Brase <[email protected]>
date:        Sat Apr 24 10:05:09 2010 -0500
summary:     added no execute

diff --git a/that b/that
new file mode 100644
--- /dev/null
+++ b/that
@@ -0,0 +1,1 @@
+this

If you're not able to get on to a unix system to set them, you could probably fake up a patch like that and hg import it, but that's definitely sub optimal.

雨后咖啡店 2024-09-06 10:10:06

如果文件系统不支持,则暂时无法更改执行位(我计划将来支持它)。

For the time being you cannot change the execute bit if the filesystem doesn't support it (I have plan to support it in the future).

好久不见√ 2024-09-06 10:10:06

对于 Windows,您需要创建一个补丁文件,然后应用它,就像 Ry4an 所说的,但使用 - -绕过hg import参数。这可以通过创建一个名为 SetFileExecutable.ps1 的 Powershell 脚本文件来完成,其中包含下面的文本,

param (
  [String]$comment = "+execbit",
  [Parameter(Mandatory=$true)][string]$filePathRelativeTo,
  [Parameter(Mandatory=$true)][string]$repositoryRoot
)

if( Test-Path -Path "$($repositoryRoot)\.hg" -PathType Container )
{
  if( Test-Path -Path "$($repositoryRoot)\$($filePathRelativeTo)" -PathType Leaf )
  {
    $filePathRelativeTo = $filePathRelativeTo.Replace( '\', '/' )

    $diff = "$comment" + [System.Environment]::NewLine +
      [System.Environment]::NewLine +
      "diff --git a/$filePathRelativeTo b/$filePathRelativeTo" + [System.Environment]::NewLine +
      "old mode 100644" + [System.Environment]::NewLine +
      "new mode 100755"

    Push-Location
    cd $repositoryRoot
    $diff | Out-File -Encoding 'utf8' $env:tmp\exebit.diff
    hg import --bypass -m "$comment" $env:tmp\exebit.diff
    Pop-Location
  }
  else
  {
    Write-Host "filePathRelativeTo must the location of a file relative to repositoryRoot"
  }
}
else
{
  Write-Host "repositoryRoot must be the location of the .hg folder"
}

按如下方式执行它:

.\SetFileExecutable.ps1" -comment "Marking file as executable" -filePathRelativeTo mvnw -repositoryRoot "c:\myrepo"

使用 Mercurial 的 Bugzilla 中的 Matt Harbison

For Windows you need to create a patch file and then apply it, like Ry4an has said, but with the --bypass argument to hg import. This could be done by creating a Powershell script file called SetFileExecutable.ps1 with the text below inside it

param (
  [String]$comment = "+execbit",
  [Parameter(Mandatory=$true)][string]$filePathRelativeTo,
  [Parameter(Mandatory=$true)][string]$repositoryRoot
)

if( Test-Path -Path "$($repositoryRoot)\.hg" -PathType Container )
{
  if( Test-Path -Path "$($repositoryRoot)\$($filePathRelativeTo)" -PathType Leaf )
  {
    $filePathRelativeTo = $filePathRelativeTo.Replace( '\', '/' )

    $diff = "$comment" + [System.Environment]::NewLine +
      [System.Environment]::NewLine +
      "diff --git a/$filePathRelativeTo b/$filePathRelativeTo" + [System.Environment]::NewLine +
      "old mode 100644" + [System.Environment]::NewLine +
      "new mode 100755"

    Push-Location
    cd $repositoryRoot
    $diff | Out-File -Encoding 'utf8' $env:tmp\exebit.diff
    hg import --bypass -m "$comment" $env:tmp\exebit.diff
    Pop-Location
  }
  else
  {
    Write-Host "filePathRelativeTo must the location of a file relative to repositoryRoot"
  }
}
else
{
  Write-Host "repositoryRoot must be the location of the .hg folder"
}

execute it as follows:

.\SetFileExecutable.ps1" -comment "Marking file as executable" -filePathRelativeTo mvnw -repositoryRoot "c:\myrepo"

The uses the solution provided by Matt Harbison in Mercurial's Bugzilla

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文