将 Git 与 VB6 结合使用

发布于 2024-08-25 10:51:24 字数 508 浏览 8 评论 0原文

我们公司拥有大量 VB6 代码库,目前我们使用 VSS,尽管我们讨厌它,但它至少集成到了 VB6 IDE 中。

我自己的团队正在使用 .NET,现在正在研究替代 SCM,例如我个人最喜欢的 Git。有了 Git 扩展,我们似乎能够很好地将 Git 命令集成到 Visual Studio IDE 中。

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

当然,我假设文件本身在 git 存储库中可以正常工作,但毫无疑问,如果开发人员必须使用命令行来完成所有源代码控制,他们会抱怨。但是有人有使用 VB6 和 Git 的经验吗? VB6 IDE 中是否有可用的集成?或者说,如果没有 IDE 集成,也许并没有那么麻烦?

我会因为第一个创建 [vb6] 和 [git] 的荒谬标签组合而获得徽章吗?

Our company has a large codebase in VB6, and we currently use VSS which, for all that we hate about it, at least integrates into the VB6 IDE.

My own team, which is using .NET, are now looking into alternative SCMs like my personal favourite, Git. With Git Extensions, it seems we will be able to integrate Git commands into the Visual Studio IDE pretty well.

However, the question has been asked: could Git be used for our VB6 codebase too?

Of course I assume the files themselves would work fine in git repositories, but no doubt developers would complain if they had to use the command-line to do all their source control. But has anyone had any experience using VB6 and Git? Any integration available from within the VB6 IDE? Or is it perhaps not that much of a hassle to not have the IDE integration?

And do I get a badge for being the first to create the absurd tag combination of [vb6] and [git]?

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

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

发布评论

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

评论(9

独夜无伴 2024-09-01 10:51:24

我发现这个解决方案适合我们的情况。它为之前的答案添加了更多内容,并解决了让我们的项目与 git 一起工作的所有许多问题。

.gitattributes

# 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

.gitignore

.DS_Store
.Trashes
*.vbw
*.csi
*.exp
*.lib
*.lvw
*.dca
*.scc
*.tmp
<name of built binary, exe, dll or ocx>

I found this solution to work in our situation. It adds a bit more to the previous answers and solved all of our MANY issues getting our project to work with git.

.gitattributes

# 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

.gitignore

.DS_Store
.Trashes
*.vbw
*.csi
*.exp
*.lib
*.lvw
*.dca
*.scc
*.tmp
<name of built binary, exe, dll or ocx>
不再见 2024-09-01 10:51:24

使用 Git 管理 VB6 项目已经大约一年了。从未遇到过任何 IDE 集成。就我个人而言,我喜欢命令行,所以我没怎么看。我遇到的两个主要问题是:

  1. VB6 IDE 不监视项目文件,如果其中任何一个在外部发生更改(例如使用“git reset”、“git checkout”),则需要重新打开项目反映变化。
  2. VB6 IDE 有时会在加载项目时更改事件参数或变量的大小写,因此使用“git commit --all”永远不安全,除非您希望代码更改产生大量垃圾。

Been using Git to manage VB6 projects for about a year now. Never came across any IDE integration. Personally I like the command line, so I've not been looking much. The two major issues I've encountered are:

  1. VB6 IDE doesn't monitor the project files, if any of them is changed externally (e.g. using 'git reset', 'git checkout') then the project needs to be re-opened to reflect the changes.
  2. VB6 IDE will sometimes change the case of event parameters or variables when loading a project, so it's never safe to use 'git commit --all' unless you want a lot of garbage with your code changes.
2024-09-01 10:51:24

您必须创建文件.gitattributes才能使用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

You have to create the file .gitattributes to use windows line endings (crlf) because git was born in 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

Also create .gitignore file with the following lines:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.vbw
*.tmp
*.scc
*.dca
随风而去 2024-09-01 10:51:24

这确实是对 KeithTheBiped 等人的其他精彩评论的补充...

但是,可以在某种程度上强制 VB6 中的立即窗口表现得像现代终端窗口,但有一些注意事项。如果我们创建一个辅助函数来运行命令,以某种方式捕获输出,然后使用 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

您将需要:

一旦你完成了这个,并且可以成功地运行任何简单的执行并输出到立即窗口中,如下所示:

?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)
...

你明白了。

从那里,您还可以实现自动化。创建辅助函数来批处理常用的 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

This really is an addition to the other excellent comments by KeithTheBiped, et al...

But, it is possible to somewhat coerce the Immediate Window in VB6 to act like a modern terminal window, with some caveats. If we create a helper function to run the command, capture the output somehow, and then use Debug.Print to relay that back to the Immediate window SIMILAR to the terminal window, but without any interactive elements, of course.

This works for most commands, but fails to capture some of the output in the git push phase. An acceptable compromise, for the convenience of no shell (imo).

We can do just that using the the command prompt (cmd.exe /c) using the 1> and 2> pipes aimed at temporary files. I don't supply a couple underlying functions, but provide sources if you don't have them already.

