git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* File archiver using git
@ 2006-08-27 13:10 Matt McCutchen
  2006-08-27 13:31 ` Grzegorz Kulewski
  0 siblings, 1 reply; 4+ messages in thread
From: Matt McCutchen @ 2006-08-27 13:10 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

Dear git people,

You might like the two attached scripts that I wrote around git to
pack file trees containing lots of redundancy into very small
packages.  For example, if I have ten slightly different versions of a
piece of software because I didn't use version control, I can use
gitar to compress them together.

Matt

[-- Attachment #2: gitar --]
[-- Type: application/octet-stream, Size: 1683 bytes --]

#!/bin/bash
# usage: gitar foo-dir >foo.gitar

set -e
trap 'echo "Unexpected error!
I am leaving the .git subdirectory around so you can troubleshoot;
delete the subdirectory before trying to gitar again." 1>&2' ERR
cd "$1"

if [ -e '.git' ]; then
	echo 'The source directory is already a git repository!' 1>&2
	exit 1
fi

if ! find . -type d -empty | cmp /dev/null - >/dev/null; then
	echo 'WARNING: The source directory contains empty directories, and git will drop them.' 1>&2
fi

# Make repository.
git-init-db >/dev/null

# Make a dummy commit to hold all the files.
function list-files-to-add {
	find . -wholename './.git' -prune -or '(' -type f -or -type l ')' -printf '%P\n'
}
list-files-to-add | git-update-index --add --stdin >/dev/null
tree=$(git-write-tree)
function clean-commit {
	GIT_AUTHOR_NAME='reproducible' GIT_AUTHOR_EMAIL='' GIT_AUTHOR_DATE='946684801 +0000' GIT_COMMITTER_NAME='reproducible' GIT_COMMITTER_EMAIL='' GIT_COMMITTER_DATE='946684801 +0000' git-commit-tree "$@" </dev/null
}
clean-commit $tree >.git/refs/heads/master

# Pack things up nicely.
git-repack -a >/dev/null
for i in pack idx; do
	mv .git/objects/pack/{pack*.$i,pack.$i}
done
git-prune >/dev/null

# Write out git repository as a Matt-style file tree.
function write_file {
	echo -n "+ ${#2} $2 "
	stat --format=$'f %s' -- "$1/$2"
	cat -- "$1/$2"
	echo
}
echo '{'
	echo '+ 4 HEAD f 23'
	echo 'ref: refs/heads/master'
	echo
	echo '+ 4 refs {'
		echo '+ 5 heads {'
			write_file .git/refs/heads master
		echo '}'
	echo '}'
	echo '+ 7 objects {'
		echo '+ 4 pack {'
			write_file .git/objects/pack pack.pack
			write_file .git/objects/pack pack.idx
		echo '}'
	echo '}'
echo '}'

rm -rf .git

[-- Attachment #3: ungitar --]
[-- Type: application/octet-stream, Size: 334 bytes --]

#!/bin/bash
# usage: ungitar foo-dir <foo.gitar

set -e
trap "echo 'Unexpected error!' 1>&2" ERR
if ! [ -e "$1" ]; then
	mkdir "$1"
fi
cd "$1"

if [ -e '.git' ]; then
	echo 'The destination directory is already a git repository!' 1>&2
	exit 1
fi
trap "rm -rf .git" EXIT

ftx .git
git-read-tree master
git-checkout-index --all --force

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

end of thread, other threads:[~2006-08-28  0:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-27 13:10 File archiver using git Matt McCutchen
2006-08-27 13:31 ` Grzegorz Kulewski
2006-08-27 15:34   ` Jakub Narebski
2006-08-28  0:40   ` Matt McCutchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).