App-SnerpVortex

 view release on metacpan or  search on metacpan

bin/snerp-projector  view on Meta::CPAN

}

# Convert a branch to an annotated tag.
# The tag's header information will be identical to the branch's.
# The branch will be deleted after tagging.

sub convert_branch_to_tag {
	my ($git, $branch, $rev_to_tag) = @_;

	# Temporarily remove the tag, if it exists.
	$git->run("tag", "-d", $branch);

	# git cat-file parsing brought to you by
	# http://github.com/book/git-gadgets/blob/master/git-copytag
	my %info;

	# get tag content
	@info{qw( header body )} = split /\n\n/, $git->run(
		'cat-file', 'commit', $branch
	), 2;

	# parse header
	%info = ( %info, map { ( split / /, $_, 2 ) } split /\n/, $info{header} );
	$info{author} =~ /^(.*?)\s+<([^>]*)>\s+(.*?)\s*$/;
	@info{qw( author_name author_email author_date )} = ( $1, $2, $3 );
	$info{committer} =~ /^(.*?)\s+<([^>]*)>\s+(.*?)\s*$/;
	@info{qw( committer_name committer_email committer_date )} = (
		$1, $2, $3
	);

	my %env;
	if (exists $info{committer}) {
		$env{GIT_COMMITTER_EMAIL} = $info{author_email};
		$env{GIT_COMMITTER_NAME}  = $info{author_name};
		$env{GIT_COMMITTER_DATE}  = $info{author_date};
	}

	if (exists $info{author}) {
		$env{GIT_AUTHOR_EMAIL}    = $info{author_email};
		$env{GIT_AUTHOR_NAME}     = $info{author_name};
		$env{GIT_AUTHOR_DATE}     = $info{author_date};
	}

	my $annotation = $info{body};
	$annotation =~ s/'/\\'/g;

	$git->run(
		"tag", "-a",
		"-m", $annotation,
		$branch, $rev_to_tag,
		{ env => \%env },

	);

	$git->run("branch", "-D", $branch);
}

sub purge_project {
	my $project = shift;

	_log("Purging backups from $project->{git_base_dir}...");

	system(
		"/bin/rm", "-r", "-f",
		"$project->{git_base_dir}/.git/refs/original",
		"$project->{git_base_dir}/.git/refs/logs/",
	) and die $!;

	_log("Expiring reflog entries from $project->{git_base_dir}...");
	$project->{git}->run("reflog", "expire", "--all");

	_log("Garbage collecting $project->{git_base_dir}...");
	$project->{git}->run("gc", "--aggressive", "--prune");

	_log("Checking $project->{git_base_dir}...");
	$project->{git}->run("fsck", "--full", "--strict");
}

sub _log {
	return unless $verbose;

	my $message = join "", @_;
	my $now = time();

	printf "%-6d %-6d %s\n", ($now - $^T), ($now - $last_log_time), $message;
	$last_log_time = $now;
}

__END__

=head1 NAME

snerp-projector - break a Git repository into projects

=head1 SYNOPSIS

	snerp-projector \
		--map paths-to-projects.txt \
		--db snanalyze-index.sqlite3 \
		--from monolithic-git-working-dir \
		--into new-parent-dir

=head1 DESCRIPTION

snerp-projector identifies and breaks up a monolithic Git repository
into separate, smaller repositories for each subproject.

The original monolithic git repository (--from) is cloned for each
anticipated subrpoject (listed in --map).  The subproject clones are
placed into a new parent directory (--into).

Subprojects are described in a YAML file, which contains a hash of
hashes:

	project:
		gitdir: project/dir
		svndir: trunk/project/dir

For example:

	poe-loop-gtk:



( run in 0.988 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )