如何运行 2005 年第一个版本的 git?

Mic*_*ael -2 c git macos linker gcc

git 的第一个版本出现于 2005 年。出于好奇和学习的目的,我试图让它运行。源代码在这里。文件很少,所以看起来很合理,但是由于缺乏 C 细节知识,我陷入了困境。

哪些分步说明可以让它macOS(最好)或 FreeBSD 上运行,并根据需要修改文件?

尝试1

使用macOS Big Sur

  1. 在 中Makefile,更改install $(PROG) $(HOME)/bin/install $(PROG) ./bin/
    This 是为了让二进制文件驻留在本地目录中。
  2. 在 中cache.h,添加行#include <string.h>#include <unistd.h>
  3. brew install openssl
  4. ln -s ../opt/openssl/include/openssl .
  5. make install

结果:错误和警告墙,包括"no member named 'st_ctim' in 'struct stat'""no member named 'st_mtim' in 'struct stat'"等等。

尝试2

使用FreeBSD 12

  1. 在 中Makefile,更改install $(PROG) $(HOME)/bin/install $(PROG) ./bin/
    This 是为了让二进制文件驻留在本地目录中。
  2. 在 中cache.h,添加行#include <string.h>#include <unistd.h>
  3. make install

链接器错误:

/usr/local/bin/ld: read-cache.o:cache.h:64: multiple definition of `sha1_file_directory'; update-cache.o:cache.h:64: first defined here
/usr/local/bin/ld: read-cache.o:cache.h:65: multiple definition of `active_cache'; update-cache.o:cache.h:65: first defined here
/usr/local/bin/ld: read-cache.o:cache.h:66: multiple definition of `active_nr'; update-cache.o:cache.h:66: first defined here
/usr/local/bin/ld: read-cache.o:cache.h:66: multiple definition of `active_alloc'; update-cache.o:cache.h:66: first defined here
/usr/local/bin/ld: update-cache.o: undefined reference to symbol 'SHA1_Init@@OPENSSL_1_1_0'
/usr/local/bin/ld: /lib/libcrypto.so.111: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
*** Error code 1
Run Code Online (Sandbox Code Playgroud)

我遇到了困难,因为我注意到我对 C 和 gcc 的了解太有限,无法继续。有哪些指示可以使其适用于 macOS(最好)或 FreeBSD(否则)?

Jon*_*ler 7

几乎可以肯定,Git 的原始版本仅针对 Linux,而不针对任何其他系统。因此,可移植性问题可能没有得到解决。

\n

这至多是您问题的部分解决方案 \xe2\x80\x94 它应该可以帮助您解决您发现的问题的一个方面。

\n

你说:

\n
\n

结果:错误和警告墙,包括“ no member named 'st_ctim' in 'struct stat'”、“ no member named 'st_mtim' in 'struct stat'”等。

\n
\n

该功能需要定义 macOS 特定的宏:

\n
/* To get the 64-bit inode structure with struct timespec elements on Mac OS X */\n#define _DARWIN_USE_64_BIT_INODE\n
Run Code Online (Sandbox Code Playgroud)\n

结构元素的名称与 POSIX 不一致。在我的代码中,我使用:

\n
#define ST_ATIME st_atimespec\n#define ST_BTIME st_birthtimespec\n#define ST_CTIME st_ctimespec\n#define ST_MTIME st_mtimespec\n
Run Code Online (Sandbox Code Playgroud)\n

POSIX 变体使用(文件生成时间不是 POSIX 的一部分):

\n
#define ST_ATIME st_atim\n#define ST_CTIME st_ctim\n#define ST_MTIME st_mtim\n
Run Code Online (Sandbox Code Playgroud)\n

对于 macOS 和 POSIX 兼容系统以外的系统,我使用这些(并且成员的类型是time_t,而不是struct timespec):

\n
#define ST_ATIME st_atime\n#define ST_CTIME st_ctime\n#define ST_MTIME st_mtime\n
Run Code Online (Sandbox Code Playgroud)\n

这是问题的一部分 \xe2\x80\x94 你还必须找到哪里st_ctim使用 etc 的位置并修改代码以处理可移植性问题。例如,一段代码如下:

\n
    struct stat *sb;\n\n    \xe2\x80\xa6\n\n        case 'a':\n            pr_format_date(sb->ST_ATIME);\n            break;\n        case 'c':\n            pr_format_date(sb->ST_CTIME);\n            break;\n        case 'm':\n            pr_format_date(sb->ST_MTIME);\n            break;\n
Run Code Online (Sandbox Code Playgroud)\n

被调用的函数被传递 a Time *,其中代码具有以下效果之一:

\n
typedef struct timespec Time;\ntypedef time_t          Time;\n
Run Code Online (Sandbox Code Playgroud)\n

函数体对于何时Timeis astruct timespec和何时 is a具有不同的代码time_t

\n