Consider the following function:

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

You will need:

  • TempFile - Return a unique and non-existant file-name that your program has read/write access to. It should probably use the GetShortPathName API to shorten long path names.
  • ShellAndWait - The standard "start a process and wait for it to exit".
  • ReadEntireFileAndDelete - Just what it says... Grab the contents, delete the file, return the string.

Once you have accomplished this and can successfully run any simple executing and output into the Immediate window like this:

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

From here, you can run Git, and display MOST things into the Immediate window, and could use it as simple as that, but we can do better.

Assuming you have already installed a command-line Git and the path is updated so that it is available, you can create a few new functions (hopefully in a module):

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

From here, you can ALMOST run Git commands from the immediate window. Remember, Git() is a function, so you have to pass in the argument as a string... Just one necessary character. Of course, VB will auto-complete a string, so you don't NEED the trailing quite, but I'll include it. Use the syntax:

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

It doesn't allow interactive git commands (git add -p), but, you could just brute-force it (git add . -f). But, the commands run and directly display their output into the Immediate window without much other effort.

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)
...

You get the idea.

From there, you can also automate things. Create helper functions to batch commonly used Git commands, etc, or just eliminate some of the clunky syntax. With RunCmdToOutput, you can also re-work some of it to use the MsgBox, if preferred, but I thought the Immediate Window was intuitive enough.

It might also be important at some point to restrict any functions to only run in the IDE, but that's optional.

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
燕归巢 2024-09-01 10:51:24

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

确保最受尊敬的开发人员了解 git 的好处并支持决策。

请注意,某些 VB6 源文件是二进制的,永远不要合并:例如 .frx 文件。我不懂git,所以我不知道这是否有问题。

You know your developers best. Will they mind using the command line? Are they keen on IDE integration? These are personal preferences.

Make sure the most respected developers understand the benefits of git and are behind the decision.

Do be aware that some VB6 source files are binary and shouldn't ever be merged: e.g. .frx files. I don't know git, so I don't know whether that's a problem.

壹場煙雨 2024-09-01 10:51:24

VB6 作为代码库(即文本文件)有何不同,导致它不适合 git?

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

唯一的潜在问题是 Windows 在 git 世界中有点像二等公民。如果您发现 git 在您的环境中运行得不太好,您可能想尝试 bazaar 或 Mercurial。

What's so different about VB6 as a code base (i.e. text files) that makes it not suitable for git?

The culture is another matter altogether: if you have plenty of incompetent developers who can't handle the command line, the cure would probably include running away from VB6 as far as you can.

The only potential problem is that windows in the git world is somewhat of a second class citizen. You might wanna try bazaar or mercurial if you find git doesn't work very well in your environment.

小霸王臭丫头 2024-09-01 10:51:24

我们正在这样做。我们已将以下内容添加到 .gitIgnore

  • *.csi
  • *.exp
  • *.lib
  • *.lvw
  • *.vbw
  • MyProject.dll

We are doing this. We have added the following to .gitIgnore

  • *.csi
  • *.exp
  • *.lib
  • *.lvw
  • *.vbw
  • MyProject.dll
桃扇骨 2024-09-01 10:51:24

我正在使用 Atlassian Source 树来管理 git 存储库中的 VB6 项目。工作正常。

如前所述,一个障碍是,当在 IDE 中定义标识符时,IDE 会关闭并更改匹配标识符的大小写,而这些会产生一系列虚假的更改。

解决方案是在文本文件中保留一块标识符,并根据需要将它们放入每个文件的(常规)(声明)部分,如下所示:

#If False Then
    Dim Index 
    Dim T 
    Dim Ctrl
    Dim C 
#End If

这将强制索引的所有实例为索引等。如果你得到一个当代码更改时会出现一堆 IDE 编辑,您只需粘贴到标准外壳中,然后再次保存文件即可。

I am using Atlassian Source tree to manage my VB6 projects in git repositories. Works fine.

As mentioned, one hurdle is that when an identifier is defined in the IDE, the IDE goes off and changes the case of matching identifiers and these produce screeds of changes that are all spurious.

The solution is to keep a block of identifiers in a text file and slap them into the (General) (Declarations) part of each file as needed like this:

#If False Then
    Dim Index 
    Dim T 
    Dim Ctrl
    Dim C 
#End If

This will force all instances of index to be Index, etc. If you get a bunch of IDE edits appearing as code changes, you simply paste in the standard casing, and save the file again.

瑶笙 2024-09-01 10:51:24

有一个针对旧的 VB6-IDE、VC6-IDE 的解决方案,它使用 MSSCCI,并且可以集成到每个提供 MSSCC 接口进行源代码控制的 IDE 中。
你可以在这里找到它 Visual Git

there is a solution for the old VB6-IDE, VC6-IDE that uses the MSSCCI and can integrate in every IDE providing MSSCC interface for source control.
you find it here Visual Git.

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