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

在vb6中使用git

  •  14
  • Gavin  · 技术社区  · 16 年前

    我们公司在vb6中有一个很大的代码库,我们目前使用的vss,尽管我们讨厌它,但至少集成到了vb6 ide中。

    我自己的团队正在使用.net,现在正在寻找其他的scm,比如我个人最喜欢的git。用 Git Extensions ,看来我们可以很好地将git命令集成到visual studio ide中。

    然而,有人提出了一个问题:git也可以用于我们的vb6代码库吗?

    当然,我认为这些文件本身在git存储库中运行良好,但毫无疑问,如果开发人员不得不使用命令行来执行所有的源代码控制,他们会抱怨。但是有没有人有使用vb6和git的经验呢?VB6 IDE中是否有可用的集成?或者,没有集成ide可能不那么麻烦吗?

    我是不是因为第一个创造了[ VB6 [和] 吉特 ?

    7 回复  |  直到 7 年前
        1
  •  14
  •   KeithTheBiped    10 年前

    我发现这个解决方案对我们的情况有效。它在前面的答案基础上增加了一些内容,解决了让项目使用git的所有问题。

    .gittattributes属性

    # Set the default behavior, in case people don't have core.autocrlf set.
    * text eol=auto
    *.bas text eol=crlf
    *.frm text eol=crlf
    *.log text eol=crlf
    *.vbp text eol=crlf
    *.cls text eol=crlf
    *.vbw text eol=crlf
    *.dsr text eol=crlf
    *.ini text eol=crlf
    *.res binary
    *.RES binary
    *.frx binary
    *.exe binary
    *.dll binary
    *.ico binary
    *.gif binary
    *.ocx binary
    *.tlb binary
    *.ocx.bin binary
    *.ism binary
    *.bin binary
    *.aps binary
    *.ncb binary
    *.exe.compat binary
    *.ocx.compat binary
    

    吉蒂格诺

    .DS_Store
    .Trashes
    *.vbw
    *.csi
    *.exp
    *.lib
    *.lvw
    *.dca
    *.scc
    *.tmp
    <name of built binary, exe, dll or ocx>
    
        2
  •  6
  •   Blasio    16 年前

    使用git管理vb6项目已经有一年了。从未遇到任何IDE集成。就我个人而言,我喜欢命令行,所以我没有看太多。我遇到的两个主要问题是:

    1. VB6 IDE不监视项目文件,如果其中任何文件在外部更改(例如使用“git reset”、“git checkout”),则需要重新打开项目以反映更改。
    2. VB6IDE有时会在加载项目时更改事件参数或变量的大小写,因此使用“git commit--all”是不安全的,除非您希望在代码更改时出现大量垃圾。
        3
  •  4
  •   Community Mohan Dere    9 年前

    你最了解你的开发者。他们介意用命令行吗?他们热衷于集成ide吗?这些都是个人喜好。

    确保最受尊敬的开发人员理解git的好处并支持这个决定。

    请注意,某些VB6源文件是二进制的, shouldn't ever be merged :例如 .frx 文件夹。我不认识吉特,所以我不知道这是不是个问题。

        4
  •  3
  •   hasen    16 年前

    vb6作为一个不适合git的代码库(即文本文件)有什么不同?

    文化完全是另一回事:如果有很多不称职的开发人员不能处理命令行,那么解决方法可能包括尽可能远离vb6。

    唯一的潜在问题是git世界中的windows在某种程度上是二等公民。如果您发现git在您的环境中工作不太好,您可能想尝试bazaar或mercurial。

        5
  •  3
  •   Mark Dornian    10 年前

    我们在做这个。我们在.gitignore中添加了以下内容

    • *CSI
    • *EXP
    • *自由基
    • *LVW
    • *VBW
    • 我的计划 dll
        6
  •  3
  •   mkrohn    7 年前

    你必须创建文件 .gittattributes属性 使用windows行尾(crlf),因为git是在unix中诞生的。

    # Declare files that will always have CRLF line endings on checkout.
    *.vbp text eol=crlf
    *.frm text eol=crlf
    *.cls text eol=crlf
    *.bas text eol=crlf
    *.dsr text eol=crlf
    *.ini text eol=crlf
    
    # Denote all files that are truly binary and should not be modified.
    *.frx binary
    *.exe binary
    *.dll binary
    *.ocx binary
    

    还可以使用以下行创建.gitignore文件:

    ## Ignore Visual Studio temporary files, build results, and
    ## files generated by popular Visual Studio add-ons.
    
    # User-specific files
    *.vbw
    *.tmp
    *.scc
    *.dca
    
        7
  •  2
  •   User51    8 年前

    这真的是对KeiththeBiped等人的其他优秀评论的补充…

    但是,可以将vb6中的即时窗口强制为 行为像 一个现代化的终端窗口,有一些注意事项。如果我们创建一个helper函数来运行该命令,以某种方式捕获输出,然后使用debug.print将其中继回与终端窗口类似的即时窗口,当然没有任何交互元素。

    这适用于大多数命令,但无法捕获 git push 相位。一个可接受的折衷方案,以方便无壳(imo)。

    我们可以使用命令提示符( cmd.exe /c )使用 1> 2> 针对临时文件的管道。我不提供两个底层函数,但如果您还没有这些函数,则提供源代码。

    考虑以下功能:

    Public Function RunCmdToOutput(ByVal cmd As String, Optional ByRef ErrStr As String = "") As String
    Const p_enSW_HIDE = 0
    
    On Error GoTo RunError
    
      Dim A As String, B As String
      A = TempFile
      B = TempFile
    
      ShellAndWait "cmd /c " & cmd & " 1> " & A & " 2> " & B, p_enSW_HIDE
    
      RunCmdToOutput = ReadEntireFileAndDelete(A)
      ErrStr = ReadEntireFileAndDelete(B)
    
      Exit Function
    
    RunError:
      RunCmdToOutput = ""
      ErrStr = "ShellOut.RunCmdToOutput: Command Execution Error - [" & Err.Number & "] " & Err.Description
    End Function
    

    你需要:

    • tempfile-返回程序具有读/写访问权限的唯一且不存在的文件名。它可能应该使用 GetShortPathName API 缩短长路径名。
    • ShellAndWait -标准的“启动一个进程并等待它退出”。
    • readentirefileanddelete-正如它所说…获取内容,删除文件,返回字符串。

    一旦您完成了这项工作,并且能够成功地运行任何简单的执行并输出到即时窗口中,如下所示:

    ?runcmdtooutput("ver")
    Microsoft Windows [Version 10.0.16299.309]
    

    从这里开始,您可以运行git,并将大多数内容显示到即时窗口中,并且可以像那样简单地使用它,但是我们可以做得更好。

    假设您已经安装了一个命令行git,并且更新了路径,使其可用,那么您可以创建一些新函数(希望是在模块中):

    Private Function GitCmd(ByVal C As String, Optional ByVal NoOutput As Boolean = False) As String
      Dim ErrSt As String
      GitCmd = RunCmdToOutput(C, ErrSt)
      If Not NoOutput Then Debug.Print GitCmd ' Because it also returns the string
      If ErrSt <> "" Then Debug.Print "ERR: " & ErrSt
    End Function
    
    Public Function Git(ByVal C As String) As Boolean
      GitCmd "git " & C
      Git = True
    End Function
    

    从这里,您几乎可以从即时窗口运行git命令。记住,git()是一个函数,所以必须将参数作为字符串传入…只有一个必要的角色。当然,vb会自动完成一个字符串,所以您不需要完全拖尾,但我会包括它。使用语法:

    Git "status"
    Git "add ."
    Git "commit -m ""Some Git Commit"""
    Git "pull -r"
    Git "push"
    

    它不允许交互式git命令( git add -p )但是,你可以用暴力( git add . -f )但是,这些命令会运行并直接将其输出显示到即时窗口中,而无需太多其他工作。

    git "status"
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    ...
    

    你明白了。

    从那里,你也可以自动化的事情。创建helper函数来批处理常用的git命令等,或者只是消除一些笨拙的语法。用 RunCmdToOutput ,如果愿意的话,您也可以重新使用msgbox,但我认为即时窗口足够直观。

    在某些情况下,限制任何函数只在ide中运行可能也很重要,但这是可选的。

    Public Function IsIDE() As Boolean
      On Error GoTo IDEInUse
      Debug.Print 1 \ 0 'division by zero error - Debug is ignored by compile
      IsIDE = False
      Exit Function
    IDEInUse:
      IsIDE = True
    End Function
    
    Public Function GitStatus()
      If Not IsIDE Then Exit Function
      GitCmd "git status"
      GitStatus = True
    End Function