开发者

Is there an easy way to retrospectively turn Emacs numbered versions of software into git versions?

开发者 https://www.devze.com 2023-02-16 01:55 出处:网络
I have some files from an open source project which I edited somewhat, e.g.开发者_C百科 Makefile

I have some files from an open source project which I edited somewhat, e.g.开发者_C百科

 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?


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号