{"thread":{"id":"33761","subject":"Misusing git: trimming old commits","startedAt":"2013-05-09T15:40:44Z","lastAt":"2013-05-11T16:56:54Z","messageCount":2,"participants":["Martin Langhoff"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"216773","messageId":"CACPiFC+XKVzNk2fm4beer0xD6yBnVW6QXCrSFm2w8T2r68xGvg@mail.gmail.com","threadId":"33761","inReplyTo":null,"subject":"Misusing git: trimming old commits","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2013-05-09T15:40:44Z","receivedAt":"2013-05-09T15:40:44Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"I am misusing git as a store-and-forward tool to transfer reports to a\nserver in a resilient manner.\n\nThe context is puppet (and ppg, I've spammed the list about it... ).\nThe reports are small, with small deltas, but created frequently.\n\nWith the exaction of the final destination, I want to expire reports\nthat are old and successfully transferred.\n\nMy current approach is (bash-y pseudocode):\n\n  git push bla bla || exit $?\n  prunehash=$(git log -n1 --until=one.month.ago --pretty=format:%H)\n  test -z \"$prunehash\" && exit 0\n  # prep empty commit\n  # skip git read-tree --empty, we get the same with\n  export GIT_INDEX_FILE=/does/not/exist\n  empty_tree=\"$(git write-tree)\"\n  unset GIT_INDEX_FILE\n  empty_commit=\"$(git commit-tree -m empty \"$empty_tree\")\"\n  echo \"${prunehash} ${empty_commit}\" >> .git/info/grafts\n  git gc\n  # TODO: cleanup stale grafts :-)\n\nis this a reasonable approach?\n\n\n\nm\n--\n martin.langhoff@gmail.com\n -  ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n ~ http://docs.moodle.org/en/User:Martin_Langhoff\n"},{"id":"217027","messageId":"CACPiFCK3b2Ohr1rNSkxa2LFwVOo+w+NQ6D6AXwwHifQo_Lcp_g@mail.gmail.com","threadId":"33761","inReplyTo":"CACPiFC+XKVzNk2fm4beer0xD6yBnVW6QXCrSFm2w8T2r68xGvg@mail.gmail.com","subject":"Re: Misusing git: trimming old commits","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2013-05-11T16:56:54Z","receivedAt":"2013-05-11T16:56:54Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On Thu, May 9, 2013 at 11:40 AM, Martin Langhoff\n<martin.langhoff@gmail.com> wrote:\n> With the exaction of the final destination, I want to expire reports\n> that are old and successfully transferred.\n\nOK, that took some effort to make work. Make sure you are not using\nreflogs (or that reflogs are promptly expired).\n\n# right after a successful push of all heads to the receiving server...\nfor head in $(git branch|sed 's/^..//'); do\n    # FIXME period\n    graft_sha1=$(git log --until=one.month.ago -n1 --pretty=format:%H ${head})\n    if [[ -z \"$graft_sha1\" ]]; then\n        # nothing to prune\n        continue\n    fi\n    # is it already grafted?\n    if grep -q \"^${graft_sha1} \" \"${GIT_DIR}/info/grafts\" &>/dev/null ; then\n        # don't duplicate the graft\n        continue\n    fi\n    some_grafted='true'\n    # prep empty commit\n    # skip git read-tree --empty, we get the same with\n    export GIT_INDEX_FILE=/tmp/ppg-emptytree.$$\n    empty_tree=\"$(git write-tree)\"\n    rm ${GIT_INDEX_FILE}\n    unset GIT_INDEX_FILE\n    empty_commit=$(git commit-tree -m empty ${empty_tree})\n    echo \"${graft_sha1} ${empty_commit}\" >> ${GIT_DIR}/info/grafts\ndone\n\nif [[ -z \"$some_grafted\" ]]; then\n    # nothing to do\n    exit 0\nfi\n\n# ppg-repack makes the unreachable objects \"loose\"\n# (it is git-repack hacked to remove --keep-true-parents),\n# git prune --expire actually deletes them\n$PPG_EXEC_PATH/ppg-repack -AFfd\ngit prune --expire=now\n\n### Cleanup stale grafts\n# current grafts points are reachable,\n# pruned graft points (made obsolete by a newer graft)\n# cannot be retrieved and git cat-file exit code is 128\ntouch ${GIT_DIR}/info/grafts.tmp.$$\nwhile read line; do\n    graftpoint=$(echo \"${line}\" | cut -d' ' -f1)\n    if git cat-file commit ${graftpoint} &>/dev/null ; then\n        echo ${line} >> ${GIT_DIR}/info/grafts.tmp.$$\n    fi\ndone < \"${GIT_DIR}/info/grafts\"\n\nif [ -s ${GIT_DIR}/info/grafts.tmp.$$ ]; then\n    mv ${GIT_DIR}/info/grafts.tmp.$$ ${GIT_DIR}/info/grafts\nfi\n\nPerhaps it helps someone else trying to run git as a spooler :-)\n\ncheers,\n\n\n\nm\n--\n martin.langhoff@gmail.com\n -  ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n ~ http://docs.moodle.org/en/User:Martin_Langhoff\n"}]}