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

* Re: File archiver using git
  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
  0 siblings, 2 replies; 4+ messages in thread
From: Grzegorz Kulewski @ 2006-08-27 13:31 UTC (permalink / raw)
  To: Matt McCutchen; +Cc: git

On Sun, 27 Aug 2006, Matt McCutchen wrote:
> 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.

Does it (and GIT in general) work ok with file permisions, ownership, soft 
and hard links, named sockets, device files and similar "strange" 
filesystem objects? Do I need any options to GIT to make it work with 
them?

Can I for example securely backup or even version-control /etc directory?


Grzegorz Kulewski

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

* Re: File archiver using git
  2006-08-27 13:31 ` Grzegorz Kulewski
@ 2006-08-27 15:34   ` Jakub Narebski
  2006-08-28  0:40   ` Matt McCutchen
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Narebski @ 2006-08-27 15:34 UTC (permalink / raw)
  To: git

Grzegorz Kulewski wrote:

> On Sun, 27 Aug 2006, Matt McCutchen wrote:
>> 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.
> 
> Does it (and GIT in general) work ok with file permisions, ownership, soft 
> and hard links, named sockets, device files and similar "strange" 
> filesystem objects? Do I need any options to GIT to make it work with 
> them?

Git in general only preserves executable bit, deals with symlinks,
hardlinks after a fashion (stored once, but unpacked/checked out as separate
files, not hardlinked), and does not deal with other "strange" filesystem
objects as far as I know.

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

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

* Re: File archiver using git
  2006-08-27 13:31 ` Grzegorz Kulewski
  2006-08-27 15:34   ` Jakub Narebski
@ 2006-08-28  0:40   ` Matt McCutchen
  1 sibling, 0 replies; 4+ messages in thread
From: Matt McCutchen @ 2006-08-28  0:40 UTC (permalink / raw)
  To: Grzegorz Kulewski; +Cc: git

On 8/27/06, Grzegorz Kulewski <kangur@polcom.net> wrote:
> Does it (and GIT in general) work ok with file permisions, ownership, soft
> and hard links, named sockets, device files and similar "strange"
> filesystem objects? Do I need any options to GIT to make it work with
> them?

Git tracks data, not filesystems.  That means it doesn't handle any of
the things you mentioned except soft links.  It doesn't even handle
empty directories, though I don't accept the argument that they do not
constitute data.  If you want to capture a filesystem, I would
recommend running "find . -ls" to create a listing file from which
everything you mentioned can be reconstructed and then putting the
filesystem together with the listing file into git.

> Can I for example securely backup or even version-control /etc directory?

With the above technique, you can do both.  However, if you just want
to back up /etc, you might be better served by a backup tool.  For
example, I use rsnapshot ( http://www.rsnapshot.org/ ).

Matt

^ 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).