代码之家  ›  专栏  ›  技术社区  ›  mwolfe02

Mercurial中不区分大小写的diffs

  •  7
  • mwolfe02  · 技术社区  · 16 年前

    我使用Mercurial(特别是Windows上的TortoiseHg)来控制VBA代码的版本。任何尝试过这种方法的人都知道,只要在项目中的任何地方(无论范围如何)更改变量的任何声明,VBA就会更改整个项目中每个变量的大小写。它使版本控制成为一场噩梦。

    执行差异时忽略源代码中的大小写更改 . 最简单的方法是什么(我缺少的一些diff选项,一个外部diff实用程序,或者其他什么?)

    注意:我不是说处理'不区分大小写的文件名'(是的,我是说你谷歌…)

    3 回复  |  直到 16 年前
        1
  •  7
  •   Ry4an Brase    16 年前

    您可以使用 ExtDiff Extension .

      [extensions]
      hgext.extdiff =
    
      [extdiff]
      # add new command that runs GNU diff(1) in case-insensitive mode
      cmd.mydiff = diff
      opts.mydiff = -i
    

    然后你就跑了 hg mydiff

    然而,这并不像您希望的那样有用,因为在内部,当然,Mercurial不能忽略case——它接受文件内容的加密散列,而这些内容不允许摆动空间。所以如果你准备好了,你会做的 ,看不到任何更改,然后执行 hg commit 到处都能看到变化。

    一种选择是找到一个visualbasic代码清理器,类似于 indent 对于类C语言,它规范化变量大小写并在mercurial提交钩子中运行。然后,至少所有进入源代码管理的代码都将是一致的,并且您可以准确地区分不同的修订。

        2
  •  2
  •   Martin Geisler    16 年前

    encode/decode hooks

    [encode]
    *.vba = tr A-Z a-z
    

    编码

    考虑包含的文件

    hello
    

    Hello World
    

    % hg diff
    diff --git a/a.txt b/a.txt
    --- a/a.txt
    +++ b/a.txt
    @@ -1,1 +1,1 @@
    -hello
    +hello world
    

    注意大写字母“H”和“W”是如何被忽略的。

    reposettings 分机可以帮你。

        3
  •  2
  •   mwolfe02    10 年前

    这是我决定的解决办法。这远不理想,但比我考虑过的其他选择要好。

    我创建了一个自动热键脚本,它执行以下操作:

    • 将存储库中检测到更改的MS Access文件还原为.orig文件
    • 读取.orig文件(包含更改的文件)
    • 读取现有文件(存储库中已存在的文件)
    • 将两个文件的文本转换为小写
    • 比较文件的小写内容
    • 如果文件是相同的(即,它们只是大小写不同,.orig文件会被删除,因为我们不关心这些更改)

    对于有我们关心的实际更改的文件,我仍然可以看到所做的案例更改。如果这会导致大量的噪声,我会在一个允许不区分大小写比较的比较工具(例如kdiff)中打开该文件。

    这是我的剧本。请注意,该脚本包含另一个自动热键脚本ConsoleApp.ahk,它提供了一个名为, ConsoleApp_RunWait() . 这是一个第三方脚本,不再与64位AHK很好地工作,所以我不包括它作为我的答案的一部分。任何执行命令行并以字符串形式返回输出的AHK函数就足够了。

    ; This script checks an MS Access source directory and reverts all files whose only modifications are to the 
    ; case of the characters within the file.
    
    #Include %A_ScriptDir%\ConsoleApp.ahk
    #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
    SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
    SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
    
    ; Allow for custom path to hg (support for moving to TortoiseHg 2.0)
    IniRead hg, %A_ScriptDir%\LocalSettings\Settings.cfg, TortoiseHg, hg_path, hg
    
    if 0 < 1  ; The left side of a non-expression if-statement is always the name of a variable.
    {
        MsgBox Usage:`n`HgIgnoreCase DirectoryWithFilesToScrub
        ExitApp
    }
    
    SrcDir = %1%
    StringReplace SrcDir, SrcDir, ", , All
    
    StringRight test, SrcDir, 1 ; add trailing slash if necessary
    ifnotequal test, \
        SrcDir = %SrcDir%\
    
    RestoreOriginals(SrcDir)
    RevertCaseChangeModifiedFiles(SrcDir)
    
    RevertCaseChangeModifiedFiles(SrcDir) {
    global hg
        includes =  -I "*.form" -I "*.bas" -I "*.report" -I "*.table"
        cmdline = %hg% revert --all %includes%
    
        ;Don't revert items that have been removed completely
        Loop 3
        {
            Result := ConsoleApp_RunWait(hg . " status -nrd " . includes, SrcDir)
            If (Result)
                Break
        }
        Loop parse, Result, `n, `r
        {
            if (A_LoopField)
                cmdline = %cmdline% -X "%A_LoopField%"
        }
        Result =
        ;msgbox %cmdline%
        ;revert all modified forms, reports, and code modules
        Loop 3
        {
    
            Result := ConsoleApp_RunWait(cmdline, SrcDir)
            If (Result)
                Break
        }
        ;MsgBox %Result%
    
        Loop parse, Result, `n, `r
        {
            StringLeft FileStatus, A_LoopField, 9
            If (FileStatus = "reverting")
            {
                StringMid FName, A_LoopField, 11
                FullPath = %SrcDir%%FName%
                ToolTip Checking %FullPath%
                RestoreIfNotEqual(FullPath, FullPath . ".orig")
            }
        }
        ToolTip
    }
    
    RestoreIfNotEqual(FName, FNameOrig) {
        FileRead File1, %FName%
        FileRead File2, %FNameOrig%
    
        StringLower File1, File1
        StringLower File2, File2
        ;MsgBox %FName%`n%FNameOrig%
        If (File1 = File2)
            FileDelete %FNameOrig%
        Else
            FileMove %FNameOrig%, %FName%, 1
    }
    
    RestoreOriginals(SrcDir) {
        Loop %SrcDir%*.orig
        {
            ;MsgBox %A_LoopFileLongPath%`n%NewName%
            NewName := SubStr(A_LoopFileLongPath, 1, -5)
            FileMove %A_LoopFileLongPath%, %NewName%, 1
        }
        while FileExist(SrcDir . "*.orig")
            Sleep 10
    }
    
    推荐文章