diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:55:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:55:44 +0000 |
commit | 6d5b6d03595796fac6d0aec608e985aa620354ff (patch) | |
tree | 1093002d8d80a0755fe25a49419e1f812c26f171 /debian/import-tar.py | |
parent | Adding upstream version 115.8.0esr. (diff) | |
download | firefox-esr-6d5b6d03595796fac6d0aec608e985aa620354ff.tar.xz firefox-esr-6d5b6d03595796fac6d0aec608e985aa620354ff.zip |
Adding debian version 115.8.0esr-1.debian/115.8.0esr-1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/import-tar.py')
-rwxr-xr-x | debian/import-tar.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/debian/import-tar.py b/debian/import-tar.py new file mode 100755 index 0000000000..d188624b14 --- /dev/null +++ b/debian/import-tar.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 + +import glob +import tarfile +import sys +from optparse import OptionParser +import os + +class GitImportTar(object): + def __init__(self, filename, head): + self.mark = 1 + self.git = sys.stdout + self.files = {} + self.name = filename + self.mtime = 0 + self.head = head + + def addfile(self, info, prefix = '', file = None): + if info.isdir(): + return + self.git.write("blob\n" + + "mark :%d\n" % self.mark) + mode = info.mode + if info.issym(): + self.git.write("data %d\n" % len(info.linkname) + + info.linkname) + mode = 0o120000 + elif file: + self.git.write("data %d\n" % (info.size)) + self.git.flush() + self.git.buffer.write(file.read(info.size)) + + self.git.write("\n") + if not prefix in self.files: + self.files[prefix] = {} + self.files[prefix][info.name] = (self.mark, mode) + self.mark += 1 + if info.mtime > self.mtime: + self.mtime = info.mtime + + def close(self): + self.git.write("commit refs/heads/%s\n" % (self.head) + + "author T Ar Creator' <tar@example.com> %d +0000\n" % (self.mtime) + + "committer T Ar Creator' <tar@example.com> %d +0000\n" % (self.mtime) + + "data <<EOM\n" + + "Imported from %s\n" % (self.name) + + "EOM\n\n" + + "from refs/heads/%s^0\n" % (self.head) + + "deleteall\n") + for prefix, fileset in self.files.items(): + basedir = os.path.commonprefix(list(fileset.keys())) + for path, info in fileset.items(): + (mark, mode) = info + if mode != 0o120000: + mode = 0o755 if (mode & 0o111) else 0o644 + path = path[len(basedir):].lstrip('/') + if prefix != '': + path = prefix + '/' + path + self.git.write("M %o :%d %s\n" % (mode, mark, path)) + +def main(): + parser = OptionParser() + parser.add_option("-H", "--head", dest="head", + help="import on the given head", metavar="NAME") + (options, args) = parser.parse_args() + + if not options.head: + options.head = "upstream" + + (name, ext) = os.path.splitext(args[0]) + if ext[0:2] != '.t': + (name, ext) = os.path.splitext(name) + + git_import = GitImportTar(os.path.basename(args[0]), options.head) + for file in [args[0]] + glob.glob(name + "-*" + ext + "*"): + (_, this_ext) = os.path.splitext(file) + if this_ext == ext: + prefix = file[len(name)+1:-len(this_ext)] + else: + prefix = file[len(name)+1:-len(this_ext) - len(ext)] + tar = tarfile.open(file, "r:*") + + while True: + info = tar.next() + if not info: + break + if info.isfile(): + file = tar.extractfile(info) + git_import.addfile(info, prefix, file) + else: + git_import.addfile(info, prefix) + + tar.close() + git_import.close() + +if __name__ == '__main__': + main() |