{"thread":{"id":"24906","subject":"git-import-tarball","startedAt":"2010-08-30T06:34:21Z","lastAt":"2010-08-30T13:49:22Z","messageCount":2,"participants":["Enrico Weigelt","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"149284","messageId":"20100830063421.GA797@nibiru.local","threadId":"24906","inReplyTo":null,"subject":"git-import-tarball","fromName":"Enrico Weigelt","fromEmail":"weigelt@metux.de","sentAt":"2010-08-30T06:34:21Z","receivedAt":"2010-08-30T06:34:21Z","isPatch":false,"sender":{"key":"weigelt@metux.de","avatar":null},"body":"\nHi folks,\n\n\nI'm currently working on an automatic import mechanism for \nvarious upstreams into repositories of the oss-qm project [1]\nand written a little shellscript which imports an existing\ntarball as new commit into a git repo.\n\nMaybe someone finds it useful ;-)\n(see attachement)\n\ncu\n[1] https://sourceforge.net/p/oss-qm/home/\n-- \n----------------------------------------------------------------------\n Enrico Weigelt, metux IT service -- http://www.metux.de/\n\n phone:  +49 36207 519931  email: weigelt@metux.de\n mobile: +49 151 27565287  icq:   210169427         skype: nekrad666\n----------------------------------------------------------------------\n Embedded-Linux / Portierung / Opensource-QM / Verteilte Systeme\n----------------------------------------------------------------------\n\n\n#!/bin/bash\n\nhelp() {\n    echo \"git-import-tarball <args>\"\n    echo \"\"\n    echo \"Imports an tarball into an existing repository, ontop of given parent commit\"\n    echo \"\"\n    echo \"    --repository=<repository>   Git repository\"\n    echo \"    --tarball=<tarball>         Name of the tarball file\"\n    echo \"    --parent=<parent-ref>       Parent commit to base on\"\n    echo \"    --tag=<tag-name>            Name for the tag to create\"\n    echo \"    --strip-components=<number> String <number> of pathname components before decompression\"\n    echo \"\"\n    echo \"Exit codes:   1    Generic error\"\n    echo \"              2    Syntax error\"\n    echo \"\"\n}\n\ndie() {\n    echo \"$0: $*\"\n    exit 1\n}\n\ndiehelp() {\n    echo \"$0: $*\"\n    echo \"\"\n    help\n    exit 2\n}\n\ncallgit() {\n    if git --work-tree=${temp_workdir} --git-dir=${param_repository} \"$@\" ; then\n\treturn 0\n    else\n\treturn 1\n    fi\n}\n\nclean_workdir() {\n    rm -Rf \"${temp_workdir}\"   || die \"cannot remove workdir: \\\"${temp_workdir}\\\"\"\n    mkdir -p \"${temp_workdir}\" || die \"cannot create workdir: \\\"${temp_workdir}\\\"\"\n    return 0\n}\n\n## command line parsing\nwhile [ \"$1\" ]; do\n    case \"$1\" in\n\t--repository=*)\n\t    param_repository=\"${1##--repository=}\"\n\t;;\n\t--tarball=*)\n\t    param_tarball=\"${1##--tarball=}\"\n\t;;\n\t--parent=*)\n\t    param_parent=\"${1##--parent=}\"\n\t;;\n\t--root-commit)\n\t    param_root_commit=1\n\t;;\n\t--tag=*)\n\t    param_tag=\"${1##--tag=}\"\n\t;;\n\t--strip-components=*)\n\t    param_strip_components=\"${1##--strip-components=}\"\n\t    taropt_strip_components=\"--strip-components=${param_strip_components}\"\n\t;;\n\t*)\n\t    echo \"$0: unhandled parameter \\\"$1\\\"\"\n\t    exit 1\n\t;;\n    esac\n    shift\ndone\n\n### parameter checks\n[ \"${param_root_commit}\" ] || [ \"$param_parent\" ] || diehelp \"missing --parent or --root-commit\"\n[ \"${param_tag}\" ]                                || diehelp \"missing --tag\"\n\n### fixup repository path\ncase \"${param_repository}\" in\n    \"\")\n\tdiehelp \"missing --repository\"\n    ;;\n    ~*)\n\tparam_repository=\"${HOME}/${param_repository##\\~}/.git\"\n    ;;\n    *)\n\tparam_repository=\"${param_repository}/.git\"\n    ;;\nesac\n\n### fixup the tarball name\ncase \"${param_tarball}\" in\n    ~*)\n\tparam_tarball=\"${HOME}/${param_tarball##\\~}\"\n    ;;\n    *)\nesac\n\n### find out which uncompress command to use\ncase \"${param_tarball}\" in\n    *.tar.bz2|*.tbz2)\n\tuncompress_cmd=\"tar -x -j    -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar.gz|*.tgz)\n\tuncompress_cmd=\"tar -x -z    -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar)\n\tuncompress_cmd=\"tar -x -z    -f  ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar.Z|*.tZ)\n\tuncompress_cmd=\"tar -x -Z    -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar.lzma)\n\tuncompress_cmd=\"tar -x -lzma -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar.xz)\n\tuncompress_cmd=\"tar -x -xz   -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar.lzip)\n\tuncompress_cmd=\"tar -x -lzip -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    *.tar.lzop)\n\tuncompress_cmd=\"tar -x -lzop -f ${param_tarball} ${taropt_strip_components}\"\n    ;;\n    \"\")\n\tdiehelp \"missing --tarball option\"\n    ;;\n    *)\n\tdiehelp \"unsupported tarball format: \\\"${param_tarball}\\\"\"\n    ;;\nesac\n__tarball_basename=`basename \"${parameter_tarball}\"`\n\n\n### render temporary branch name, temporary workdir, etc\ntemp_branch=`date \"+__import_tarball_tmp-%Y-%m-%d-%H-%M-%S\"`\ntemp_workdir=`mktemp`\n\n### create temporary working dir\nclean_workdir\n\n### store the previous HEAD pointer\nlast_head=`callgit symbolic-ref HEAD`\n\n### checkout the parent ref and cleanup again\n## fixme: perhaps we should clean out old temporary branches ;-o\nif [ \"${param_root_commit}\" ]; then\n    callgit symbolic-ref HEAD \"refs/heads/$temp_branch\" || die \"git-symbolic-ref failed\"\nelse\n    callgit checkout -f \"${param_parent}\" -b \"$temp_branch\" || die \"git-checkout failed\"\nfi\nclean_workdir\n\n### now decompress the workdir\ncd ${temp_workdir} || die \"cannot chdir to ${temp_workdir}\"\n$uncompress_cmd || die \"uncompress failed: \\\"$uncompress_cmd\\\"\"\n\n### add everything in there to the index\ncallgit add -A     || die \"git add -A failed\"\n\n### commit\ncallgit commit -m \"tarball import: ${__tarball_basename}\" || die \"git-commit failed\"\n\n### tag the commit\ncallgit tag \"${param_tag}\" || die \"git-tag failed\"\n\n### final cleanup\ncallgit symbolic-ref HEAD \"$last_head\" || die \"git-symbolic-ref failed (2)\"\ncallgit branch -D \"$temp_branch\" || die \"git-branch -D for temporary branch failed\"\nclean_workdir\n\nexit 0\n"},{"id":"149317","messageId":"20100830134922.GB2315@burratino","threadId":"24906","inReplyTo":"20100830063421.GA797@nibiru.local","subject":"Re: git-import-tarball","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-30T13:49:22Z","receivedAt":"2010-08-30T13:49:22Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Enrico,\n\nEnrico Weigelt wrote:\n\n> written a little shellscript which imports an existing\n> tarball as new commit into a git repo.\n\nYou might also like contrib/fast-import/import-tars.perl. :)\n\nCheers,\nJonathan\n"}]}