App-SnerpVortex

 view release on metacpan or  search on metacpan

lib/SVN/Dump/Replayer/Git.pm  view on Meta::CPAN

	$self->directories_needing_add()->{$dst_path} = 1;
	$self->pop_dir();
}

sub on_directory_creation {
	my ($self, $change, $revision) = @_;
	$self->push_dir($self->replay_base());
	$self->set_branch($revision, $change->entity_type(), $change->entity_name());
	$self->do_mkdir($change->rel_path());
	$self->pop_dir();
}

sub on_directory_deletion {
	my ($self, $change, $revision) = @_;

	# TODO - Doesn't need a commit if $rel_path is a directory that
	# contains no files.
	#   1. find $rel_path -type f
	#   2. If anything comes up, then we need a commit.
	#   3. Otherwise, we don't need one on account of this.

	# First try git rm, to remove from the repository.
	$self->push_dir($self->replay_base());
	$self->set_branch($revision, $change->entity_type(), $change->entity_name());

	my $rm_path = $change->rel_path();
	confess "can't remove nonexistent directory $rm_path" unless -e $rm_path;

	$self->git_env_setup($revision);

	$self->do_sans_die(
		"git", "rm", "-r", "--ignore-unmatch", "-f", "-q", "--",
		$rm_path,
	);

	# Second, try a plain filesystem remove in case the file hasn't yet
	# been staged.  Since git-rm may have removed any number of parent
	# directories for $rel_path, we only try to rmtree() if it still
	# exists.

	$self->do_rmdir($rm_path) if -e $rm_path;

	# Git cleans up directories; svn assumes they exist.
	$self->ensure_parent_dir_exists($rm_path);

	delete $self->directories_needing_add()->{$rm_path};
	$self->needs_commit(1);

	$self->pop_dir();
}

sub on_branch_directory_deletion {
	my ($self, $change, $revision) = @_;

	$self->push_dir($self->replay_base());

	my $branch_to_delete = $change->entity_name();

	# Get off the branch if we're deleting the one we're on.
	if ($branch_to_delete eq $self->current_branch()) {
		my $escape_dir_info = $self->arborist()->get_dir_analysis_info(
			$revision->id(),
			""
		);

		$self->set_branch(
			$revision,
			$escape_dir_info->ent_type(),
			$escape_dir_info->ent_name(),
		);
	}

	$self->git_env_setup($revision);
	$self->do_or_die("git", "branch", "-D", $change->entity_name());
	$self->pop_dir();
}

sub on_file_change {
	my ($self, $change, $revision) = @_;
	$self->push_dir($self->replay_base());
	$self->set_branch($revision, $change->entity_type(), $change->entity_name());
	my $rewrite_path = $change->rel_path();

	if ($self->rewrite_file($change, $rewrite_path)) {
		$self->files_needing_add()->{$rewrite_path} = 1;
	}
	$self->pop_dir();
}

sub on_file_copy {
	my ($self, $change, $revision) = @_;
	$self->push_dir($self->replay_base());
	$self->set_branch($revision, $change->entity_type(), $change->entity_name());

	my $dst_path = $change->rel_path();

	$self->do_file_copy($change, $revision);
	$self->files_needing_add()->{$dst_path} = 1;
	$self->pop_dir();
}

sub on_file_creation {
	my ($self, $change, $revision) = @_;
	$self->push_dir($self->replay_base());
	$self->set_branch($revision, $change->entity_type(), $change->entity_name());
	my $create_path = $change->rel_path();

	$self->write_new_file($change, $create_path);
	$self->files_needing_add()->{$create_path} = 1;
	$self->pop_dir();
}

sub on_file_deletion {
	my ($self, $change, $revision) = @_;

	$self->push_dir($self->replay_base());
	$self->set_branch($revision, $change->entity_type(), $change->entity_name());

	my $rm_path = $change->rel_path();
	confess "can't remove nonexistent file $rm_path" unless -e $rm_path;

	$self->git_env_setup($revision);

	$self->do_sans_die(
		"git", "rm", "-r", "--ignore-unmatch", "-f", "-q", "--",
		$rm_path,
	);

	# git-rm doesn't always remove the files right away.



( run in 1.297 second using v1.01-cache-2.11-cpan-39bf76dae61 )