@matheusbsbs / matheus-bagliano / commits / ef3cfaad19
Fork 0

git-svn: track writes writes to the index in fetch

Introducing Git::IndexInfo. This module will probably be useful outside of git-svn, so I'm not putting it in the Git::SVN namespace. This will allow me to more easily avoid the use of get_log() in the future and simply run do_update in incrementing ranges. get_log() should be avoided because there are cases where moved/deleted directories do not track correctly (until --follow-parent is run on a new branch). Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jan 24, 2007 at 03:30 UTC ef3cfaad19f2587ea4ff7d46574d9118f8d9555e
1 file changed +41 -9
git-svn.perl
+41 -9
@@ -1643,8 +1643,7 @@ sub new {
1643 $self->{file_prop} = {};
1644 $self->{absent_dir} = {};
1645 $self->{absent_file} = {};
1646 - ($self->{gui}, $self->{ctx}) = $git_svn->tmp_index_do(
1647 - sub { command_input_pipe(qw/update-index -z --index-info/) } );
1646 + $self->{gii} = $git_svn->tmp_index_do(sub { Git::IndexInfo->new });
1647 require Digest::MD5;
1648 $self;
1649 }
@@ -1671,7 +1670,6 @@ sub git_path {
1670
1671 sub delete_entry {
1672 my ($self, $path, $rev, $pb) = @_;
1674 - my $gui = $self->{gui};
1673
1674 my $gpath = $self->git_path($path);
1675 # remove entire directories.
@@ -1681,14 +1679,15 @@ sub delete_entry {
1679 $self->{c}, '--', $gpath);
1680 local $/ = "\0";
1681 while (<$ls>) {
1684 - print $gui '0 ',0 x 40,"\t",$_ or croak $!;
1682 + chomp;
1683 + $self->{gii}->remove($_);
1684 print "\tD\t$_\n" unless $self->{q};
1685 }
1686 print "\tD\t$gpath/\n" unless $self->{q};
1687 command_close_pipe($ls, $ctx);
1688 $self->{empty}->{$path} = 0
1689 } else {
1691 - print $gui '0 ',0 x 40,"\t",$gpath,"\0" or croak $!;
1690 + $self->{gii}->remove($gpath);
1691 print "\tD\t$gpath\n" unless $self->{q};
1692 }
1693 undef;
@@ -1824,22 +1823,23 @@ sub close_file {
1823 $hash = $fb->{blob} or die "no blob information\n";
1824 }
1825 $fb->{pool}->clear;
1827 - my $gui = $self->{gui};
1828 - print $gui "$fb->{mode_b} $hash\t$path\0" or croak $!;
1826 + $self->{gii}->update($fb->{mode_b}, $hash, $path) or croak $!;
1827 print "\t$fb->{action}\t$path\n" if $fb->{action} && ! $self->{q};
1828 undef;
1829 }
1830
1831 sub abort_edit {
1832 my $self = shift;
1835 - eval { command_close_pipe($self->{gui}, $self->{ctx}) };
1833 + $self->{nr} = $self->{gii}->{nr};
1834 + delete $self->{gii};
1835 $self->SUPER::abort_edit(@_);
1836 }
1837
1838 sub close_edit {
1839 my $self = shift;
1841 - command_close_pipe($self->{gui}, $self->{ctx});
1840 $self->{git_commit_ok} = 1;
1841 + $self->{nr} = $self->{gii}->{nr};
1842 + delete $self->{gii};
1843 $self->SUPER::close_edit(@_);
1844 }
1845
@@ -2832,6 +2832,38 @@ sub migration_check {
2832 minimize_connections() if $_minimize;
2833 }
2834
2835 +package Git::IndexInfo;
2836 +use strict;
2837 +use warnings;
2838 +use Git qw/command_input_pipe command_close_pipe/;
2839 +
2840 +sub new {
2841 + my ($class) = @_;
2842 + my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/);
2843 + bless { gui => $gui, ctx => $ctx, nr => 0}, $class;
2844 +}
2845 +
2846 +sub remove {
2847 + my ($self, $path) = @_;
2848 + if (print { $self->{gui} } '0 ', 0 x 40, "\t", $path, "\0") {
2849 + return ++$self->{nr};
2850 + }
2851 + undef;
2852 +}
2853 +
2854 +sub update {
2855 + my ($self, $mode, $hash, $path) = @_;
2856 + if (print { $self->{gui} } $mode, ' ', $hash, "\t", $path, "\0") {
2857 + return ++$self->{nr};
2858 + }
2859 + undef;
2860 +}
2861 +
2862 +sub DESTROY {
2863 + my ($self) = @_;
2864 + command_close_pipe($self->{gui}, $self->{ctx});
2865 +}
2866 +
2867 __END__
2868
2869 Data structures: