有没有一种简单的方法可以将 Emacs 编号的软件版本转换为 git 版本?

发布于 2024-10-21 06:53:08 字数 291 浏览 2 评论 0原文

我有一些来自开源项目的文件,我对其进行了一些编辑,例如,

 Makefile
 Makefile.~1~
 Makefile.~2~

这些编号版本是由 Emacs 及其编号版本控制创建的,就像 VMS 版本化文件

我了解 Linux 项目和 Perl 语言项目回顾性地将其最旧的版本放在版本下控制。我想将 .tar.gz tarball 文件中未解压的文件和编号版本追溯添加到版本控制系统中。

有没有相对容易或简单的方法来做这样的事情?我将如何编写脚本来自动化此过程?

I have some files from an open source project which I edited somewhat, e.g.

 Makefile
 Makefile.~1~
 Makefile.~2~

These numbered versions are made by Emacs with its numbered version control and are like VMS versioned files

I understand that the Linux project and Perl language project retrospectively put their oldest versions under version control. I would like to retrospectively add the files as untarred from the .tar.gz tarball file and the numbered versions into a version-controlled system.

Is there any relatively easy or simple way to do such a thing? How would I go about writing a script to automate this process?

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

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

发布评论

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

评论(1

自由如风 2024-10-28 06:53:08

好吧,我要冒险假设您的编号文件全部匹配 - 即 foo.~3~bar.~3~ 是来自相同的整体版本。如果不是,我不明白你怎么可能有足够的信息来构建有意义的历史。当然,我们还假设所有这些编号的文件都在一个目录中,可能包含在您提到的 tarball 中。

以下内容并不完全完美,但它确实适用于我的测试用例。 (它无法正确处理一个版本中存在但下一版本中不存在的隐藏文件 - 如果您关心的话,请将 rm -rf * 更改为更闪亮的内容。)

#!/bin/bash

old_directory=/path/to/numbered_files_dir
repo_dir=/path/to/repo_to_create

empty_repo() {
    (
    cd "$repo_dir" &&
        rm -rf *
    )
}

commit_all() {
    (
    cd "$repo_dir" &&
    git add -A &&
    git commit -e -m "$1"
    )
}


mkdir -p "$repo_dir" && (cd "$repo_dir" && git init)

# note: sort -u gave incorrect results for me here. very strange.
for n in $(find "$old_directory" | grep -o '~[0-9]\+~
 | sort -rn | uniq); do
    echo "version $n"
    empty_repo
    for f in $(find "$old_directory" -type f -name "*.$n" -printf '%P\n'); do
        mkdir -p "$repo_dir/$(dirname "$f")"
        cp "$old_directory/$f" "$repo_dir/${f%.$n}"
    done
    commit_all "version $n"
done

empty_repo
for f in $(find $old_directory -type f -not -regex '.*\.~[0-9]+~
 -printf '%P\n'); do
    mkdir -p "$repo_dir/$(dirname "$f")"
    cp "$old_directory/$f" "$repo_dir/$f"
done
commit_all "final version"

Okay, I'm going to go out on a limb here and assume that your numbered files all match up - i.e. foo.~3~ and bar.~3~ are from the same overall version. If they aren't, I don't see how you possibly have enough information to construct a meaningful history. And of course, let's also assume all these numbered files are in one directory, possibly bottled up in that tarball that you mention.

The following isn't totally perfect, but it certainly worked on my test case. (It doesn't properly deal with hidden files which exist in one version but not the next - change that rm -rf * to something shinier if you care about that.)

#!/bin/bash

old_directory=/path/to/numbered_files_dir
repo_dir=/path/to/repo_to_create

empty_repo() {
    (
    cd "$repo_dir" &&
        rm -rf *
    )
}

commit_all() {
    (
    cd "$repo_dir" &&
    git add -A &&
    git commit -e -m "$1"
    )
}


mkdir -p "$repo_dir" && (cd "$repo_dir" && git init)

# note: sort -u gave incorrect results for me here. very strange.
for n in $(find "$old_directory" | grep -o '~[0-9]\+~
 | sort -rn | uniq); do
    echo "version $n"
    empty_repo
    for f in $(find "$old_directory" -type f -name "*.$n" -printf '%P\n'); do
        mkdir -p "$repo_dir/$(dirname "$f")"
        cp "$old_directory/$f" "$repo_dir/${f%.$n}"
    done
    commit_all "version $n"
done

empty_repo
for f in $(find $old_directory -type f -not -regex '.*\.~[0-9]+~
 -printf '%P\n'); do
    mkdir -p "$repo_dir/$(dirname "$f")"
    cp "$old_directory/$f" "$repo_dir/$f"
done
commit_all "final version"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文