All of lore.kernel.org
 help / color / mirror / Atom feed
* Misusing git: trimming old commits
@ 2013-05-09 15:40 Martin Langhoff
  2013-05-11 16:56 ` Martin Langhoff
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Langhoff @ 2013-05-09 15:40 UTC (permalink / raw)
  To: Git Mailing List

I am misusing git as a store-and-forward tool to transfer reports to a
server in a resilient manner.

The context is puppet (and ppg, I've spammed the list about it... ).
The reports are small, with small deltas, but created frequently.

With the exaction of the final destination, I want to expire reports
that are old and successfully transferred.

My current approach is (bash-y pseudocode):

  git push bla bla || exit $?
  prunehash=$(git log -n1 --until=one.month.ago --pretty=format:%H)
  test -z "$prunehash" && exit 0
  # prep empty commit
  # skip git read-tree --empty, we get the same with
  export GIT_INDEX_FILE=/does/not/exist
  empty_tree="$(git write-tree)"
  unset GIT_INDEX_FILE
  empty_commit="$(git commit-tree -m empty "$empty_tree")"
  echo "${prunehash} ${empty_commit}" >> .git/info/grafts
  git gc
  # TODO: cleanup stale grafts :-)

is this a reasonable approach?



m
--
 martin.langhoff@gmail.com
 -  ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 ~ http://docs.moodle.org/en/User:Martin_Langhoff

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Misusing git: trimming old commits
  2013-05-09 15:40 Misusing git: trimming old commits Martin Langhoff
@ 2013-05-11 16:56 ` Martin Langhoff
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Langhoff @ 2013-05-11 16:56 UTC (permalink / raw)
  To: Git Mailing List

On Thu, May 9, 2013 at 11:40 AM, Martin Langhoff
<martin.langhoff@gmail.com> wrote:
> With the exaction of the final destination, I want to expire reports
> that are old and successfully transferred.

OK, that took some effort to make work. Make sure you are not using
reflogs (or that reflogs are promptly expired).

# right after a successful push of all heads to the receiving server...
for head in $(git branch|sed 's/^..//'); do
    # FIXME period
    graft_sha1=$(git log --until=one.month.ago -n1 --pretty=format:%H ${head})
    if [[ -z "$graft_sha1" ]]; then
        # nothing to prune
        continue
    fi
    # is it already grafted?
    if grep -q "^${graft_sha1} " "${GIT_DIR}/info/grafts" &>/dev/null ; then
        # don't duplicate the graft
        continue
    fi
    some_grafted='true'
    # prep empty commit
    # skip git read-tree --empty, we get the same with
    export GIT_INDEX_FILE=/tmp/ppg-emptytree.$$
    empty_tree="$(git write-tree)"
    rm ${GIT_INDEX_FILE}
    unset GIT_INDEX_FILE
    empty_commit=$(git commit-tree -m empty ${empty_tree})
    echo "${graft_sha1} ${empty_commit}" >> ${GIT_DIR}/info/grafts
done

if [[ -z "$some_grafted" ]]; then
    # nothing to do
    exit 0
fi

# ppg-repack makes the unreachable objects "loose"
# (it is git-repack hacked to remove --keep-true-parents),
# git prune --expire actually deletes them
$PPG_EXEC_PATH/ppg-repack -AFfd
git prune --expire=now

### Cleanup stale grafts
# current grafts points are reachable,
# pruned graft points (made obsolete by a newer graft)
# cannot be retrieved and git cat-file exit code is 128
touch ${GIT_DIR}/info/grafts.tmp.$$
while read line; do
    graftpoint=$(echo "${line}" | cut -d' ' -f1)
    if git cat-file commit ${graftpoint} &>/dev/null ; then
        echo ${line} >> ${GIT_DIR}/info/grafts.tmp.$$
    fi
done < "${GIT_DIR}/info/grafts"

if [ -s ${GIT_DIR}/info/grafts.tmp.$$ ]; then
    mv ${GIT_DIR}/info/grafts.tmp.$$ ${GIT_DIR}/info/grafts
fi

Perhaps it helps someone else trying to run git as a spooler :-)

cheers,



m
--
 martin.langhoff@gmail.com
 -  ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 ~ http://docs.moodle.org/en/User:Martin_Langhoff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-05-11 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-09 15:40 Misusing git: trimming old commits Martin Langhoff
2013-05-11 16:56 ` Martin Langhoff

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.