* [PATCH 13/13] git-svn: make the $GIT_DIR/svn/*/revs directory obsolete
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
This is a very intrusive change, so I've beefed up the tests
significantly. Added 'full-test' a target to the Makefile,
to test different possible configurations. This is intended
for maintainers only. Users should only be concerned with
'test' succeeding.
We now have a very simple custom database format for handling
mapping of svn revisions => git commits. Of course, we're
not really using it yet, either.
Also disabled automatic branch-finding on new trees for now.
It's too easily broken. revisions_eq() function should be
helpful for branch detection.
Also removed an extra assertion in fetch_cmd() that wasn't
correctly done. This bug was found by full-test.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/Makefile | 12 +
contrib/git-svn/git-svn.perl | 245 ++++++++++++++--------
contrib/git-svn/t/t0000-contrib-git-svn.sh | 13 +
contrib/git-svn/t/t0001-contrib-git-svn-props.sh | 86 ++++----
4 files changed, 224 insertions(+), 132 deletions(-)
diff --git a/contrib/git-svn/Makefile b/contrib/git-svn/Makefile
index 48f60b3..d73aa56 100644
--- a/contrib/git-svn/Makefile
+++ b/contrib/git-svn/Makefile
@@ -29,8 +29,16 @@ git-svn.html : git-svn.txt
asciidoc -b xhtml11 -d manpage \
-f ../../Documentation/asciidoc.conf $<
test: git-svn
- cd t && $(SHELL) ./t0000-contrib-git-svn.sh
- cd t && $(SHELL) ./t0001-contrib-git-svn-props.sh
+ cd t && $(SHELL) ./t0000-contrib-git-svn.sh $(TEST_FLAGS)
+ cd t && $(SHELL) ./t0001-contrib-git-svn-props.sh $(TEST_FLAGS)
+
+full-test:
+ $(MAKE) test GIT_SVN_NO_LIB=1 GIT_SVN_NO_OPTIMIZE_COMMITS=1
+ $(MAKE) test GIT_SVN_NO_LIB=0 GIT_SVN_NO_OPTIMIZE_COMMITS=1
+ $(MAKE) test GIT_SVN_NO_LIB=1 GIT_SVN_NO_OPTIMIZE_COMMITS=0 \
+ LC_ALL=en_US.UTF-8
+ $(MAKE) test GIT_SVN_NO_LIB=0 GIT_SVN_NO_OPTIMIZE_COMMITS=0 \
+ LC_ALL=en_US.UTF-8
clean:
rm -f git-svn *.xml *.html *.1
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index 9618c8b..884969e 100755
--- a/contrib/git-svn/git-svn.perl
+++ b/contrib/git-svn/git-svn.perl
@@ -6,9 +6,9 @@ use strict;
use vars qw/ $AUTHOR $VERSION
$SVN_URL $SVN_INFO $SVN_WC $SVN_UUID
$GIT_SVN_INDEX $GIT_SVN
- $GIT_DIR $REV_DIR $GIT_SVN_DIR/;
+ $GIT_DIR $GIT_SVN_DIR $REVDB/;
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
-$VERSION = '1.1.0-pre';
+$VERSION = '1.1.1-broken';
use Cwd qw/abs_path/;
$GIT_DIR = abs_path($ENV{GIT_DIR} || '.git');
@@ -31,10 +31,13 @@ use File::Path qw/mkpath/;
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
use File::Spec qw//;
use POSIX qw/strftime/;
+use Memoize;
+memoize('revisions_eq');
my ($SVN_PATH, $SVN, $SVN_LOG, $_use_lib);
$_use_lib = 1 unless $ENV{GIT_SVN_NO_LIB};
libsvn_load();
+my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS};
my $sha1 = qr/[a-f\d]{40}/;
my $sha1_short = qr/[a-f\d]{4,40}/;
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
@@ -43,7 +46,7 @@ my ($_revision,$_stdin,$_no_ignore_ext,$
$_template, $_shared, $_no_default_regex, $_no_graft_copy,
$_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
$_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m);
-my (@_branch_from, %tree_map, %users, %rusers);
+my (@_branch_from, %tree_map, %users, %rusers, %equiv);
my ($_svn_co_url_revs, $_svn_pg_peg_revs);
my @repo_path_split_cache;
@@ -201,7 +204,6 @@ sub rebuild {
next if (defined $SVN_UUID && ($uuid ne $SVN_UUID));
next if (defined $SVN_URL && defined $url && ($url ne $SVN_URL));
- print "r$rev = $c\n";
unless (defined $latest) {
if (!$SVN_URL && !$url) {
croak "SVN repository location required: $url\n";
@@ -211,8 +213,8 @@ sub rebuild {
setup_git_svn();
$latest = $rev;
}
- assert_revision_eq_or_unknown($rev, $c);
- sys('git-update-ref',"svn/$GIT_SVN/revs/$rev",$c);
+ revdb_set($REVDB, $rev, $c);
+ print "r$rev = $c\n";
$newest_rev = $rev if ($rev > $newest_rev);
}
close $rev_list or croak $?;
@@ -280,7 +282,11 @@ sub fetch_cmd {
my $svn_log = svn_log_raw(@log_args);
my $base = next_log_entry($svn_log) or croak "No base revision!\n";
- my $last_commit = undef;
+ # don't need last_revision from grab_base_rev() because
+ # user could've specified a different revision to skip (they
+ # didn't want to import certain revisions into git for whatever
+ # reason, so trust $base->{revision} instead.
+ my (undef, $last_commit) = svn_grab_base_rev();
unless (-d $SVN_WC) {
svn_cmd_checkout($SVN_URL,$base->{revision},$SVN_WC);
chdir $SVN_WC or croak $!;
@@ -290,7 +296,6 @@ sub fetch_cmd {
} else {
chdir $SVN_WC or croak $!;
read_uuid();
- eval { $last_commit = file_to_s("$REV_DIR/$base->{revision}") };
# looks like a user manually cp'd and svn switch'ed
unless ($last_commit) {
sys(qw/svn revert -R ./);
@@ -303,7 +308,6 @@ sub fetch_cmd {
push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
my $last = $base;
while (my $log_msg = next_log_entry($svn_log)) {
- assert_tree($last_commit);
if ($last->{revision} >= $log_msg->{revision}) {
croak "Out of order: last >= current: ",
"$last->{revision} >= $log_msg->{revision}\n";
@@ -444,14 +448,14 @@ sub commit_cmd {
}
$info = svn_info('.');
read_uuid($info);
- my $svn_current_rev = $info->{'Last Changed Rev'};
+ my $last = $fetched;
foreach my $c (@revs) {
- my $mods = svn_checkout_tree($svn_current_rev, $c);
+ my $mods = svn_checkout_tree($last, $c);
if (scalar @$mods == 0) {
print "Skipping, no changes detected\n";
next;
}
- $svn_current_rev = svn_commit_tree($svn_current_rev, $c);
+ $last = svn_commit_tree($last, $c);
}
}
@@ -500,7 +504,7 @@ sub commit_lib {
},
@lock)
);
- my $mods = libsvn_checkout_tree($r_last, $c, $ed);
+ my $mods = libsvn_checkout_tree($cmt_last, $c, $ed);
if (@$mods == 0) {
print "No changes\nr$r_last = $cmt_last\n";
$ed->abort_edit;
@@ -814,7 +818,7 @@ sub graft_file_copy_cmd {
my ($grafts, $l_map, $u) = @_;
my $paths = $l_map->{$u};
my $pfx = common_prefix([keys %$paths]);
-
+ $SVN_URL ||= $u.$pfx;
my $pid = open my $fh, '-|';
defined $pid or croak $!;
unless ($pid) {
@@ -851,6 +855,8 @@ sub graft_file_copy_lib {
my ($base, $head) = libsvn_parse_revision();
my $inc = 1000;
my ($min, $max) = ($base, $head < $base+$inc ? $head : $base+$inc);
+ my $eh = $SVN::Error::handler;
+ $SVN::Error::handler = \&libsvn_skip_unknown_revs;
while (1) {
my $pool = SVN::Pool->new;
$SVN_LOG->get_log( "/$path", $min, $max, 0, 1, 1,
@@ -864,6 +870,7 @@ sub graft_file_copy_lib {
$max += $inc;
$max = $head if ($max > $head);
}
+ $SVN::Error::handler = $eh;
}
sub process_merge_msg_matches {
@@ -994,7 +1001,8 @@ sub setup_git_svn {
}
mkpath([$GIT_SVN_DIR]);
mkpath(["$GIT_SVN_DIR/info"]);
- mkpath([$REV_DIR]);
+ open my $fh, '>>',$REVDB or croak $!;
+ close $fh;
s_to_file($SVN_URL,"$GIT_SVN_DIR/info/url");
open my $fd, '>>', "$GIT_SVN_DIR/info/exclude" or croak $!;
@@ -1201,8 +1209,7 @@ sub precommit_check {
sub get_diff {
- my ($svn_rev, $treeish) = @_;
- my $from = file_to_s("$REV_DIR/$svn_rev");
+ my ($from, $treeish) = @_;
assert_tree($from);
print "diff-tree $from $treeish\n";
my $pid = open my $diff_fh, '-|';
@@ -1222,8 +1229,8 @@ sub get_diff {
}
sub svn_checkout_tree {
- my ($svn_rev, $treeish) = @_;
- my $mods = get_diff($svn_rev, $treeish);
+ my ($from, $treeish) = @_;
+ my $mods = get_diff($from->{commit}, $treeish);
return $mods unless (scalar @$mods);
my ($rm, $add) = precommit_check($mods);
@@ -1268,8 +1275,8 @@ sub svn_checkout_tree {
}
sub libsvn_checkout_tree {
- my ($svn_rev, $treeish, $ed) = @_;
- my $mods = get_diff($svn_rev, $treeish);
+ my ($from, $treeish, $ed) = @_;
+ my $mods = get_diff($from, $treeish);
return $mods unless (scalar @$mods);
my %o = ( D => 1, R => 0, C => -1, A => 3, M => 3, T => 3 );
foreach my $m (sort { $o{$a->{chg}} <=> $o{$b->{chg}} } @$mods) {
@@ -1365,7 +1372,7 @@ sub get_commit_message {
}
sub svn_commit_tree {
- my ($svn_rev, $commit) = @_;
+ my ($last, $commit) = @_;
my $commit_msg = "$GIT_SVN_DIR/.svn-commit.tmp.$$";
my $log_msg = get_commit_message($commit, $commit_msg);
my ($oneline) = ($log_msg->{msg} =~ /([^\n\r]+)/);
@@ -1392,7 +1399,7 @@ sub svn_commit_tree {
my @svn_up = qw(svn up);
push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
- if ($committed == ($svn_rev + 1)) {
+ if ($_optimize_commits && ($committed == ($last->{revision} + 1))) {
push @svn_up, "-r$committed";
sys(@svn_up);
my $info = svn_info('.');
@@ -1408,14 +1415,14 @@ sub svn_commit_tree {
$log_msg->{author} = $info->{'Last Changed Author'};
$log_msg->{revision} = $committed;
$log_msg->{msg} .= "\n";
- my $parent = file_to_s("$REV_DIR/$svn_rev");
- git_commit($log_msg, $parent, $commit);
- return $committed;
+ $log_msg->{parents} = [ $last->{commit} ];
+ $log_msg->{commit} = git_commit($log_msg, $commit);
+ return $log_msg;
}
# resync immediately
- push @svn_up, "-r$svn_rev";
+ push @svn_up, "-r$last->{revision}";
sys(@svn_up);
- return fetch("$committed=$commit")->{revision};
+ return fetch("$committed=$commit");
}
sub rev_list_raw {
@@ -1671,10 +1678,9 @@ sub file_to_s {
}
sub assert_revision_unknown {
- my $revno = shift;
- if (-f "$REV_DIR/$revno") {
- croak "$REV_DIR/$revno already exists! ",
- "Why are we refetching it?";
+ my $r = shift;
+ if (my $c = revdb_get($REVDB, $r)) {
+ croak "$r = $c already exists! Why are we refetching it?";
}
}
@@ -1690,18 +1696,6 @@ sub trees_eq {
return 1;
}
-sub assert_revision_eq_or_unknown {
- my ($revno, $commit) = @_;
- if (-f "$REV_DIR/$revno") {
- my $current = file_to_s("$REV_DIR/$revno");
- if (($commit ne $current) && !trees_eq($commit, $current)) {
- croak "$REV_DIR/$revno already exists!\n",
- "current: $current\nexpected: $commit\n";
- }
- return;
- }
-}
-
sub git_commit {
my ($log_msg, @parents) = @_;
assert_revision_unknown($log_msg->{revision});
@@ -1763,19 +1757,12 @@ sub git_commit {
}
my @update_ref = ('git-update-ref',"refs/remotes/$GIT_SVN",$commit);
if (my $primary_parent = shift @exec_parents) {
- $pid = fork;
- defined $pid or croak $!;
- if (!$pid) {
- close STDERR;
- close STDOUT;
- exec 'git-rev-parse','--verify',
- "refs/remotes/$GIT_SVN^0" or croak $!;
- }
- waitpid $pid, 0;
+ quiet_run(qw/git-rev-parse --verify/,"refs/remotes/$GIT_SVN^0");
push @update_ref, $primary_parent unless $?;
}
sys(@update_ref);
- sys('git-update-ref',"svn/$GIT_SVN/revs/$log_msg->{revision}",$commit);
+ revdb_set($REVDB, $log_msg->{revision}, $commit);
+
# this output is read via pipe, do not change:
print "r$log_msg->{revision} = $commit\n";
if ($_repack && (--$_repack_nr == 0)) {
@@ -1990,7 +1977,29 @@ sub git_svn_each {
}
}
+sub migrate_revdb {
+ git_svn_each(sub {
+ my $id = shift;
+ defined(my $pid = fork) or croak $!;
+ if (!$pid) {
+ $GIT_SVN = $ENV{GIT_SVN_ID} = $id;
+ init_vars();
+ exit 0 if -r $REVDB;
+ print "Upgrading svn => git mapping...\n";
+ open my $fh, '>>',$REVDB or croak $!;
+ close $fh;
+ rebuild();
+ print "Done upgrading. You may now delete the ",
+ "deprecated $GIT_SVN_DIR/revs directory\n";
+ exit 0;
+ }
+ waitpid $pid, 0;
+ croak $? if $?;
+ });
+}
+
sub migration_check {
+ migrate_revdb() unless (-e $REVDB);
return if (-d "$GIT_DIR/svn" || !-d $GIT_DIR);
print "Upgrading repository...\n";
unless (-d "$GIT_DIR/svn") {
@@ -2013,15 +2022,19 @@ sub migration_check {
s_to_file($url, "$GIT_DIR/svn/$x/info/repo_url");
s_to_file($path, "$GIT_DIR/svn/$x/info/repo_path");
}
+ migrate_revdb() if (-d $GIT_SVN_DIR && !-w $REVDB);
print "Done upgrading.\n";
}
sub find_rev_before {
- my ($r, $git_svn_id) = @_;
- my @revs = map { basename $_ } <$GIT_DIR/svn/$git_svn_id/revs/*>;
- foreach my $r0 (sort { $b <=> $a } @revs) {
- next if $r0 >= $r;
- return ($r0, file_to_s("$GIT_DIR/svn/$git_svn_id/revs/$r0"));
+ my ($r, $id, $eq_ok) = @_;
+ my $f = "$GIT_DIR/svn/$id/.rev_db";
+ # --$r unless $eq_ok;
+ while ($r > 0) {
+ if (my $c = revdb_get($f, $r)) {
+ return ($r, $c);
+ }
+ --$r;
}
return (undef, undef);
}
@@ -2029,9 +2042,9 @@ sub find_rev_before {
sub init_vars {
$GIT_SVN ||= $ENV{GIT_SVN_ID} || 'git-svn';
$GIT_SVN_DIR = "$GIT_DIR/svn/$GIT_SVN";
+ $REVDB = "$GIT_SVN_DIR/.rev_db";
$GIT_SVN_INDEX = "$GIT_SVN_DIR/index";
$SVN_URL = undef;
- $REV_DIR = "$GIT_SVN_DIR/revs";
$SVN_WC = "$GIT_SVN_DIR/tree";
}
@@ -2491,7 +2504,27 @@ sub libsvn_traverse_ignore {
$pool->clear;
}
-sub libsvn_new_tree {
+sub revisions_eq {
+ my ($path, $r0, $r1) = @_;
+ return 1 if $r0 == $r1;
+ my $nr = 0;
+ if ($_use_lib) {
+ # should be OK to use Pool here (r1 - r0) should be small
+ my $pool = SVN::Pool->new;
+ $SVN->get_log("/$path", $r0, $r1, 0, 1, 1, sub {$nr++},$pool);
+ $pool->clear;
+ } else {
+ my ($url, undef) = repo_path_split($SVN_URL);
+ my $svn_log = svn_log_raw("$url/$path","-r$r0:$r1");
+ while (next_log_entry($svn_log)) { $nr++ }
+ close $svn_log->{fh};
+ }
+ return 0 if ($nr > 1);
+ return 1;
+}
+
+sub libsvn_find_parent_branch {
+ return undef; # XXX this function is disabled atm (not tested enough)
my ($paths, $rev, $author, $date, $msg) = @_;
my $svn_path = '/'.$SVN_PATH;
@@ -2502,27 +2535,33 @@ sub libsvn_new_tree {
my $branch_from = $i->copyfrom_path or next;
my $r = $i->copyfrom_rev;
print STDERR "Found possible branch point: ",
- "$branch_from => $svn_path, $r\n";
+ "$branch_from => $svn_path, $r\n";
$branch_from =~ s#^/##;
my $l_map = read_url_paths();
my $url = $SVN->{url};
defined $l_map->{$url} or next;
my $id = $l_map->{$url}->{$branch_from} or next;
- my $f = "$GIT_DIR/svn/$id/revs/$r";
- while ($r && !-r $f) {
- $r--;
- $f = "$GIT_DIR/svn/$id/revs/$r";
- }
- if (-r $f) {
- my $parent = file_to_s($f);
+ my ($r0, $parent) = find_rev_before($r,$id,1);
+ if (defined $r0 && defined $parent &&
+ revisions_eq($branch_from, $r0, $r)) {
unlink $GIT_SVN_INDEX;
print STDERR "Found branch parent: $parent\n";
sys(qw/git-read-tree/, $parent);
return libsvn_fetch($parent, $paths, $rev,
$author, $date, $msg);
+ } else {
+ print STDERR
+ "Nope, branch point not imported or unknown\n";
}
- print STDERR "Nope, branch point not imported or unknown\n";
}
+ return undef;
+}
+
+sub libsvn_new_tree {
+ if (my $log_entry = libsvn_find_parent_branch(@_)) {
+ return $log_entry;
+ }
+ my ($paths, $rev, $author, $date, $msg) = @_;
open my $gui, '| git-update-index -z --index-info' or croak $!;
my $pool = SVN::Pool->new;
libsvn_traverse($gui, '', $SVN_PATH, $rev, $pool);
@@ -2536,10 +2575,8 @@ sub find_graft_path_commit {
foreach my $x (keys %$tree_paths) {
next unless ($p1 =~ /^\Q$x\E/);
my $i = $tree_paths->{$x};
- my $f = "$GIT_DIR/svn/$i/revs/$r1";
-
- return file_to_s($f) if (-r $f);
-
+ my ($r0, $parent) = find_rev_before($r1,$i,1);
+ return $parent if (defined $r0 && $r0 == $r1);
print STDERR "r$r1 of $i not imported\n";
next;
}
@@ -2551,18 +2588,10 @@ sub find_graft_path_parents {
foreach my $x (keys %$tree_paths) {
next unless ($p0 =~ /^\Q$x\E/);
my $i = $tree_paths->{$x};
- my $f = "$GIT_DIR/svn/$i/revs/$r0";
- while ($r0 && !-r $f) {
- # could be an older revision, too...
- $r0--;
- $f = "$GIT_DIR/svn/$i/revs/$r0";
- }
- unless (-r $f) {
- print STDERR "r$r0 of $i not imported\n";
- next;
+ my ($r, $parent) = find_rev_before($r0, $i, 1);
+ if (defined $r && defined $parent && revisions_eq($x,$r,$r0)) {
+ $grafts->{$c}->{$parent} = 1;
}
- my $parent = file_to_s($f);
- $grafts->{$c}->{$parent} = 1;
}
}
@@ -2600,8 +2629,7 @@ sub restore_index {
sub libsvn_commit_cb {
my ($rev, $date, $committer, $c, $msg, $r_last, $cmt_last) = @_;
- if ($rev == ($r_last + 1)) {
- # optimized (avoid fetch)
+ if ($_optimize_commits && $rev == ($r_last + 1)) {
my $log = libsvn_log_entry($rev,$committer,$date,$msg);
$log->{tree} = get_tree_from_treeish($c);
my $cmt = git_commit($log, $cmt_last, $c);
@@ -2652,6 +2680,49 @@ sub libsvn_skip_unknown_revs {
croak "Error from SVN, ($errno): ", $err->expanded_message,"\n";
};
+# Tie::File seems to be prone to offset errors if revisions get sparse,
+# it's not that fast, either. Tie::File is also not in Perl 5.6. So
+# one of my favorite modules is out :< Next up would be one of the DBM
+# modules, but I'm not sure which is most portable... So I'll just
+# go with something that's plain-text, but still capable of
+# being randomly accessed. So here's my ultra-simple fixed-width
+# database. All records are 40 characters + "\n", so it's easy to seek
+# to a revision: (41 * rev) is the byte offset.
+# A record of 40 0s denotes an empty revision.
+# And yes, it's still pretty fast (faster than Tie::File).
+sub revdb_set {
+ my ($file, $rev, $commit) = @_;
+ length $commit == 40 or croak "arg3 must be a full SHA1 hexsum\n";
+ open my $fh, '+<', $file or croak $!;
+ my $offset = $rev * 41;
+ # assume that append is the common case:
+ seek $fh, 0, 2 or croak $!;
+ my $pos = tell $fh;
+ if ($pos < $offset) {
+ print $fh (('0' x 40),"\n") x (($offset - $pos) / 41);
+ }
+ seek $fh, $offset, 0 or croak $!;
+ print $fh $commit,"\n";
+ close $fh or croak $!;
+}
+
+sub revdb_get {
+ my ($file, $rev) = @_;
+ my $ret;
+ my $offset = $rev * 41;
+ open my $fh, '<', $file or croak $!;
+ seek $fh, $offset, 0;
+ if (tell $fh == $offset) {
+ $ret = readline $fh;
+ if (defined $ret) {
+ chomp $ret;
+ $ret = undef if ($ret =~ /^0{40}$/);
+ }
+ }
+ close $fh or croak $!;
+ return $ret;
+}
+
package SVN::Git::Editor;
use vars qw/@ISA/;
use strict;
diff --git a/contrib/git-svn/t/t0000-contrib-git-svn.sh b/contrib/git-svn/t/t0000-contrib-git-svn.sh
index c33b522..f896e2c 100644
--- a/contrib/git-svn/t/t0000-contrib-git-svn.sh
+++ b/contrib/git-svn/t/t0000-contrib-git-svn.sh
@@ -193,5 +193,18 @@ test_expect_success "$name" \
git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b &&
diff -u a b"
+name='check imported tree checksums expected tree checksums'
+cat > expected <<\EOF
+tree f735671b89a7eb30cab1d8597de35bd4271ab813
+tree 4b9af72bb861eaed053854ec502cf7df72618f0f
+tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1
+tree 0b094cbff17168f24c302e297f55bfac65eb8bd3
+tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
+tree 56a30b966619b863674f5978696f4a3594f2fca9
+tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e
+tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4
+EOF
+test_expect_success "$name" "diff -u a expected"
+
test_done
diff --git a/contrib/git-svn/t/t0001-contrib-git-svn-props.sh b/contrib/git-svn/t/t0001-contrib-git-svn-props.sh
index 23a5a2a..54e0ed7 100644
--- a/contrib/git-svn/t/t0001-contrib-git-svn-props.sh
+++ b/contrib/git-svn/t/t0001-contrib-git-svn-props.sh
@@ -52,49 +52,49 @@ EOF
cd ..
rm -rf import
-svn co "$svnrepo" test_wc
+test_expect_success 'checkout working copy from svn' "svn co $svnrepo test_wc"
+test_expect_success 'setup some commits to svn' \
+ 'cd test_wc &&
+ echo Greetings >> kw.c &&
+ svn commit -m "Not yet an Id" &&
+ svn up &&
+ echo Hello world >> kw.c &&
+ svn commit -m "Modified file, but still not yet an Id" &&
+ svn up &&
+ svn propset svn:keywords Id kw.c &&
+ svn commit -m "Propset Id" &&
+ svn up &&
+ cd ..'
+
+test_expect_success 'initialize git-svn' "git-svn init $svnrepo"
+test_expect_success 'fetch revisions from svn' 'git-svn fetch'
-cd test_wc
- echo 'Greetings' >> kw.c
- svn commit -m 'Not yet an $Id$'
- svn up
-
- echo 'Hello world' >> kw.c
- svn commit -m 'Modified file, but still not yet an $Id$'
- svn up
-
- svn propset svn:keywords Id kw.c
- svn commit -m 'Propset $Id$'
- svn up
-cd ..
-
-git-svn init "$svnrepo"
-git-svn fetch
-
-git checkout -b mybranch remotes/git-svn
-echo 'Hi again' >> kw.c
name='test svn:keywords ignoring'
-
-git commit -a -m "$name"
-git-svn commit remotes/git-svn..mybranch
-git pull . remotes/git-svn
+test_expect_success "$name" \
+ 'git checkout -b mybranch remotes/git-svn &&
+ echo Hi again >> kw.c &&
+ git commit -a -m "test keywoards ignoring" &&
+ git-svn commit remotes/git-svn..mybranch &&
+ git pull . remotes/git-svn'
expect='/* $Id$ */'
got="`sed -ne 2p kw.c`"
test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'"
-cd test_wc
- svn propset svn:eol-style CR empty
- svn propset svn:eol-style CR crlf
- svn propset svn:eol-style CR ne_crlf
- svn commit -m 'propset CR on crlf files'
- svn up
-cd ..
+test_expect_success "propset CR on crlf files" \
+ 'cd test_wc &&
+ svn propset svn:eol-style CR empty &&
+ svn propset svn:eol-style CR crlf &&
+ svn propset svn:eol-style CR ne_crlf &&
+ svn commit -m "propset CR on crlf files" &&
+ svn up &&
+ cd ..'
-git-svn fetch
-git pull . remotes/git-svn
+test_expect_success 'fetch and pull latest from svn and checkout a new wc' \
+ "git-svn fetch &&
+ git pull . remotes/git-svn &&
+ svn co $svnrepo new_wc"
-svn co "$svnrepo" new_wc
for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf
do
test_expect_success "Comparing $i" "cmp $i new_wc/$i"
@@ -106,16 +106,16 @@ cd test_wc
printf '$Id$\rHello\rWorld' > ne_cr
a_cr=`printf '$Id$\r\nHello\r\nWorld\r\n' | git-hash-object --stdin`
a_ne_cr=`printf '$Id$\r\nHello\r\nWorld' | git-hash-object --stdin`
- svn propset svn:eol-style CRLF cr
- svn propset svn:eol-style CRLF ne_cr
- svn propset svn:keywords Id cr
- svn propset svn:keywords Id ne_cr
- svn commit -m 'propset CRLF on cr files'
- svn up
+ test_expect_success 'Set CRLF on cr files' \
+ 'svn propset svn:eol-style CRLF cr &&
+ svn propset svn:eol-style CRLF ne_cr &&
+ svn propset svn:keywords Id cr &&
+ svn propset svn:keywords Id ne_cr &&
+ svn commit -m "propset CRLF on cr files" &&
+ svn up'
cd ..
-
-git-svn fetch
-git pull . remotes/git-svn
+test_expect_success 'fetch and pull latest from svn' \
+ 'git-svn fetch && git pull . remotes/git-svn'
b_cr="`git-hash-object cr`"
b_ne_cr="`git-hash-object ne_cr`"
--
1.4.0
^ permalink raw reply related
* [PATCH 10/13] git-svn: add UTF-8 message test
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/t/t0000-contrib-git-svn.sh | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/contrib/git-svn/t/t0000-contrib-git-svn.sh b/contrib/git-svn/t/t0000-contrib-git-svn.sh
index a07fbad..0c6ff20 100644
--- a/contrib/git-svn/t/t0000-contrib-git-svn.sh
+++ b/contrib/git-svn/t/t0000-contrib-git-svn.sh
@@ -4,6 +4,7 @@ # Copyright (c) 2006 Eric Wong
#
test_description='git-svn tests'
+GIT_SVN_LC_ALL=$LC_ALL
. ./lib-git-svn.sh
mkdir import
@@ -163,6 +164,18 @@ test_expect_success "$name" \
diff -u help $SVN_TREE/exec-2.sh"
+if test -n "$GIT_SVN_LC_ALL" && echo $GIT_SVN_LC_ALL | grep -q '\.UTF-8$'
+then
+ name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
+ echo '# hello' >> exec-2.sh
+ git update-index exec-2.sh
+ git commit -m 'éïâ'
+ export LC_ALL="$GIT_SVN_LC_ALL"
+ test_expect_success "$name" "git-svn commit HEAD"
+ unset LC_ALL
+else
+ echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)"
+fi
name='test fetch functionality (svn => git) with alternate GIT_SVN_ID'
GIT_SVN_ID=alt
--
1.4.0
^ permalink raw reply related
* [PATCH 3/13] git-svn: optimize --branch and --branch-all-ref
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
By breaking the pipe read once we've seen a commit twice.
This should make -B/--branch-all-ref faster and usable on a
frequent basis.
We use topological order now for calling git-rev-list, and any
commit we've seen before should imply that all parents have been
seen (at least I hope that's the case for --topo-order).
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/git-svn.perl | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index c91160d..d4b9323 100755
--- a/contrib/git-svn/git-svn.perl
+++ b/contrib/git-svn/git-svn.perl
@@ -1220,23 +1220,30 @@ sub check_upgrade_needed {
# fills %tree_map with a reverse mapping of trees to commits. Useful
# for finding parents to commit on.
sub map_tree_joins {
+ my %seen;
foreach my $br (@_branch_from) {
my $pid = open my $pipe, '-|';
defined $pid or croak $!;
if ($pid == 0) {
- exec(qw(git-rev-list --pretty=raw), $br) or croak $?;
+ exec(qw(git-rev-list --topo-order --pretty=raw), $br)
+ or croak $?;
}
while (<$pipe>) {
if (/^commit ($sha1)$/o) {
my $commit = $1;
+
+ # if we've seen a commit,
+ # we've seen its parents
+ last if $seen{$commit};
my ($tree) = (<$pipe> =~ /^tree ($sha1)$/o);
unless (defined $tree) {
die "Failed to parse commit $commit\n";
}
push @{$tree_map{$tree}}, $commit;
+ $seen{$commit} = 1;
}
}
- close $pipe or croak $?;
+ close $pipe; # we could be breaking the pipe early
}
}
--
1.4.0
^ permalink raw reply related
* [PATCH 6/13] git-svn: minor cleanups, extra error-checking
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
While we're at it, read_repo_config has been added and
expanded to handle case where command-line arguments are
optional to Getopt::Long
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/git-svn.perl | 82 ++++++++++++++++++++++++------------------
1 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index 2dce4e7..a243060 100755
--- a/contrib/git-svn/git-svn.perl
+++ b/contrib/git-svn/git-svn.perl
@@ -77,39 +77,15 @@ for (my $i = 0; $i < @ARGV; $i++) {
my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
-# convert GetOpt::Long specs for use by git-repo-config
-foreach my $o (keys %opts) {
- my $v = $opts{$o};
- my ($key) = ($o =~ /^([a-z\-]+)/);
- $key =~ s/-//g;
- my $arg = 'git-repo-config';
- $arg .= ' --int' if ($o =~ /=i$/);
- $arg .= ' --bool' if ($o !~ /=[sfi]$/);
- if (ref $v eq 'ARRAY') {
- chomp(my @tmp = `$arg --get-all svn.$key`);
- @$v = @tmp if @tmp;
- } else {
- chomp(my $tmp = `$arg --get svn.$key`);
- if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {
- $$v = $tmp;
- }
- }
-}
-
+read_repo_config(\%opts);
GetOptions(%opts, 'help|H|h' => \$_help,
'version|V' => \$_version,
'id|i=s' => \$GIT_SVN) or exit 1;
-$GIT_SVN ||= $ENV{GIT_SVN_ID} || 'git-svn';
-$GIT_SVN_DIR = "$GIT_DIR/svn/$GIT_SVN";
-$GIT_SVN_INDEX = "$GIT_SVN_DIR/index";
-$SVN_URL = undef;
-$REV_DIR = "$GIT_SVN_DIR/revs";
-$SVN_WC = "$GIT_SVN_DIR/tree";
-
usage(0) if $_help;
version() if $_version;
usage(1) unless defined $cmd;
+init_vars();
load_authors() if $_authors;
load_all_refs() if $_branch_all_refs;
svn_compat_check();
@@ -132,7 +108,7 @@ Usage: $0 <command> [options] [arguments
print $fd ' ',pack('A13',$_),$cmd{$_}->[1],"\n";
foreach (keys %{$cmd{$_}->[2]}) {
# prints out arguments as they should be passed:
- my $x = s#=s$## ? '<arg>' : s#=i$## ? '<num>' : '';
+ my $x = s#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
print $fd ' ' x 17, join(', ', map { length $_ > 1 ?
"--$_" : "-$_" }
split /\|/,$_)," $x\n";
@@ -220,9 +196,10 @@ sub rebuild {
sys(@svn_up,"-r$newest_rev");
$ENV{GIT_INDEX_FILE} = $GIT_SVN_INDEX;
index_changes();
- exec('git-write-tree');
+ exec('git-write-tree') or croak $!;
}
waitpid $pid, 0;
+ croak $? if $?;
if ($_upgrade) {
print STDERR <<"";
@@ -295,6 +272,7 @@ sub fetch {
unless (-e "$GIT_DIR/refs/heads/master") {
sys(qw(git-update-ref refs/heads/master),$last_commit);
}
+ close $svn_log->{fh};
return $last;
}
@@ -830,7 +808,7 @@ sub svn_log_raw {
exec (qw(svn log), @log_args) or croak $!
}
waitpid $pid, 0;
- croak if $?;
+ croak $? if $?;
seek $log_fh, 0, 0 or croak $!;
return { state => 'sep', fh => $log_fh };
}
@@ -1090,7 +1068,7 @@ sub git_commit {
$ENV{GIT_INDEX_FILE} = $GIT_SVN_INDEX;
index_changes();
chomp(my $tree = `git-write-tree`);
- croak if $?;
+ croak $? if $?;
if (exists $tree_map{$tree}) {
my %seen_parent = map { $_ => 1 } @exec_parents;
foreach (@{$tree_map{$tree}}) {
@@ -1118,7 +1096,7 @@ sub git_commit {
exec @exec or croak $!;
}
waitpid($pid,0);
- croak if $?;
+ croak $? if $?;
$out_fh->flush == 0 or croak $!;
seek $out_fh, 0, 0 or croak $!;
@@ -1134,7 +1112,7 @@ sub git_commit {
close STDERR;
close STDOUT;
exec 'git-rev-parse','--verify',
- "refs/remotes/$GIT_SVN^0";
+ "refs/remotes/$GIT_SVN^0" or croak $!;
}
waitpid $pid, 0;
push @update_ref, $primary_parent unless $?;
@@ -1190,7 +1168,7 @@ sub blob_to_file {
if ($pid == 0) {
open STDOUT, '>&', $blob_fh or croak $!;
- exec('git-cat-file','blob',$blob);
+ exec('git-cat-file','blob',$blob) or croak $!;
}
waitpid $pid, 0;
croak $? if $?;
@@ -1202,7 +1180,7 @@ sub safe_qx {
my $pid = open my $child, '-|';
defined $pid or croak $!;
if ($pid == 0) {
- exec(@_) or croak $?;
+ exec(@_) or croak $!;
}
my @ret = (<$child>);
close $child or croak $?;
@@ -1252,7 +1230,7 @@ sub check_upgrade_needed {
defined $pid or croak $!;
if ($pid == 0) {
close STDERR;
- exec('git-rev-parse',"$GIT_SVN-HEAD") or croak $?;
+ exec('git-rev-parse',"$GIT_SVN-HEAD") or croak $!;
}
my @ret = (<$child>);
close $child or croak $?;
@@ -1276,7 +1254,7 @@ sub map_tree_joins {
defined $pid or croak $!;
if ($pid == 0) {
exec(qw(git-rev-list --topo-order --pretty=raw), $br)
- or croak $?;
+ or croak $!;
}
while (<$pipe>) {
if (/^commit ($sha1)$/o) {
@@ -1352,6 +1330,38 @@ sub migration_check {
print "Done upgrading.\n";
}
+sub init_vars {
+ $GIT_SVN ||= $ENV{GIT_SVN_ID} || 'git-svn';
+ $GIT_SVN_DIR = "$GIT_DIR/svn/$GIT_SVN";
+ $GIT_SVN_INDEX = "$GIT_SVN_DIR/index";
+ $SVN_URL = undef;
+ $REV_DIR = "$GIT_SVN_DIR/revs";
+ $SVN_WC = "$GIT_SVN_DIR/tree";
+}
+
+# convert GetOpt::Long specs for use by git-repo-config
+sub read_repo_config {
+ return unless -d $GIT_DIR;
+ my $opts = shift;
+ foreach my $o (keys %$opts) {
+ my $v = $opts->{$o};
+ my ($key) = ($o =~ /^([a-z\-]+)/);
+ $key =~ s/-//g;
+ my $arg = 'git-repo-config';
+ $arg .= ' --int' if ($o =~ /[:=]i$/);
+ $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
+ if (ref $v eq 'ARRAY') {
+ chomp(my @tmp = `$arg --get-all svn.$key`);
+ @$v = @tmp if @tmp;
+ } else {
+ chomp(my $tmp = `$arg --get svn.$key`);
+ if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {
+ $$v = $tmp;
+ }
+ }
+ }
+}
+
__END__
Data structures:
--
1.4.0
^ permalink raw reply related
* [PATCH 9/13] git-svn: add some functionality to better support branches in svn
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
New commands:
graft-branches - The most interesting command of the bunch. It
detects branches in SVN via various techniques (currently
regexes and file copies). It can be later extended to handle
svk and other properties people may use to track merges in svk.
Basically, merge tracking is not standardized at all in the SVN
world, and git grafts are perfect for dealing with this
situation.
Existing branch support (via tree matches) is only handled at
fetch time.
The following tow were originally implemented as shell scripts
several months ago, but I just decided to streamline things a
bit and added them to the main script.
multi-init - supports git-svnimport-like command-line syntax for
importing repositories that are layed out as recommended by the
SVN folks. This is a bit more tolerant than the git-svnimport
command-line syntax and doesn't require the user to figure out
where the repository URL ends and where the repository path
begins.
multi-fetch - runs fetch on all known SVN branches we're
tracking. This will NOT discover new branches (unlike
git-svnimport), so multi-init will need to be re-run (it's
idempotent).
Consider these three to be auxilliary commands (like
show-ignore, and rebuild) so their behavior won't receive as
much testing or scrutiny as the core commands (fetch and
commit).
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/git-svn.perl | 429 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 424 insertions(+), 5 deletions(-)
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index d8f103e..d5c7e47 100755
--- a/contrib/git-svn/git-svn.perl
+++ b/contrib/git-svn/git-svn.perl
@@ -35,8 +35,8 @@ my $sha1_short = qr/[a-f\d]{4,40}/;
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
$_find_copies_harder, $_l, $_cp_similarity,
$_repack, $_repack_nr, $_repack_flags,
- $_template, $_shared,
- $_version, $_upgrade, $_authors, $_branch_all_refs);
+ $_template, $_shared, $_no_default_regex, $_no_graft_copy,
+ $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m);
my (@_branch_from, %tree_map, %users);
my ($_svn_co_url_revs, $_svn_pg_peg_revs);
my @repo_path_split_cache;
@@ -48,6 +48,12 @@ my %fc_opts = ( 'no-ignore-externals' =>
'repack:i' => \$_repack,
'repack-flags|repack-args|repack-opts=s' => \$_repack_flags);
+my ($_trunk, $_tags, $_branches);
+my %multi_opts = ( 'trunk|T=s' => \$_trunk,
+ 'tags|t=s' => \$_tags,
+ 'branches|b=s' => \$_branches );
+my %init_opts = ( 'template=s' => \$_template, 'shared' => \$_shared );
+
# yes, 'native' sets "\n". Patches to fix this for non-*nix systems welcome:
my %EOL = ( CR => "\015", LF => "\012", CRLF => "\015\012", native => "\012" );
@@ -56,8 +62,7 @@ my %cmd = (
{ 'revision|r=s' => \$_revision, %fc_opts } ],
init => [ \&init, "Initialize a repo for tracking" .
" (requires URL argument)",
- { 'template=s' => \$_template,
- 'shared' => \$_shared } ],
+ \%init_opts ],
commit => [ \&commit, "Commit git revisions to SVN",
{ 'stdin|' => \$_stdin,
'edit|e' => \$_edit,
@@ -71,7 +76,19 @@ my %cmd = (
rebuild => [ \&rebuild, "Rebuild git-svn metadata (after git clone)",
{ 'no-ignore-externals' => \$_no_ignore_ext,
'upgrade' => \$_upgrade } ],
+ 'graft-branches' => [ \&graft_branches,
+ 'Detect merges/branches from already imported history',
+ { 'merge-rx|m' => \@_opt_m,
+ 'no-default-regex' => \$_no_default_regex,
+ 'no-graft-copy' => \$_no_graft_copy } ],
+ 'multi-init' => [ \&multi_init,
+ 'Initialize multiple trees (like git-svnimport)',
+ { %multi_opts, %fc_opts } ],
+ 'multi-fetch' => [ \&multi_fetch,
+ 'Fetch multiple trees (like git-svnimport)',
+ \%fc_opts ],
);
+
my $cmd;
for (my $i = 0; $i < @ARGV; $i++) {
if (defined $cmd{$ARGV[$i]}) {
@@ -96,7 +113,7 @@ init_vars();
load_authors() if $_authors;
load_all_refs() if $_branch_all_refs;
svn_compat_check();
-migration_check() unless $cmd eq 'init';
+migration_check() unless $cmd =~ /^(?:init|multi-init)$/;
$cmd{$cmd}->[0]->(@ARGV);
exit 0;
@@ -219,6 +236,7 @@ when you have upgraded your tools and ha
sub init {
$SVN_URL = shift or die "SVN repository location required " .
"as a command-line argument\n";
+ $SVN_URL =~ s!/+$!!; # strip trailing slash
unless (-d $GIT_DIR) {
my @init_db = ('git-init-db');
push @init_db, "--template=$_template" if defined $_template;
@@ -358,8 +376,283 @@ sub show_ignore {
}
}
+sub graft_branches {
+ my $gr_file = "$GIT_DIR/info/grafts";
+ my ($grafts, $comments) = read_grafts($gr_file);
+ my $gr_sha1;
+
+ if (%$grafts) {
+ # temporarily disable our grafts file to make this idempotent
+ chomp($gr_sha1 = safe_qx(qw/git-hash-object -w/,$gr_file));
+ rename $gr_file, "$gr_file~$gr_sha1" or croak $!;
+ }
+
+ my $l_map = read_url_paths();
+ my @re = map { qr/$_/is } @_opt_m if @_opt_m;
+ unless ($_no_default_regex) {
+ push @re, ( qr/\b(?:merge|merging|merged)\s+(\S.+)/is,
+ qr/\b(?:from|of)\s+(\S.+)/is );
+ }
+ foreach my $u (keys %$l_map) {
+ if (@re) {
+ foreach my $p (keys %{$l_map->{$u}}) {
+ graft_merge_msg($grafts,$l_map,$u,$p);
+ }
+ }
+ graft_file_copy($grafts,$l_map,$u) unless $_no_graft_copy;
+ }
+
+ write_grafts($grafts, $comments, $gr_file);
+ unlink "$gr_file~$gr_sha1" if $gr_sha1;
+}
+
+sub multi_init {
+ my $url = shift;
+ $_trunk ||= 'trunk';
+ $_trunk =~ s#/+$##;
+ $url =~ s#/+$## if $url;
+ if ($_trunk !~ m#^[a-z\+]+://#) {
+ $_trunk = '/' . $_trunk if ($_trunk !~ m#^/#);
+ unless ($url) {
+ print STDERR "E: '$_trunk' is not a complete URL ",
+ "and a separate URL is not specified\n";
+ exit 1;
+ }
+ $_trunk = $url . $_trunk;
+ }
+ if ($GIT_SVN eq 'git-svn') {
+ print "GIT_SVN_ID set to 'trunk' for $_trunk\n";
+ $GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
+ }
+ init_vars();
+ init($_trunk);
+ complete_url_ls_init($url, $_branches, '--branches/-b', '');
+ complete_url_ls_init($url, $_tags, '--tags/-t', 'tags/');
+}
+
+sub multi_fetch {
+ # try to do trunk first, since branches/tags
+ # may be descended from it.
+ if (-d "$GIT_DIR/svn/trunk") {
+ print "Fetching trunk\n";
+ defined(my $pid = fork) or croak $!;
+ if (!$pid) {
+ $GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
+ init_vars();
+ fetch(@_);
+ exit 0;
+ }
+ waitpid $pid, 0;
+ croak $? if $?;
+ }
+ rec_fetch('', "$GIT_DIR/svn", @_);
+}
+
########################### utility functions #########################
+sub rec_fetch {
+ my ($pfx, $p, @args) = @_;
+ my @dir;
+ foreach (sort <$p/*>) {
+ if (-r "$_/info/url") {
+ $pfx .= '/' if $pfx && $pfx !~ m!/$!;
+ my $id = $pfx . basename $_;
+ next if $id eq 'trunk';
+ print "Fetching $id\n";
+ defined(my $pid = fork) or croak $!;
+ if (!$pid) {
+ $GIT_SVN = $ENV{GIT_SVN_ID} = $id;
+ init_vars();
+ fetch(@args);
+ exit 0;
+ }
+ waitpid $pid, 0;
+ croak $? if $?;
+ } elsif (-d $_) {
+ push @dir, $_;
+ }
+ }
+ foreach (@dir) {
+ my $x = $_;
+ $x =~ s!^\Q$GIT_DIR\E/svn/!!;
+ rec_fetch($x, $_);
+ }
+}
+
+sub complete_url_ls_init {
+ my ($url, $var, $switch, $pfx) = @_;
+ unless ($var) {
+ print STDERR "W: $switch not specified\n";
+ return;
+ }
+ $var =~ s#/+$##;
+ if ($var !~ m#^[a-z\+]+://#) {
+ $var = '/' . $var if ($var !~ m#^/#);
+ unless ($url) {
+ print STDERR "E: '$var' is not a complete URL ",
+ "and a separate URL is not specified\n";
+ exit 1;
+ }
+ $var = $url . $var;
+ }
+ chomp(my @ls = safe_qx(qw/svn ls --non-interactive/, $var));
+ my $old = $GIT_SVN;
+ defined(my $pid = fork) or croak $!;
+ if (!$pid) {
+ foreach my $u (map { "$var/$_" } (grep m!/$!, @ls)) {
+ $u =~ s#/+$##;
+ if ($u !~ m!\Q$var\E/(.+)$!) {
+ print STDERR "W: Unrecognized URL: $u\n";
+ die "This should never happen\n";
+ }
+ my $id = $pfx.$1;
+ print "init $u => $id\n";
+ $GIT_SVN = $ENV{GIT_SVN_ID} = $id;
+ init_vars();
+ init($u);
+ }
+ exit 0;
+ }
+ waitpid $pid, 0;
+ croak $? if $?;
+}
+
+sub common_prefix {
+ my $paths = shift;
+ my %common;
+ foreach (@$paths) {
+ my @tmp = split m#/#, $_;
+ my $p = '';
+ while (my $x = shift @tmp) {
+ $p .= "/$x";
+ $common{$p} ||= 0;
+ $common{$p}++;
+ }
+ }
+ foreach (sort {length $b <=> length $a} keys %common) {
+ if ($common{$_} == @$paths) {
+ return $_;
+ }
+ }
+ return '';
+}
+
+# this isn't funky-filename safe, but good enough for now...
+sub graft_file_copy {
+ my ($grafts, $l_map, $u) = @_;
+ my $paths = $l_map->{$u};
+ my $pfx = common_prefix([keys %$paths]);
+
+ my $pid = open my $fh, '-|';
+ defined $pid or croak $!;
+ unless ($pid) {
+ exec(qw/svn log -v/, $u.$pfx) or croak $!;
+ }
+ my ($r, $mp) = (undef, undef);
+ while (<$fh>) {
+ chomp;
+ if (/^\-{72}$/) {
+ $mp = $r = undef;
+ } elsif (/^r(\d+) \| /) {
+ $r = $1 unless defined $r;
+ } elsif (/^Changed paths:/) {
+ $mp = 1;
+ } elsif ($mp && m#^ [AR] /(\S.*?) \(from /(\S+?):(\d+)\)$#) {
+ my $dbg = "r$r | $_";
+ my ($p1, $p0, $r0) = ($1, $2, $3);
+ my $c;
+ foreach my $x (keys %$paths) {
+ next unless ($p1 =~ /^\Q$x\E/);
+ my $i = $paths->{$x};
+ my $f = "$GIT_DIR/svn/$i/revs/$r";
+ unless (-r $f) {
+ print STDERR "r$r of $i not imported,",
+ " $dbg\n";
+ next;
+ }
+ $c = file_to_s($f);
+ }
+ next unless $c;
+ foreach my $x (keys %$paths) {
+ next unless ($p0 =~ /^\Q$x\E/);
+ my $i = $paths->{$x};
+ my $f = "$GIT_DIR/svn/$i/revs/$r0";
+ while ($r0 && !-r $f) {
+ # could be an older revision, too...
+ $r0--;
+ $f = "$GIT_DIR/svn/$i/revs/$r0";
+ }
+ unless (-r $f) {
+ print STDERR "r$r0 of $i not imported,",
+ " $dbg\n";
+ next;
+ }
+ my $r1 = file_to_s($f);
+ $grafts->{$c}->{$r1} = 1;
+ }
+ }
+ }
+}
+
+sub process_merge_msg_matches {
+ my ($grafts, $l_map, $u, $p, $c, @matches) = @_;
+ my (@strong, @weak);
+ foreach (@matches) {
+ # merging with ourselves is not interesting
+ next if $_ eq $p;
+ if ($l_map->{$u}->{$_}) {
+ push @strong, $_;
+ } else {
+ push @weak, $_;
+ }
+ }
+ foreach my $w (@weak) {
+ last if @strong;
+ # no exact match, use branch name as regexp.
+ my $re = qr/\Q$w\E/i;
+ foreach (keys %{$l_map->{$u}}) {
+ if (/$re/) {
+ push @strong, $_;
+ last;
+ }
+ }
+ last if @strong;
+ $w = basename($w);
+ $re = qr/\Q$w\E/i;
+ foreach (keys %{$l_map->{$u}}) {
+ if (/$re/) {
+ push @strong, $_;
+ last;
+ }
+ }
+ }
+ my ($rev) = ($c->{m} =~ /^git-svn-id:\s(?:\S+?)\@(\d+)
+ \s(?:[a-f\d\-]+)$/xsm);
+ unless (defined $rev) {
+ ($rev) = ($c->{m} =~/^git-svn-id:\s(\d+)
+ \@(?:[a-f\d\-]+)/xsm);
+ return unless defined $rev;
+ }
+ foreach my $m (@strong) {
+ my ($r0, $s0) = find_rev_before($rev, $m);
+ $grafts->{$c->{c}}->{$s0} = 1 if defined $s0;
+ }
+}
+
+sub graft_merge_msg {
+ my ($grafts, $l_map, $u, $p, @re) = @_;
+
+ my $x = $l_map->{$u}->{$p};
+ my $rl = rev_list_raw($x);
+ while (my $c = next_rev_list_entry($rl)) {
+ foreach my $re (@re) {
+ my (@br) = ($c->{m} =~ /$re/g);
+ next unless @br;
+ process_merge_msg_matches($grafts,$l_map,$u,$p,$c,@br);
+ }
+ }
+}
+
sub read_uuid {
return if $SVN_UUID;
my $info = shift || svn_info('.');
@@ -402,6 +695,7 @@ sub repo_path_split {
$url .= "/$n";
}
push @repo_path_split_cache, qr/^(\Q$url\E)/;
+ $path = join('/',@paths);
return ($url, $path);
}
@@ -806,6 +1100,38 @@ sub svn_commit_tree {
return fetch("$committed=$commit")->{revision};
}
+sub rev_list_raw {
+ my (@args) = @_;
+ my $pid = open my $fh, '-|';
+ defined $pid or croak $!;
+ if (!$pid) {
+ exec(qw/git-rev-list --pretty=raw/, @args) or croak $!;
+ }
+ return { fh => $fh, t => { } };
+}
+
+sub next_rev_list_entry {
+ my $rl = shift;
+ my $fh = $rl->{fh};
+ my $x = $rl->{t};
+ while (<$fh>) {
+ if (/^commit ($sha1)$/o) {
+ if ($x->{c}) {
+ $rl->{t} = { c => $1 };
+ return $x;
+ } else {
+ $x->{c} = $1;
+ }
+ } elsif (/^parent ($sha1)$/o) {
+ $x->{p}->{$1} = 1;
+ } elsif (s/^ //) {
+ $x->{m} ||= '';
+ $x->{m} .= $_;
+ }
+ }
+ return ($x != $rl->{t}) ? $x : undef;
+}
+
# read the entire log into a temporary file (which is removed ASAP)
# and store the file handle + parser state
sub svn_log_raw {
@@ -1318,6 +1644,16 @@ sub svn_propget_base {
return safe_qx(qw/svn propget/, $p, $f);
}
+sub git_svn_each {
+ my $sub = shift;
+ foreach (`git-rev-parse --symbolic --all`) {
+ next unless s#^refs/remotes/##;
+ chomp $_;
+ next unless -f "$GIT_DIR/svn/$_/info/url";
+ &$sub($_);
+ }
+}
+
sub migration_check {
return if (-d "$GIT_DIR/svn" || !-d $GIT_DIR);
print "Upgrading repository...\n";
@@ -1344,6 +1680,16 @@ sub migration_check {
print "Done upgrading.\n";
}
+sub find_rev_before {
+ my ($r, $git_svn_id) = @_;
+ my @revs = map { basename $_ } <$GIT_DIR/svn/$git_svn_id/revs/*>;
+ foreach my $r0 (sort { $b <=> $a } @revs) {
+ next if $r0 >= $r;
+ return ($r0, file_to_s("$GIT_DIR/svn/$git_svn_id/revs/$r0"));
+ }
+ return (undef, undef);
+}
+
sub init_vars {
$GIT_SVN ||= $ENV{GIT_SVN_ID} || 'git-svn';
$GIT_SVN_DIR = "$GIT_DIR/svn/$GIT_SVN";
@@ -1384,6 +1730,79 @@ sub set_default_vals {
}
}
+sub read_grafts {
+ my $gr_file = shift;
+ my ($grafts, $comments) = ({}, {});
+ if (open my $fh, '<', $gr_file) {
+ my @tmp;
+ while (<$fh>) {
+ if (/^($sha1)\s+/) {
+ my $c = $1;
+ if (@tmp) {
+ @{$comments->{$c}} = @tmp;
+ @tmp = ();
+ }
+ foreach my $p (split /\s+/, $_) {
+ $grafts->{$c}->{$p} = 1;
+ }
+ } else {
+ push @tmp, $_;
+ }
+ }
+ close $fh or croak $!;
+ @{$comments->{'END'}} = @tmp if @tmp;
+ }
+ return ($grafts, $comments);
+}
+
+sub write_grafts {
+ my ($grafts, $comments, $gr_file) = @_;
+
+ open my $fh, '>', $gr_file or croak $!;
+ foreach my $c (sort keys %$grafts) {
+ if ($comments->{$c}) {
+ print $fh $_ foreach @{$comments->{$c}};
+ }
+ my $p = $grafts->{$c};
+ delete $p->{$c}; # commits are not self-reproducing...
+ my $pid = open my $ch, '-|';
+ defined $pid or croak $!;
+ if (!$pid) {
+ exec(qw/git-cat-file commit/, $c) or croak $!;
+ }
+ while (<$ch>) {
+ if (/^parent ([a-f\d]{40})/) {
+ $p->{$1} = 1;
+ } else {
+ last unless /^\S/i;
+ }
+ }
+ close $ch; # breaking the pipe
+ print $fh $c, ' ', join(' ', sort keys %$p),"\n";
+ }
+ if ($comments->{'END'}) {
+ print $fh $_ foreach @{$comments->{'END'}};
+ }
+ close $fh or croak $!;
+}
+
+sub read_url_paths {
+ my $l_map = {};
+ git_svn_each(sub { my $x = shift;
+ my $u = file_to_s("$GIT_DIR/svn/$x/info/repo_url");
+ my $p = file_to_s("$GIT_DIR/svn/$x/info/repo_path");
+ # we hate trailing slashes
+ if ($u =~ s#(?:^\/+|\/+$)##g) {
+ s_to_file($u,"$GIT_DIR/svn/$x/info/repo_url");
+ }
+ if ($p =~ s#(?:^\/+|\/+$)##g) {
+ s_to_file($p,"$GIT_DIR/svn/$x/info/repo_path");
+ }
+ $l_map->{$u}->{$p} = $x;
+ });
+ return $l_map;
+}
+
__END__
Data structures:
--
1.4.0
^ permalink raw reply related
* [PATCH 5/13] git-svn: Move all git-svn-related paths into $GIT_DIR/svn
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
Since GIT_SVN_ID usage is probably going to become more
widespread <evil grin>, we won't run the chance of somebody
having a GIT_SVN_ID name that conflicts with one of the default
directories that already exist in $GIT_DIR (branches/tags).
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/git-svn.perl | 99 ++++++++++++++++++++++++++++++++------
contrib/git-svn/t/lib-git-svn.sh | 2 -
2 files changed, 85 insertions(+), 16 deletions(-)
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index 54f3d63..2dce4e7 100755
--- a/contrib/git-svn/git-svn.perl
+++ b/contrib/git-svn/git-svn.perl
@@ -6,7 +6,7 @@ use strict;
use vars qw/ $AUTHOR $VERSION
$SVN_URL $SVN_INFO $SVN_WC $SVN_UUID
$GIT_SVN_INDEX $GIT_SVN
- $GIT_DIR $REV_DIR/;
+ $GIT_DIR $REV_DIR $GIT_SVN_DIR/;
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
$VERSION = '1.1.0-pre';
@@ -37,6 +37,7 @@ my ($_revision,$_stdin,$_no_ignore_ext,$
$_version, $_upgrade, $_authors, $_branch_all_refs);
my (@_branch_from, %tree_map, %users);
my ($_svn_co_url_revs, $_svn_pg_peg_revs);
+my @repo_path_split_cache;
my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
'branch|b=s' => \@_branch_from,
@@ -100,10 +101,11 @@ GetOptions(%opts, 'help|H|h' => \$_help,
'id|i=s' => \$GIT_SVN) or exit 1;
$GIT_SVN ||= $ENV{GIT_SVN_ID} || 'git-svn';
-$GIT_SVN_INDEX = "$GIT_DIR/$GIT_SVN/index";
+$GIT_SVN_DIR = "$GIT_DIR/svn/$GIT_SVN";
+$GIT_SVN_INDEX = "$GIT_SVN_DIR/index";
$SVN_URL = undef;
-$REV_DIR = "$GIT_DIR/$GIT_SVN/revs";
-$SVN_WC = "$GIT_DIR/$GIT_SVN/tree";
+$REV_DIR = "$GIT_SVN_DIR/revs";
+$SVN_WC = "$GIT_SVN_DIR/tree";
usage(0) if $_help;
version() if $_version;
@@ -111,6 +113,7 @@ usage(1) unless defined $cmd;
load_authors() if $_authors;
load_all_refs() if $_branch_all_refs;
svn_compat_check();
+migration_check() unless $cmd eq 'init';
$cmd{$cmd}->[0]->(@ARGV);
exit 0;
@@ -200,7 +203,7 @@ sub rebuild {
$latest = $rev;
}
assert_revision_eq_or_unknown($rev, $c);
- sys('git-update-ref',"$GIT_SVN/revs/$rev",$c);
+ sys('git-update-ref',"svn/$GIT_SVN/revs/$rev",$c);
$newest_rev = $rev if ($rev > $newest_rev);
}
close $rev_list or croak $?;
@@ -241,7 +244,7 @@ sub init {
sub fetch {
my (@parents) = @_;
check_upgrade_needed();
- $SVN_URL ||= file_to_s("$GIT_DIR/$GIT_SVN/info/url");
+ $SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
my @log_args = -d $SVN_WC ? ($SVN_WC) : ($SVN_URL);
unless ($_revision) {
$_revision = -d $SVN_WC ? 'BASE:HEAD' : '0:HEAD';
@@ -350,7 +353,7 @@ sub show_ignore {
chomp(my @excludes = (<$fh>));
close $fh or croak $!;
- $SVN_URL ||= file_to_s("$GIT_DIR/$GIT_SVN/info/url");
+ $SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
chdir $SVN_WC or croak $!;
my %ign;
File::Find::find({wanted=>sub{if(lstat $_ && -d _ && -d "$_/.svn"){
@@ -374,7 +377,44 @@ sub read_uuid {
my $info = shift || svn_info('.');
$SVN_UUID = $info->{'Repository UUID'} or
croak "Repository UUID unreadable\n";
- s_to_file($SVN_UUID,"$GIT_DIR/$GIT_SVN/info/uuid");
+ s_to_file($SVN_UUID,"$GIT_SVN_DIR/info/uuid");
+}
+
+sub quiet_run {
+ my $pid = fork;
+ defined $pid or croak $!;
+ if (!$pid) {
+ open my $null, '>', '/dev/null' or croak $!;
+ open STDERR, '>&', $null or croak $!;
+ open STDOUT, '>&', $null or croak $!;
+ exec @_ or croak $!;
+ }
+ waitpid $pid, 0;
+ return $?;
+}
+
+sub repo_path_split {
+ my $full_url = shift;
+ $full_url =~ s#/+$##;
+
+ foreach (@repo_path_split_cache) {
+ if ($full_url =~ s#$_##) {
+ my $u = $1;
+ $full_url =~ s#^/+##;
+ return ($u, $full_url);
+ }
+ }
+
+ my ($url, $path) = ($full_url =~ m!^([a-z\+]+://[^/]*)(.*)$!i);
+ $path =~ s#^/+##;
+ my @paths = split(m#/+#, $path);
+
+ while (quiet_run(qw/svn ls --non-interactive/, $url)) {
+ my $n = shift @paths || last;
+ $url .= "/$n";
+ }
+ push @repo_path_split_cache, qr/^(\Q$url\E)/;
+ return ($url, $path);
}
sub setup_git_svn {
@@ -382,14 +422,17 @@ sub setup_git_svn {
unless (-d $GIT_DIR) {
croak "GIT_DIR=$GIT_DIR does not exist!\n";
}
- mkpath(["$GIT_DIR/$GIT_SVN"]);
- mkpath(["$GIT_DIR/$GIT_SVN/info"]);
+ mkpath([$GIT_SVN_DIR]);
+ mkpath(["$GIT_SVN_DIR/info"]);
mkpath([$REV_DIR]);
- s_to_file($SVN_URL,"$GIT_DIR/$GIT_SVN/info/url");
+ s_to_file($SVN_URL,"$GIT_SVN_DIR/info/url");
- open my $fd, '>>', "$GIT_DIR/$GIT_SVN/info/exclude" or croak $!;
+ open my $fd, '>>', "$GIT_SVN_DIR/info/exclude" or croak $!;
print $fd '.svn',"\n";
close $fd or croak $!;
+ my ($url, $path) = repo_path_split($SVN_URL);
+ s_to_file($url, "$GIT_SVN_DIR/info/repo_url");
+ s_to_file($path, "$GIT_SVN_DIR/info/repo_path");
}
sub assert_svn_wc_clean {
@@ -688,7 +731,7 @@ sub handle_rmdir {
sub svn_commit_tree {
my ($svn_rev, $commit) = @_;
- my $commit_msg = "$GIT_DIR/$GIT_SVN/.svn-commit.tmp.$$";
+ my $commit_msg = "$GIT_SVN_DIR/.svn-commit.tmp.$$";
my %log_msg = ( msg => '' );
open my $msg, '>', $commit_msg or croak $!;
@@ -965,7 +1008,7 @@ sub index_changes {
'remove',
$no_text_base);
do_update_index([qw/git-ls-files -z --others/,
- "--exclude-from=$GIT_DIR/$GIT_SVN/info/exclude"],
+ "--exclude-from=$GIT_SVN_DIR/info/exclude"],
'add',
$no_text_base);
}
@@ -1097,7 +1140,7 @@ sub git_commit {
push @update_ref, $primary_parent unless $?;
}
sys(@update_ref);
- sys('git-update-ref',"$GIT_SVN/revs/$log_msg->{revision}",$commit);
+ sys('git-update-ref',"svn/$GIT_SVN/revs/$log_msg->{revision}",$commit);
print "r$log_msg->{revision} = $commit\n";
return $commit;
}
@@ -1283,6 +1326,32 @@ sub svn_propget_base {
return safe_qx(qw/svn propget/, $p, $f);
}
+sub migration_check {
+ return if (-d "$GIT_DIR/svn" || !-d $GIT_DIR);
+ print "Upgrading repository...\n";
+ unless (-d "$GIT_DIR/svn") {
+ mkdir "$GIT_DIR/svn" or croak $!;
+ }
+ print "Data from a previous version of git-svn exists, but\n\t",
+ "$GIT_SVN_DIR\n\t(required for this version ",
+ "($VERSION) of git-svn) does not.\n";
+
+ foreach my $x (`git-rev-parse --symbolic --all`) {
+ next unless $x =~ s#^refs/remotes/##;
+ chomp $x;
+ next unless -f "$GIT_DIR/$x/info/url";
+ my $u = eval { file_to_s("$GIT_DIR/$x/info/url") };
+ next unless $u;
+ my $dn = dirname("$GIT_DIR/svn/$x");
+ mkpath([$dn]) unless -d $dn;
+ rename "$GIT_DIR/$x", "$GIT_DIR/svn/$x" or croak "$!: $x";
+ my ($url, $path) = repo_path_split($u);
+ s_to_file($url, "$GIT_DIR/svn/$x/info/repo_url");
+ s_to_file($path, "$GIT_DIR/svn/$x/info/repo_path");
+ }
+ print "Done upgrading.\n";
+}
+
__END__
Data structures:
diff --git a/contrib/git-svn/t/lib-git-svn.sh b/contrib/git-svn/t/lib-git-svn.sh
index a98e9d1..58408a6 100644
--- a/contrib/git-svn/t/lib-git-svn.sh
+++ b/contrib/git-svn/t/lib-git-svn.sh
@@ -10,7 +10,7 @@ fi
. ./test-lib.sh
GIT_DIR=$PWD/.git
-GIT_SVN_DIR=$GIT_DIR/git-svn
+GIT_SVN_DIR=$GIT_DIR/svn/git-svn
SVN_TREE=$GIT_SVN_DIR/tree
svnadmin >/dev/null 2>&1
--
1.4.0
^ permalink raw reply related
* [PATCH 7/13] git-svn: add --repack and --repack-flags= options
From: Eric Wong @ 2006-06-13 18:02 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Eric Wong
In-Reply-To: <11502217352245-git-send-email-normalperson@yhbt.net>
This should help keep disk usage sane for large imports.
--repack takes an optional argument for the interval, it
defaults to 1000 if no argument is specified.
Arguments to --repack-flags are passed directly to git-repack.
No arguments are passed by default.
Idea stolen from git-cvsimport :)
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
contrib/git-svn/git-svn.perl | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl
index a243060..a04cf1d 100755
--- a/contrib/git-svn/git-svn.perl
+++ b/contrib/git-svn/git-svn.perl
@@ -34,6 +34,7 @@ my $sha1 = qr/[a-f\d]{40}/;
my $sha1_short = qr/[a-f\d]{4,40}/;
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
$_find_copies_harder, $_l, $_cp_similarity,
+ $_repack, $_repack_nr, $_repack_flags,
$_version, $_upgrade, $_authors, $_branch_all_refs);
my (@_branch_from, %tree_map, %users);
my ($_svn_co_url_revs, $_svn_pg_peg_revs);
@@ -42,7 +43,9 @@ my @repo_path_split_cache;
my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
'branch|b=s' => \@_branch_from,
'branch-all-refs|B' => \$_branch_all_refs,
- 'authors-file|A=s' => \$_authors );
+ 'authors-file|A=s' => \$_authors,
+ 'repack:i' => \$_repack,
+ 'repack-flags|repack-args|repack-opts=s' => \$_repack_flags);
# yes, 'native' sets "\n". Patches to fix this for non-*nix systems welcome:
my %EOL = ( CR => "\015", LF => "\012", CRLF => "\015\012", native => "\012" );
@@ -82,6 +85,7 @@ GetOptions(%opts, 'help|H|h' => \$_help,
'version|V' => \$_version,
'id|i=s' => \$GIT_SVN) or exit 1;
+set_default_vals();
usage(0) if $_help;
version() if $_version;
usage(1) unless defined $cmd;
@@ -1120,6 +1124,10 @@ sub git_commit {
sys(@update_ref);
sys('git-update-ref',"svn/$GIT_SVN/revs/$log_msg->{revision}",$commit);
print "r$log_msg->{revision} = $commit\n";
+ if ($_repack && (--$_repack_nr == 0)) {
+ $_repack_nr = $_repack;
+ sys("git repack $_repack_flags");
+ }
return $commit;
}
@@ -1362,6 +1370,14 @@ sub read_repo_config {
}
}
+sub set_default_vals {
+ if (defined $_repack) {
+ $_repack = 1000 if ($_repack <= 0);
+ $_repack_nr = $_repack;
+ $_repack_flags ||= '';
+ }
+}
+
__END__
Data structures:
--
1.4.0
^ permalink raw reply related
* Re: Thoughts on adding another hook to git
From: Junio C Hamano @ 2006-06-13 18:41 UTC (permalink / raw)
To: David Kowis; +Cc: git
In-Reply-To: <448DB201.5090208@shlrm.org>
David Kowis <dkowis@shlrm.org> writes:
> I'd like to be able to modify the commit message before it ends up in
> the $EDITOR. This is a fairly trivial thing to implement:
> Call ${GIT_DIR}/hooks/pre-editor on COMMIT_MESSAGE before opening it in
> $EDITOR.
Three random thoughts.
- pre-editor is too generic a name because before making a
commit is not the only place we give you $EDITOR (both am and
tag do EDITOR thing IIRC). So the hook name must be more
specific to the commit codepath (otherwise your pre-editor
hook needs to be able to tell which codepath called it).
- git-commit gives you EDITOR when you are making a merge, and
you would probably want to keep the default merge commit
message without the prefixed directory thing. You probably
do not want to do this while doing --amend either.
- it might make sense to have a "commit template" that is used
when making a non-merge commit afresh (i.e. without -F, -m,
-c or -C to specify messages), instead of a hook script.
^ permalink raw reply
* Re: git-cvsimport doesn't quite work, wrt branches
From: Keith Packard @ 2006-06-13 18:46 UTC (permalink / raw)
To: Linus Torvalds
Cc: keithp, Jim Meyering, Git Mailing List, Matthias Urlichs,
Yann Dirson, Pavel Roskin
In-Reply-To: <Pine.LNX.4.64.0606131008470.5498@g5.osdl.org>
[-- Attachment #1: Type: text/plain, Size: 542 bytes --]
On Tue, 2006-06-13 at 10:20 -0700, Linus Torvalds wrote:
> Well, it's a cvsps problem.
>
> Big surprise.
Yeah, we've got
git-cvsimport
cvsps
cvs rlog
,v files
cvs rlog is designed to 'represent' the history of the repository to
users. Cvsps was built as a software analysis tool, and is used by
putative software engineering researchers. Basing a supposedly lossless
repository conversion system on this pair seems foolish to me,
notwithstanding the heroic efforts to make it work.
--
keith.packard@intel.com
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply
* [PATCH 0/8] Make a couple of commands builtin
From: Lukas Sandström @ 2006-06-13 20:21 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
This patchseries has the ultimate goal of making
git-am a builtin.
The version of git-am I'm sending out makes quite heavy
use of system(), but I think that can be worked around.
I just haven't figured out how, yet.
/Lukas
^ permalink raw reply
* [PATCH 1/8] Make git-write-tree a builtin
From: Lukas Sandström @ 2006-06-13 20:21 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Makefile | 6 ++-
write-tree.c => builtin-write-tree.c | 68 +++++++++++++++++++++-------------
builtin.h | 3 ++
git.c | 3 +-
4 files changed, 50 insertions(+), 30 deletions(-)
diff --git a/Makefile b/Makefile
index 2a1e639..37b5e40 100644
--- a/Makefile
+++ b/Makefile
@@ -159,7 +159,7 @@ PROGRAMS = \
git-show-index$X git-ssh-fetch$X \
git-ssh-upload$X git-unpack-file$X \
git-unpack-objects$X git-update-index$X git-update-server-info$X \
- git-upload-pack$X git-verify-pack$X git-write-tree$X \
+ git-upload-pack$X git-verify-pack$X \
git-update-ref$X git-symbolic-ref$X \
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
@@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X
git-check-ref-format$X git-rev-parse$X \
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
- git-read-tree$X git-commit-tree$X \
+ git-read-tree$X git-commit-tree$X git-write-tree$X \
git-apply$X git-show-branch$X git-diff-files$X \
git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
@@ -223,7 +223,7 @@ BUILTIN_OBJS = \
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
builtin-tar-tree.o builtin-upload-tar.o \
- builtin-ls-files.o builtin-ls-tree.o \
+ builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
builtin-read-tree.o builtin-commit-tree.o \
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
diff --git a/write-tree.c b/builtin-write-tree.c
similarity index 66%
rename from write-tree.c
rename to builtin-write-tree.c
index bd07da6..c3aac36 100644
--- a/write-tree.c
+++ b/builtin-write-tree.c
@@ -3,41 +3,24 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+#include "builtin.h"
#include "cache.h"
#include "tree.h"
#include "cache-tree.h"
-static int missing_ok = 0;
-static char *prefix = NULL;
-
static const char write_tree_usage[] =
"git-write-tree [--missing-ok] [--prefix=<prefix>/]";
-static struct lock_file lock_file;
-
-int main(int argc, char **argv)
+int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
{
int entries, was_valid, newfd;
- setup_git_directory();
+ /* We can't free this memory, it becomes part of a linked list parsed atexit() */
+ struct lock_file *lock_file = xmalloc(sizeof(struct lock_file));
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
- entries = read_cache();
-
- while (1 < argc) {
- char *arg = argv[1];
- if (!strcmp(arg, "--missing-ok"))
- missing_ok = 1;
- else if (!strncmp(arg, "--prefix=", 9))
- prefix = arg + 9;
- else
- die(write_tree_usage);
- argc--; argv++;
- }
-
- if (argc > 2)
- die("too many options");
+ newfd = hold_lock_file_for_update(lock_file, get_index_file());
+ entries = read_cache();
if (entries < 0)
die("git-write-tree: error reading cache");
@@ -45,6 +28,7 @@ int main(int argc, char **argv)
active_cache_tree = cache_tree();
was_valid = cache_tree_fully_valid(active_cache_tree);
+
if (!was_valid) {
if (cache_tree_update(active_cache_tree,
active_cache, active_nr,
@@ -52,7 +36,7 @@ int main(int argc, char **argv)
die("git-write-tree: error building trees");
if (0 <= newfd) {
if (!write_cache(newfd, active_cache, active_nr))
- commit_lock_file(&lock_file);
+ commit_lock_file(lock_file);
}
/* Not being able to write is fine -- we are only interested
* in updating the cache-tree part, and if the next caller
@@ -61,12 +45,44 @@ int main(int argc, char **argv)
* performance penalty and not a big deal.
*/
}
+
if (prefix) {
struct cache_tree *subtree =
cache_tree_find(active_cache_tree, prefix);
- printf("%s\n", sha1_to_hex(subtree->sha1));
+ memcpy(sha1, subtree->sha1, 20);
}
else
- printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
+ memcpy(sha1, active_cache_tree->sha1, 20);
+
+ rollback_lock_file(lock_file);
+
return 0;
}
+
+int cmd_write_tree(int argc, const char **argv, char **envp)
+{
+ int missing_ok = 0, ret;
+ const char *prefix = NULL;
+ unsigned char sha1[20];
+
+ setup_git_directory();
+
+ while (1 < argc) {
+ const char *arg = argv[1];
+ if (!strcmp(arg, "--missing-ok"))
+ missing_ok = 1;
+ else if (!strncmp(arg, "--prefix=", 9))
+ prefix = arg + 9;
+ else
+ die(write_tree_usage);
+ argc--; argv++;
+ }
+
+ if (argc > 2)
+ die("too many options");
+
+ ret = write_tree(sha1, missing_ok, prefix);
+ printf("%s\n", sha1_to_hex(sha1));
+
+ return ret;
+}
diff --git a/builtin.h b/builtin.h
index b9f36be..885422e 100644
--- a/builtin.h
+++ b/builtin.h
@@ -46,4 +46,7 @@ extern int cmd_diff_tree(int argc, const
extern int cmd_cat_file(int argc, const char **argv, char **envp);
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
+extern int cmd_write_tree(int argc, const char **argv, char **envp);
+extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
+
#endif
diff --git a/git.c b/git.c
index 9469d44..5868fb9 100644
--- a/git.c
+++ b/git.c
@@ -178,7 +178,8 @@ static void handle_internal_command(int
{ "diff-stages", cmd_diff_stages },
{ "diff-tree", cmd_diff_tree },
{ "cat-file", cmd_cat_file },
- { "rev-parse", cmd_rev_parse }
+ { "rev-parse", cmd_rev_parse },
+ { "write-tree", cmd_write_tree }
};
int i;
--
1.4.0
^ permalink raw reply related
* [PATCH 2/8] Make git-mailsplit a builtin
From: Lukas Sandström @ 2006-06-13 20:21 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Makefile | 5 +--
mailsplit.c => builtin-mailsplit.c | 71 +++++++++++++++++++++---------------
builtin.h | 2 +
git.c | 3 +-
4 files changed, 48 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
index 37b5e40..7bee30d 100644
--- a/Makefile
+++ b/Makefile
@@ -144,7 +144,6 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)
# The ones that do not have to link with lcrypto, lz nor xdiff.
SIMPLE_PROGRAMS = \
- git-mailsplit$X \
git-stripspace$X git-daemon$X
# ... and all the rest that could be moved out of bindir to gitexecdir
@@ -165,7 +164,7 @@ PROGRAMS = \
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
- git-count-objects$X git-diff$X git-push$X \
+ git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
git-grep$X git-add$X git-rm$X git-rev-list$X \
git-check-ref-format$X git-rev-parse$X \
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
@@ -227,7 +226,7 @@ BUILTIN_OBJS = \
builtin-read-tree.o builtin-commit-tree.o \
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
- builtin-cat-file.o
+ builtin-cat-file.o builtin-mailsplit.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
LIBS = $(GITLIBS) -lz
diff --git a/mailsplit.c b/builtin-mailsplit.c
similarity index 85%
rename from mailsplit.c
rename to builtin-mailsplit.c
index 70a569c..e2a0058 100644
--- a/mailsplit.c
+++ b/builtin-mailsplit.c
@@ -12,6 +12,7 @@ #include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include "cache.h"
+#include "builtin.h"
static const char git_mailsplit_usage[] =
"git-mailsplit [-d<prec>] [-f<n>] [-b] -o<directory> <mbox>...";
@@ -102,14 +103,48 @@ static int split_one(FILE *mbox, const c
exit(1);
}
-int main(int argc, const char **argv)
+int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip)
{
- int nr = 0, nr_prec = 4;
+ char *name = xmalloc(strlen(dir) + 2 + 3 * sizeof(skip));
+ int ret = -1;
+
+ while (*mbox) {
+ const char *file = *mbox++;
+ FILE *f = !strcmp(file, "-") ? stdin : fopen(file, "r");
+ int file_done = 0;
+
+ if ( !f ) {
+ error("cannot open mbox %s", file);
+ goto out;
+ }
+
+ if (fgets(buf, sizeof(buf), f) == NULL) {
+ if (f == stdin)
+ break; /* empty stdin is OK */
+ error("cannot read mbox %s", file);
+ goto out;
+ }
+
+ while (!file_done) {
+ sprintf(name, "%s/%0*d", dir, nr_prec, ++skip);
+ file_done = split_one(f, name, allow_bare);
+ }
+
+ if (f != stdin)
+ fclose(f);
+ }
+ ret = skip;
+out:
+ free(name);
+ return ret;
+}
+int cmd_mailsplit(int argc, const char **argv, char **envp)
+{
+ int nr = 0, nr_prec = 4, ret;
int allow_bare = 0;
const char *dir = NULL;
const char **argp;
static const char *stdin_only[] = { "-", NULL };
- char *name;
for (argp = argv+1; *argp; argp++) {
const char *arg = *argp;
@@ -158,31 +193,9 @@ int main(int argc, const char **argv)
argp = stdin_only;
}
- name = xmalloc(strlen(dir) + 2 + 3 * sizeof(nr));
-
- while (*argp) {
- const char *file = *argp++;
- FILE *f = !strcmp(file, "-") ? stdin : fopen(file, "r");
- int file_done = 0;
-
- if ( !f )
- die ("cannot open mbox %s", file);
-
- if (fgets(buf, sizeof(buf), f) == NULL) {
- if (f == stdin)
- break; /* empty stdin is OK */
- die("cannot read mbox %s", file);
- }
-
- while (!file_done) {
- sprintf(name, "%s/%0*d", dir, nr_prec, ++nr);
- file_done = split_one(f, name, allow_bare);
- }
-
- if (f != stdin)
- fclose(f);
- }
+ ret = split_mbox(argp, dir, allow_bare, nr_prec, nr);
+ if (ret != -1)
+ printf("%d\n", ret);
- printf("%d\n", nr);
- return 0;
+ return ret == -1;
}
diff --git a/builtin.h b/builtin.h
index 885422e..92e1e1b 100644
--- a/builtin.h
+++ b/builtin.h
@@ -49,4 +49,6 @@ extern int cmd_rev_parse(int argc, const
extern int cmd_write_tree(int argc, const char **argv, char **envp);
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
+extern int cmd_mailsplit(int argc, const char **argv, char **envp);
+extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
#endif
diff --git a/git.c b/git.c
index 5868fb9..3264c65 100644
--- a/git.c
+++ b/git.c
@@ -179,7 +179,8 @@ static void handle_internal_command(int
{ "diff-tree", cmd_diff_tree },
{ "cat-file", cmd_cat_file },
{ "rev-parse", cmd_rev_parse },
- { "write-tree", cmd_write_tree }
+ { "write-tree", cmd_write_tree },
+ { "mailsplit", cmd_mailsplit }
};
int i;
--
1.4.0
^ permalink raw reply related
* [PATCH 3/8] Make git-mailinfo a builtin
From: Lukas Sandström @ 2006-06-13 20:21 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Makefile | 12 ++---
mailinfo.c => builtin-mailinfo.c | 85 ++++++++++++++++++++++----------------
builtin.h | 6 +++
git.c | 3 +
4 files changed, 62 insertions(+), 44 deletions(-)
diff --git a/Makefile b/Makefile
index 7bee30d..e64d943 100644
--- a/Makefile
+++ b/Makefile
@@ -151,7 +151,7 @@ PROGRAMS = \
git-checkout-index$X git-clone-pack$X \
git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
git-hash-object$X git-index-pack$X git-local-fetch$X \
- git-mailinfo$X git-merge-base$X \
+ git-merge-base$X \
git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
git-peek-remote$X git-prune-packed$X git-receive-pack$X \
git-send-pack$X git-shell$X \
@@ -166,7 +166,7 @@ PROGRAMS = \
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
git-grep$X git-add$X git-rm$X git-rev-list$X \
- git-check-ref-format$X git-rev-parse$X \
+ git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
git-read-tree$X git-commit-tree$X git-write-tree$X \
@@ -223,7 +223,7 @@ BUILTIN_OBJS = \
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
builtin-tar-tree.o builtin-upload-tar.o \
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
- builtin-read-tree.o builtin-commit-tree.o \
+ builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
builtin-cat-file.o builtin-mailsplit.o
@@ -486,7 +486,7 @@ strip: $(PROGRAMS) git$X
git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS)
$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
- $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+ $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) $(LIB_4_ICONV)
builtin-help.o: common-cmds.h
@@ -563,10 +563,6 @@ git-%$X: %.o $(GITLIBS)
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(LIB_FILE) $(SIMPLE_LIB)
-git-mailinfo$X: mailinfo.o $(LIB_FILE)
- $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
- $(LIB_FILE) $(SIMPLE_LIB) $(LIB_4_ICONV)
-
git-local-fetch$X: fetch.o
git-ssh-fetch$X: rsh.o fetch.o
git-ssh-upload$X: rsh.o
diff --git a/mailinfo.c b/builtin-mailinfo.c
similarity index 94%
rename from mailinfo.c
rename to builtin-mailinfo.c
index 5b6c215..6e30758 100644
--- a/mailinfo.c
+++ b/builtin-mailinfo.c
@@ -12,8 +12,9 @@ #include <iconv.h>
#endif
#include "git-compat-util.h"
#include "cache.h"
+#include "builtin.h"
-static FILE *cmitmsg, *patchfile;
+static FILE *cmitmsg, *patchfile, *fin, *fout;
static int keep_subject = 0;
static char *metainfo_charset = NULL;
@@ -49,7 +50,7 @@ static int bogus_from(char *line)
/* This is fallback, so do not bother if we already have an
* e-mail address.
- */
+ */
if (*email)
return 0;
@@ -311,12 +312,12 @@ static char *cleanup_subject(char *subje
if (remove <= len *2) {
subject = p+1;
continue;
- }
+ }
break;
}
return subject;
}
-}
+}
static void cleanup_space(char *buf)
{
@@ -638,7 +639,7 @@ static void handle_info(void)
cleanup_space(email);
cleanup_space(sub);
- printf("Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n",
+ fprintf(fout, "Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n",
name, email, sub, date);
}
@@ -675,7 +676,7 @@ static int handle_commit_msg(int *seen)
continue;
fputs(line, cmitmsg);
- } while (fgets(line, sizeof(line), stdin) != NULL);
+ } while (fgets(line, sizeof(line), fin) != NULL);
fclose(cmitmsg);
cmitmsg = NULL;
return 0;
@@ -696,7 +697,7 @@ static void handle_patch(void)
decode_transfer_encoding(line);
fputs(line, patchfile);
patch_lines++;
- } while (fgets(line, sizeof(line), stdin) != NULL);
+ } while (fgets(line, sizeof(line), fin) != NULL);
}
/* multipart boundary and transfer encoding are set up for us, and we
@@ -709,7 +710,7 @@ static int handle_multipart_one_part(int
{
int n = 0;
- while (fgets(line, sizeof(line), stdin) != NULL) {
+ while (fgets(line, sizeof(line), fin) != NULL) {
again:
n++;
if (is_multipart_boundary(line))
@@ -730,7 +731,7 @@ static void handle_multipart_body(void)
int part_num = 0;
/* Skip up to the first boundary */
- while (fgets(line, sizeof(line), stdin) != NULL)
+ while (fgets(line, sizeof(line), fin) != NULL)
if (is_multipart_boundary(line)) {
part_num = 1;
break;
@@ -739,7 +740,7 @@ static void handle_multipart_body(void)
return;
/* We are on boundary line. Start slurping the subhead. */
while (1) {
- int hdr = read_one_header_line(line, sizeof(line), stdin);
+ int hdr = read_one_header_line(line, sizeof(line), fin);
if (!hdr) {
if (handle_multipart_one_part(&seen) < 0)
return;
@@ -762,7 +763,7 @@ static void handle_body(void)
{
int seen = 0;
- if (line[0] || fgets(line, sizeof(line), stdin) != NULL) {
+ if (line[0] || fgets(line, sizeof(line), fin) != NULL) {
handle_commit_msg(&seen);
handle_patch();
}
@@ -773,10 +774,45 @@ static void handle_body(void)
}
}
+int mailinfo(FILE *in, FILE *out, int ks, char *encoding,
+ const char *msg, const char *patch)
+{
+ keep_subject = ks;
+ metainfo_charset = encoding;
+ fin = in;
+ fout = out;
+
+ cmitmsg = fopen(msg, "w");
+ if (!cmitmsg) {
+ perror(msg);
+ return -1;
+ }
+ patchfile = fopen(patch, "w");
+ if (!patchfile) {
+ perror(patch);
+ fclose(cmitmsg);
+ return -1;
+ }
+ while (1) {
+ int hdr = read_one_header_line(line, sizeof(line), fin);
+ if (!hdr) {
+ if (multipart_boundary[0])
+ handle_multipart_body();
+ else
+ handle_body();
+ handle_info();
+ break;
+ }
+ check_header_line(line);
+ }
+
+ return 0;
+}
+
static const char mailinfo_usage[] =
"git-mailinfo [-k] [-u | --encoding=<encoding>] msg patch <mail >info";
-int main(int argc, char **argv)
+int cmd_mailinfo(int argc, const char **argv, char **envp)
{
/* NEEDSWORK: might want to do the optional .git/ directory
* discovery
@@ -797,27 +833,6 @@ int main(int argc, char **argv)
if (argc != 3)
usage(mailinfo_usage);
- cmitmsg = fopen(argv[1], "w");
- if (!cmitmsg) {
- perror(argv[1]);
- exit(1);
- }
- patchfile = fopen(argv[2], "w");
- if (!patchfile) {
- perror(argv[2]);
- exit(1);
- }
- while (1) {
- int hdr = read_one_header_line(line, sizeof(line), stdin);
- if (!hdr) {
- if (multipart_boundary[0])
- handle_multipart_body();
- else
- handle_body();
- handle_info();
- break;
- }
- check_header_line(line);
- }
- return 0;
+
+ return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[1], argv[2]);
}
diff --git a/builtin.h b/builtin.h
index 92e1e1b..979e0cd 100644
--- a/builtin.h
+++ b/builtin.h
@@ -1,6 +1,8 @@
#ifndef BUILTIN_H
#define BUILTIN_H
+#include <stdio.h>
+
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
@@ -51,4 +53,8 @@ extern int write_tree(unsigned char *sha
extern int cmd_mailsplit(int argc, const char **argv, char **envp);
extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
+
+extern int cmd_mailinfo(int argc, const char **argv, char **envp);
+extern int mailinfo(FILE *in, FILE *out, int ks, char *encoding,
+ const char *msg, const char *patch);
#endif
diff --git a/git.c b/git.c
index 3264c65..1e216de 100644
--- a/git.c
+++ b/git.c
@@ -180,7 +180,8 @@ static void handle_internal_command(int
{ "cat-file", cmd_cat_file },
{ "rev-parse", cmd_rev_parse },
{ "write-tree", cmd_write_tree },
- { "mailsplit", cmd_mailsplit }
+ { "mailsplit", cmd_mailsplit },
+ { "mailinfo", cmd_mailinfo }
};
int i;
--
1.4.0
^ permalink raw reply related
* [PATCH 4/8] Make git-stripspace a builtin
From: Lukas Sandström @ 2006-06-13 20:21 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Makefile | 6 +++---
stripspace.c => builtin-stripspace.c | 16 +++++++++++-----
builtin.h | 6 ++++--
git.c | 3 ++-
4 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index e64d943..181255f 100644
--- a/Makefile
+++ b/Makefile
@@ -144,7 +144,7 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)
# The ones that do not have to link with lcrypto, lz nor xdiff.
SIMPLE_PROGRAMS = \
- git-stripspace$X git-daemon$X
+ git-daemon$X
# ... and all the rest that could be moved out of bindir to gitexecdir
PROGRAMS = \
@@ -165,7 +165,7 @@ PROGRAMS = \
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
- git-grep$X git-add$X git-rm$X git-rev-list$X \
+ git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
@@ -226,7 +226,7 @@ BUILTIN_OBJS = \
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
- builtin-cat-file.o builtin-mailsplit.o
+ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
LIBS = $(GITLIBS) -lz
diff --git a/stripspace.c b/builtin-stripspace.c
similarity index 76%
rename from stripspace.c
rename to builtin-stripspace.c
index 65a6346..2ce1264 100644
--- a/stripspace.c
+++ b/builtin-stripspace.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+#include "builtin.h"
/*
* Remove empty lines from the beginning and end.
@@ -28,21 +29,21 @@ static int cleanup(char *line)
return 1;
}
-int main(int argc, char **argv)
+void stripspace(FILE *in, FILE *out)
{
int empties = -1;
int incomplete = 0;
char line[1024];
- while (fgets(line, sizeof(line), stdin)) {
+ while (fgets(line, sizeof(line), in)) {
incomplete = cleanup(line);
/* Not just an empty line? */
if (line[0] != '\n') {
if (empties > 0)
- putchar('\n');
+ fputc('\n', out);
empties = 0;
- fputs(line, stdout);
+ fputs(line, out);
continue;
}
if (empties < 0)
@@ -50,6 +51,11 @@ int main(int argc, char **argv)
empties++;
}
if (incomplete)
- putchar('\n');
+ fputc('\n', out);
+}
+
+int cmd_stripspace(int argc, const char **argv, char **envp)
+{
+ stripspace(stdin, stdout);
return 0;
}
diff --git a/builtin.h b/builtin.h
index 979e0cd..c934d7a 100644
--- a/builtin.h
+++ b/builtin.h
@@ -55,6 +55,8 @@ extern int cmd_mailsplit(int argc, const
extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
extern int cmd_mailinfo(int argc, const char **argv, char **envp);
-extern int mailinfo(FILE *in, FILE *out, int ks, char *encoding,
- const char *msg, const char *patch);
+extern int mailinfo(FILE *in, FILE *out, int ks, char *encoding, const char *msg, const char *patch);
+
+extern int cmd_stripspace(int argc, const char **argv, char **envp);
+extern void stripspace(FILE *in, FILE *out);
#endif
diff --git a/git.c b/git.c
index 1e216de..31196f5 100644
--- a/git.c
+++ b/git.c
@@ -181,7 +181,8 @@ static void handle_internal_command(int
{ "rev-parse", cmd_rev_parse },
{ "write-tree", cmd_write_tree },
{ "mailsplit", cmd_mailsplit },
- { "mailinfo", cmd_mailinfo }
+ { "mailinfo", cmd_mailinfo },
+ { "stripspace", cmd_stripspace }
};
int i;
--
1.4.0
^ permalink raw reply related
* [PATCH 7/8] Make it possible to call cmd_apply multiple times
From: Lukas Sandström @ 2006-06-13 20:22 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
* xmalloc a new struct lock_file each invocation.
* Don't die() if the patch doesn't apply.
* Initialize the global variables each invocation.
* Roll back the lock_file.
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
builtin-apply.c | 94 +++++++++++++++++++++++++++++++++++--------------------
1 files changed, 60 insertions(+), 34 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index e113c74..a76c553 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -22,24 +22,13 @@ #include "builtin.h"
// --index updates the cache as well.
// --cached updates only the cache without ever touching the working tree.
//
-static const char *prefix;
-static int prefix_length = -1;
-static int newfd = -1;
-
-static int p_value = 1;
-static int allow_binary_replacement = 0;
-static int check_index = 0;
-static int write_index = 0;
-static int cached = 0;
-static int diffstat = 0;
-static int numstat = 0;
-static int summary = 0;
-static int check = 0;
-static int apply = 1;
-static int no_add = 0;
-static int show_index_info = 0;
-static int line_termination = '\n';
+static const char *prefix, *patch_input_file;
+static int prefix_length, newfd, p_value, allow_binary_replacement, check_index,
+ write_index, cached, diffstat, numstat, summary, check, apply, no_add,
+ show_index_info, line_termination, whitespace_error, squelch_whitespace_errors,
+ applied_after_stripping;
static unsigned long p_context = -1;
+
static const char apply_usage[] =
"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
@@ -49,10 +38,31 @@ static enum whitespace_eol {
error_on_whitespace,
strip_whitespace,
} new_whitespace = warn_on_whitespace;
-static int whitespace_error = 0;
-static int squelch_whitespace_errors = 5;
-static int applied_after_stripping = 0;
-static const char *patch_input_file = NULL;
+
+static void setup_state()
+{
+ prefix = NULL;
+ prefix_length = -1;
+ newfd = -1;
+ p_value = 1;
+ allow_binary_replacement = 0;
+ check_index = 0;
+ write_index = 0;
+ cached = 0;
+ diffstat = 0;
+ numstat = 0;
+ summary = 0;
+ check = 0;
+ apply = 1;
+ no_add = 0;
+ show_index_info = 0;
+ line_termination = '\n';
+ p_context = -1;
+ whitespace_error = 0;
+ squelch_whitespace_errors = 5;
+ applied_after_stripping = 0;
+ patch_input_file = NULL;
+}
static void parse_whitespace_option(const char *option)
{
@@ -2072,7 +2082,7 @@ static void write_out_results(struct pat
}
}
-static struct lock_file lock_file;
+static struct lock_file *lock_file;
static struct excludes {
struct excludes *next;
@@ -2106,7 +2116,7 @@ static int apply_patch(int fd, const cha
patch_input_file = filename;
if (!buffer)
- return -1;
+ return -2;
offset = 0;
while (size > 0) {
struct patch *patch;
@@ -2134,7 +2144,7 @@ static int apply_patch(int fd, const cha
write_index = check_index && apply;
if (write_index && newfd < 0) {
- newfd = hold_lock_file_for_update(&lock_file,
+ newfd = hold_lock_file_for_update(lock_file,
get_index_file());
if (newfd < 0)
die("unable to create new index file");
@@ -2145,7 +2155,7 @@ static int apply_patch(int fd, const cha
}
if ((check || apply) && check_patch_list(list) < 0)
- exit(1);
+ return -1;
if (apply)
write_out_results(list, skipped_patch);
@@ -2175,20 +2185,27 @@ static int git_apply_config(const char *
return git_default_config(var, value);
}
-
int cmd_apply(int argc, const char **argv, char **envp)
{
- int i;
+ int i, ret = 0;
int read_stdin = 1;
const char *whitespace_option = NULL;
+ setup_state();
+
+ /* This memory can't be free()'d since it's needed atexit() */
+ lock_file = xmalloc(sizeof(struct lock_file));
+
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
char *end;
- int fd;
+ int fd, apply_status;
if (!strcmp(arg, "-")) {
- apply_patch(0, "<stdin>");
+ if (apply_patch(0, "<stdin>")) {
+ ret = 1;
+ goto err;
+ }
read_stdin = 0;
continue;
}
@@ -2281,12 +2298,18 @@ int cmd_apply(int argc, const char **arg
usage(apply_usage);
read_stdin = 0;
set_default_whitespace_mode(whitespace_option);
- apply_patch(fd, arg);
+ apply_status = apply_patch(fd, arg);
close(fd);
+ if (apply_status) {
+ ret = 1;
+ goto err;
+ }
}
set_default_whitespace_mode(whitespace_option);
- if (read_stdin)
- apply_patch(0, "<stdin>");
+ if (read_stdin && apply_patch(0, "<stdin>")) {
+ ret = 1;
+ goto err;
+ }
if (whitespace_error) {
if (squelch_whitespace_errors &&
squelch_whitespace_errors < whitespace_error) {
@@ -2316,9 +2339,12 @@ int cmd_apply(int argc, const char **arg
if (write_index) {
if (write_cache(newfd, active_cache, active_nr) ||
- commit_lock_file(&lock_file))
+ commit_lock_file(lock_file))
die("Unable to write new index file");
}
- return 0;
+err:
+ rollback_lock_file(lock_file);
+
+ return ret;
}
--
1.4.0
^ permalink raw reply related
* [PATCH 6/8] Make git-update-ref a builtin
From: Lukas Sandström @ 2006-06-13 20:22 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Makefile | 7 ++++---
update-ref.c => builtin-update-ref.c | 5 ++++-
builtin.h | 1 +
git.c | 3 ++-
4 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 906fc0f..4b30ca0 100644
--- a/Makefile
+++ b/Makefile
@@ -159,11 +159,11 @@ PROGRAMS = \
git-ssh-upload$X git-unpack-file$X \
git-unpack-objects$X git-update-server-info$X \
git-upload-pack$X git-verify-pack$X \
- git-update-ref$X git-symbolic-ref$X \
+ git-symbolic-ref$X \
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
-BUILT_INS = git-log$X git-whatchanged$X git-show$X \
+BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
@@ -226,7 +226,8 @@ BUILTIN_OBJS = \
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
- builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o
+ builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
+ builtin-update-ref.o
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
LIBS = $(GITLIBS) -lz
diff --git a/update-ref.c b/builtin-update-ref.c
similarity index 89%
rename from update-ref.c
rename to builtin-update-ref.c
index a1e6bb9..00333c7 100644
--- a/update-ref.c
+++ b/builtin-update-ref.c
@@ -1,10 +1,11 @@
#include "cache.h"
#include "refs.h"
+#include "builtin.h"
static const char git_update_ref_usage[] =
"git-update-ref <refname> <value> [<oldval>] [-m <reason>]";
-int main(int argc, char **argv)
+int cmd_update_ref(int argc, const char **argv, char **envp)
{
const char *refname=NULL, *value=NULL, *oldval=NULL, *msg=NULL;
struct ref_lock *lock;
@@ -52,5 +53,7 @@ int main(int argc, char **argv)
return 1;
if (write_ref_sha1(lock, sha1, msg) < 0)
return 1;
+
+ /* write_ref_sha1 always unlocks the ref, no need to do it explicitly */
return 0;
}
diff --git a/builtin.h b/builtin.h
index 9ee5ea6..c1f3395 100644
--- a/builtin.h
+++ b/builtin.h
@@ -48,6 +48,7 @@ extern int cmd_diff_tree(int argc, const
extern int cmd_cat_file(int argc, const char **argv, char **envp);
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
extern int cmd_update_index(int argc, const char **argv, char **envp);
+extern int cmd_update_ref(int argc, const char **argv, char **envp);
extern int cmd_write_tree(int argc, const char **argv, char **envp);
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
diff --git a/git.c b/git.c
index 4a931fb..652e3c4 100644
--- a/git.c
+++ b/git.c
@@ -183,7 +183,8 @@ static void handle_internal_command(int
{ "mailsplit", cmd_mailsplit },
{ "mailinfo", cmd_mailinfo },
{ "stripspace", cmd_stripspace },
- { "update-index", cmd_update_index }
+ { "update-index", cmd_update_index },
+ { "update-ref", cmd_update_ref }
};
int i;
--
1.4.0
^ permalink raw reply related
* [PATCH 5/8] Make git-update-index a builtin
From: Lukas Sandström @ 2006-06-13 20:21 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Makefile | 6 +++---
update-index.c => builtin-update-index.c | 19 ++++++++++++-------
builtin.h | 1 +
git.c | 3 ++-
4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index 181255f..906fc0f 100644
--- a/Makefile
+++ b/Makefile
@@ -157,7 +157,7 @@ PROGRAMS = \
git-send-pack$X git-shell$X \
git-show-index$X git-ssh-fetch$X \
git-ssh-upload$X git-unpack-file$X \
- git-unpack-objects$X git-update-index$X git-update-server-info$X \
+ git-unpack-objects$X git-update-server-info$X \
git-upload-pack$X git-verify-pack$X \
git-update-ref$X git-symbolic-ref$X \
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
@@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
git-read-tree$X git-commit-tree$X git-write-tree$X \
- git-apply$X git-show-branch$X git-diff-files$X \
+ git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
# what 'all' will build and 'install' will install, in gitexecdir
@@ -221,7 +221,7 @@ BUILTIN_OBJS = \
builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
- builtin-tar-tree.o builtin-upload-tar.o \
+ builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
diff --git a/update-index.c b/builtin-update-index.c
similarity index 97%
rename from update-index.c
rename to builtin-update-index.c
index fbccc4a..325cd09 100644
--- a/update-index.c
+++ b/builtin-update-index.c
@@ -8,6 +8,7 @@ #include "strbuf.h"
#include "quote.h"
#include "cache-tree.h"
#include "tree-walk.h"
+#include "builtin.h"
/*
* Default to not allowing changes to the list of files. The
@@ -186,8 +187,6 @@ static void chmod_path(int flip, const c
die("git-update-index: cannot chmod %cx '%s'", flip, path);
}
-static struct lock_file lock_file;
-
static void update_one(const char *path, const char *prefix, int prefix_length)
{
const char *p = prefix_path(prefix, prefix_length, path);
@@ -238,7 +237,7 @@ static void read_index_info(int line_ter
* (2) mode SP type SP sha1 TAB path
* The second format is to stuff git-ls-tree output
* into the index file.
- *
+ *
* (3) mode SP sha1 SP stage TAB path
* This format is to put higher order stages into the
* index file and matches git-ls-files --stage output.
@@ -477,7 +476,7 @@ static int do_reupdate(int ac, const cha
return 0;
}
-int main(int argc, const char **argv)
+int cmd_update_index(int argc, const char **argv, char **envp)
{
int i, newfd, entries, has_errors = 0, line_termination = '\n';
int allow_options = 1;
@@ -486,12 +485,16 @@ int main(int argc, const char **argv)
int prefix_length = prefix ? strlen(prefix) : 0;
char set_executable_bit = 0;
unsigned int refresh_flags = 0;
+ struct lock_file *lock_file;
git_config(git_default_config);
- newfd = hold_lock_file_for_update(&lock_file, get_index_file());
+ /* We can't free this memory, it becomes part of a linked list parsed atexit() */
+ lock_file = xmalloc(sizeof(struct lock_file));
+
+ newfd = hold_lock_file_for_update(lock_file, get_index_file());
if (newfd < 0)
- die("unable to create new index file");
+ die("unable to create new cachefile");
entries = read_cache();
if (entries < 0)
@@ -645,9 +648,11 @@ int main(int argc, const char **argv)
finish:
if (active_cache_changed) {
if (write_cache(newfd, active_cache, active_nr) ||
- commit_lock_file(&lock_file))
+ commit_lock_file(lock_file))
die("Unable to write new index file");
}
+ rollback_lock_file(lock_file);
+
return has_errors ? 1 : 0;
}
diff --git a/builtin.h b/builtin.h
index c934d7a..9ee5ea6 100644
--- a/builtin.h
+++ b/builtin.h
@@ -47,6 +47,7 @@ extern int cmd_diff_stages(int argc, con
extern int cmd_diff_tree(int argc, const char **argv, char **envp);
extern int cmd_cat_file(int argc, const char **argv, char **envp);
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
+extern int cmd_update_index(int argc, const char **argv, char **envp);
extern int cmd_write_tree(int argc, const char **argv, char **envp);
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
diff --git a/git.c b/git.c
index 31196f5..4a931fb 100644
--- a/git.c
+++ b/git.c
@@ -182,7 +182,8 @@ static void handle_internal_command(int
{ "write-tree", cmd_write_tree },
{ "mailsplit", cmd_mailsplit },
{ "mailinfo", cmd_mailinfo },
- { "stripspace", cmd_stripspace }
+ { "stripspace", cmd_stripspace },
+ { "update-index", cmd_update_index }
};
int i;
--
1.4.0
^ permalink raw reply related
* [PATCH/RFC 8/8] Make git-am a builtin
From: Lukas Sandström @ 2006-06-13 20:22 UTC (permalink / raw)
To: Junio C Hamano, Git Mailing List; +Cc: Lukas Sandström
In-Reply-To: <448EF791.7070504@etek.chalmers.se>
Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>
---
Being able to switch index-file on the fly would reduce the number of
system() calls.
A way to check if the index/working dir is dirty would also help.
Makefile | 6 -
builtin-am.c | 664 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
builtin.h | 1
git-am.sh | 427 -------------------------------------
git.c | 3
5 files changed, 670 insertions(+), 431 deletions(-)
diff --git a/Makefile b/Makefile
index 4b30ca0..e9b372e 100644
--- a/Makefile
+++ b/Makefile
@@ -122,7 +122,7 @@ SCRIPT_SH = \
git-repack.sh git-request-pull.sh git-reset.sh \
git-resolve.sh git-revert.sh git-sh-setup.sh \
git-tag.sh git-verify-tag.sh \
- git-applymbox.sh git-applypatch.sh git-am.sh \
+ git-applymbox.sh git-applypatch.sh \
git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
git-merge-resolve.sh git-merge-ours.sh \
git-lost-found.sh git-quiltimport.sh
@@ -166,7 +166,7 @@ PROGRAMS = \
BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
- git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
+ git-check-ref-format$X git-rev-parse$X git-mailinfo$X git-am$X \
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
git-read-tree$X git-commit-tree$X git-write-tree$X \
@@ -220,7 +220,7 @@ LIB_OBJS = \
BUILTIN_OBJS = \
builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
- builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
+ builtin-rm.o builtin-init-db.o builtin-rev-parse.o builtin-am.o \
builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
diff --git a/builtin-am.c b/builtin-am.c
new file mode 100644
index 0000000..d9e7ac5
--- /dev/null
+++ b/builtin-am.c
@@ -0,0 +1,664 @@
+/*
+ * GIT - The information manager from hell
+ *
+ * Copyright (C) Lukas Sandström, 2006
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/wait.h>
+
+#include "git-compat-util.h"
+#include "cache.h"
+#include "builtin.h"
+
+static char builtin_am_usage[] = "[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] "
+ "[--interactive] [--whitespace=<option>] <mbox>...\n"
+ "or, when resuming [--skip | --resolved]";
+
+static int binary, interactive, threeway, signoff, utf8, keep_subject, resolved, skip, resume;
+static char whitespace[40] = "--whitespace=warn", **env;
+static const char **mbox, *dotest, *resolvmsg;
+
+#define PATCH_PREC 4
+
+#define AGAIN 0
+#define SKIP 1
+#define YES 2
+
+//ugly hack to be able to change the index file
+extern char *git_index_file;
+
+static int rm_rf(const char* path)
+{
+ char cmd[PATH_MAX + 10];
+ snprintf(cmd, sizeof(cmd), "rm -rf %s", path);
+ return system(cmd);
+}
+
+static int mkdir_p(const char *path)
+{
+ char p[PATH_MAX], n, *l;
+
+ strcpy(p, path);
+ while ((l = strchr(p, '/'))) {
+ n = *l;
+ *l = '\0';
+ if (access(p, F_OK) && mkdir(p, 0777))
+ return -1;
+ *l = n;
+ }
+ return mkdir(p, 0777);
+}
+
+static int fcat(char *file, char *fmt, ...)
+{
+ va_list args;
+ int ret;
+ FILE *f;
+
+ file = mkpath("%s/%s", dotest, file);
+ if ((f = fopen(file, "r")) == NULL) {
+ perror(file);
+ die("Couldn't open file %s", file);
+ }
+ va_start(args, fmt);
+ ret = vfscanf(f, fmt, args);
+ va_end(args);
+ fclose(f);
+ return ret;
+}
+
+static int fecho(char *file, char *fmt, ...)
+{
+ va_list args;
+ int ret;
+ FILE *f;
+
+ file = mkpath("%s/%s", dotest, file);
+ if ((f = fopen(file, "w")) == NULL) {
+ perror(file);
+ die("Couldn't open file %s/%s", dotest, file);
+ }
+ va_start(args, fmt);
+ ret = vfprintf(f, fmt, args);
+ va_end(args);
+ fclose(f);
+ return ret;
+}
+
+static FILE* get_output(char *cmd, int *status)
+{
+ char c[2000];
+ FILE *ret;
+ int s;
+
+ snprintf(c, sizeof(c), "%s > \"%s/outtmp\"", cmd, dotest);
+ s = system(c);
+ if (status)
+ *status = s;
+ if ((ret = fopen(mkpath("%s/outtmp", dotest), "r")) == NULL)
+ die("cmd: %s\nOpen \"%s\" failed.", c, mkpath("%s/outtmp", dotest));
+ unlink(mkpath("%s/outtmp", dotest));
+ return ret;
+}
+
+static int has_zero_output(char *cmd)
+{
+ struct stat s;
+
+ system(mkpath("%s > %s/zerotmp", cmd, dotest));
+ stat(mkpath("%s/zerotmp", dotest), &s);
+ unlink(mkpath("%s/zerotmp", dotest));
+ return s.st_size == 0;
+}
+
+static int go_next(int this) {
+ unlink(mkpath("%s/%0*d", dotest, PATCH_PREC, this));
+ unlink(mkpath("%s/msg", dotest));
+ unlink(mkpath("%s/msg-clean", dotest));
+ unlink(mkpath("%s/patch", dotest));
+ unlink(mkpath("%s/info", dotest));
+ fecho("next", "%d", this + 1);
+ return this + 1;
+}
+
+static void stop_here(int this)
+{
+ fecho("next","%d\n", this);
+ exit(1);
+}
+
+static void stop_here_user_resolve(int this)
+{
+ char cmdline[1000] = "git am";
+ int pos = 6; /* "git am" */
+
+ if (resolvmsg != NULL) {
+ printf("%s", resolvmsg);
+ stop_here(this);
+ }
+
+ if (interactive)
+ pos += sprintf(cmdline + pos, " -i");
+ if (threeway)
+ pos += sprintf(cmdline + pos, " -3");
+ if (strcmp(".dotest", dotest))
+ pos += sprintf(cmdline + pos, " -d=%s", dotest);
+
+ printf("When you have resolved this problem run \"git am %s --resolved\".\n", cmdline);
+ printf("If you would prefer to skip this patch, instead run \"%s --skip\".\n", cmdline);
+
+ stop_here(this);
+}
+
+static int fall_back_3way()
+{
+ char cmd[1000];
+ char tmp_index[PATH_MAX], old_index[PATH_MAX] = "";
+ int ret = -1;
+
+ snprintf(cmd, sizeof(cmd), "git-apply -z --index-info \"%s/patch\""
+ " > %s/patch-merge-index-info 2> /dev/null", dotest, dotest);
+ if (!system(cmd)) {
+ snprintf(tmp_index, sizeof(tmp_index),"%s/patch-merge-tmp-index", dotest);
+ if (getenv(INDEX_ENVIRONMENT))
+ strcpy(old_index, getenv(INDEX_ENVIRONMENT));
+ setenv(INDEX_ENVIRONMENT, tmp_index, 1);
+
+ snprintf(cmd, sizeof(cmd), "git-update-index -z --index-info <\"%s/patch-merge-index-info\"", dotest);
+ if (!system(cmd)) {
+#if 1
+ system(mkpath("git-write-tree > \"%s/patch-merge-base\"", dotest));
+ snprintf(cmd, sizeof(cmd), "git-apply %s --cached < \"%s/patch\"", binary ? "--allow-binary-replacement":"", dotest);
+ if (!system(cmd)) {
+ char his_tree[41], orig_tree[41];
+ printf("Using index info to reconstruct a base tree...\n");
+ system(mkpath("git-write-tree > \"%s/his-tree\"", dotest));
+ fcat("his-tree", "%40s", his_tree);
+ fcat("patch-merge-base", "%40s", orig_tree);
+
+ printf("Falling back to patching base and 3-way merge...\n");
+
+ if (*old_index)
+ setenv(INDEX_ENVIRONMENT, old_index, 1);
+ else
+ unsetenv(INDEX_ENVIRONMENT);
+ if (!system(mkpath("git-merge-resolve %s -- HEAD %s", orig_tree, his_tree)))
+ return 0;
+ }
+ }
+#else
+ unsigned char orig_tree[20], his_tree[20];
+
+ // We need a way to switch the index file on the fly for this to work
+
+ char *opts[] = { "git-apply", "--allow-binary-replacement", "--cached", NULL, NULL };
+ char **opt = &opts[0];
+ char patch[PATH_MAX];
+ int optc = ARRAY_SIZE(opts) - 1;
+
+ opts[optc - 1] = strncpy(patch, mkpath("%s/patch", dotest), sizeof(patch));
+ if (!binary) {
+ opts[1] = "git-apply";
+ opt++; optc--;
+ }
+ write_tree(orig_tree, 0, NULL);
+ if (!cmd_apply(optc, (const char**)opt, env)) {
+ printf("Using index info to reconstruct a base tree...\n");
+ write_tree(his_tree, 0, NULL);
+
+ snprintf(cmd, sizeof(cmd), "git-merge-resolve %s -- HEAD %s", sha1_to_hex(orig_tree),
+ sha1_to_hex(his_tree));
+ ret = system(cmd);
+ }
+ }
+ if (*old_index)
+ setenv(INDEX_ENVIRONMENT, old_index, 1);
+ else
+ unsetenv(INDEX_ENVIRONMENT);
+#endif
+ if (!ret)
+ return 0;
+ }
+ if (!access(mkpath("%s/rr-cache/.", get_git_dir()), F_OK))
+ system("git-rerere");
+ die("Failed to merge in the changes.");
+}
+
+static int go_interactive(void)
+{
+ int action = AGAIN;
+
+ if (!isatty(0))
+ die("Cannot be interactive without stdin connected to a terminal.");
+
+ while (action == AGAIN) {
+ char line[1000];
+ FILE *cmt;
+
+ printf("Commit Body is:\n--------------------------\n");
+ cmt = fopen(mkpath("%s/final-commit", dotest), "r");
+ while (fgets(line, sizeof(line), cmt))
+ fputs(line, stdout);
+ fclose(cmt);
+ printf("--------------------------\nApply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all ");
+
+ fgets(line, sizeof(line), stdin);
+ switch (line[0]) {
+ case 'y':
+ case 'Y':
+ action = YES;
+ break;
+ case 'a':
+ case 'A':
+ action = YES;
+ interactive = 0;
+ break;
+ case 'n':
+ case 'N':
+ action = SKIP;
+ break;
+ case 'e':
+ case 'E':
+ system(mkpath("\"${VISUAL:-${EDITOR:-vi}}\" \"%s/final-commit\"", dotest));
+ action = AGAIN;
+ break;
+ case 'v':
+ case 'V':
+ system(mkpath("LESS=-S ${PAGER:-less} \"%s/patch\"", dotest));
+ action = AGAIN;
+ break;
+ default:
+ action = AGAIN;
+ break;
+ }
+ }
+ return action;
+}
+
+static int commit(char *subject)
+{
+ unsigned char sha1[20];
+ char commit[41], parent[41], cmd[1000];
+ FILE *f;
+ int status;
+
+ if (!write_tree(sha1, 0, NULL)) {
+ printf("Wrote tree %s\n", sha1_to_hex(sha1));
+ f = get_output("git-rev-parse --verify HEAD", &status);
+ if (!status) {
+ fgets(parent, 41, f);
+ fclose(f);
+ snprintf(cmd, sizeof(cmd), "git-commit-tree %s -p %s <\"%s/final-commit\"",
+ sha1_to_hex(sha1), parent, dotest);
+ f = get_output(cmd, &status);
+ if (!status) {
+ //git-update-ref -m "am: $SUBJECT" HEAD $commit $parent
+ char *opts[] = { "git-update-ref", "-m", NULL, "HEAD", NULL, NULL, NULL };
+ const char **opt = (const char**)&opts[0];
+ fgets(commit, 41, f);
+ fclose(f);
+ printf("Committed: %s\n", commit);
+ snprintf(cmd, sizeof(cmd), "am: %s", subject);
+ opts[2] = cmd;
+ opts[4] = commit;
+ opts[5] = parent;
+ if (!cmd_update_ref(ARRAY_SIZE(opts) - 1, opt, env))
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+int cmd_am(int argc, const char **argv, char **envp)
+{
+ int i, this, last, apply_status, action;
+ char sign[1000] = "";
+
+ env = envp;
+
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
+
+ if (arg[0] != '-')
+ break;
+ if (!strcmp(arg, "--")) {
+ i++;
+ break;
+ }
+ if (!strcmp(arg, "-i") || !strcmp(arg, "--interactive")) {
+ interactive = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-b") || !strcmp(arg, "--binary")) {
+ binary = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-3") || !strcmp(arg, "--3way")) {
+ threeway = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-s") || !strcmp(arg, "--signoff")) {
+ signoff = 1;
+ continue;
+ }
+ if (!strcmp(arg, "--skip")) {
+ skip = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-u") || !strcmp(arg, "--utf8")) {
+ utf8 = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-k") || !strcmp(arg, "--keep")) {
+ keep_subject = 1;
+ continue;
+ }
+ if (!strcmp(arg, "-r") || !strcmp(arg, "--resolved")) {
+ resolved = 1;
+ continue;
+ }
+ if (!strncmp(arg, "--whitespace=", 13)) {
+ strncpy(whitespace, arg, sizeof(whitespace));
+ continue;
+ }
+ if (!strncmp(arg, "--resolvemsg=", 13)) {
+ resolvmsg = arg + 13;
+ continue;
+ }
+ if (!strncmp(arg, "--dotest", 8)) {
+ if (arg[8] == '=')
+ dotest = arg + 9;
+ else {
+ i++;
+ if (argv[i] == NULL)
+ die(builtin_am_usage);
+ dotest = argv[i];
+ }
+ continue;
+ }
+ usage(builtin_am_usage);
+ }
+ mbox = argv + i;
+
+ if (!dotest)
+ dotest = ".dotest";
+
+ /* Cleanup old .dotest */
+ if (mbox && !access(dotest, F_OK))
+ if (fcat("next", "%d", &this) && fcat("last", "%d", &last))
+ if (this > last)
+ rm_rf(dotest);
+
+ if (!access(dotest, F_OK)) {
+ if (mbox != NULL)
+ die("previous dotest directory \"%s\" still exists but mbox given.", dotest);
+ resume = 1;
+ } else {
+ if (skip || resolved)
+ die("Resolve operation not in progress, we are not resuming.");
+
+ if (mkdir_p(dotest))
+ die("Unable to create directory %s.", dotest);
+
+ if ((last = split_mbox(mbox, dotest, 1 /*allow bare*/, PATCH_PREC, 0 /*skip*/)) == -1) {
+ rm_rf(dotest);
+ die("split_mbox failed");
+ }
+
+ /*
+ -b, -s, -u, -k and --whitespace flags are kept for the
+ resuming session after a patch failure.
+ -3 and -i can and must be given when resuming.
+ */
+ fecho("binary", "%d\n", binary);
+ fecho("whitespace", "%s\n", whitespace);
+ fecho("sign", "%d\n", signoff);
+ fecho("utf8", "%d\n", utf8);
+ fecho("keep", "%d\n", keep_subject);
+ fecho("next", "%d\n", 1);
+ fecho("last", "%d\n", last);
+ }
+
+ if (!resolved) {
+ /* Make sure we have a clean index */
+ char buf[PATH_MAX];
+ int status = 0;
+ FILE *f;
+
+ if ((f = get_output("git-diff-index --name-only HEAD", &status)) == NULL || status)
+ die("Command: \"git-diff-index --name-only HEAD\" failed");
+
+ if ((status = fgetc(f)) != EOF) {
+ ungetc(status, f);
+ fprintf(stderr, "Dirty index: cannot apply patches. Dirty files:\n");
+ while (fgets(buf, sizeof(buf), f))
+ fprintf(stderr, "%s", buf);
+ return 1;
+ }
+ fclose(f);
+ }
+
+ /* Read back saved state */
+ fcat("binary", "%d", &binary);
+ fcat("utf8", "%d", &utf8);
+ fcat("keep", "%d", &keep_subject);
+ fcat("whitespace", "%40[^\n]", whitespace);
+ fcat("sign", "%d", &signoff);
+ fcat("last", "%d", &last);
+ fcat("next", "%d", &this);
+
+ if (this > last) {
+ printf("Nothing to do.\n");
+ rm_rf(dotest);
+ return 0;
+ }
+
+ if (signoff) {
+ int off = snprintf(sign, sizeof(sign), "Signed-off-by: %s <%s>",
+ getenv("GIT_COMMITTER_NAME"), getenv("GIT_COMMITTER_EMAIL"));
+ if (off > sizeof(sign))
+ die ("Impossibly long committer identifier");
+ }
+
+ if (skip) {
+ this++;
+ resume = 0;
+ }
+
+ while (this <= last) {
+ char patch_no[PATCH_PREC + 1];
+ char name[1000];
+ char email[1000];
+ char date[1000];
+ char s[1000] = "[PATCH] ", *subject = &s[0];
+
+ snprintf(patch_no, sizeof(patch_no), "%0*d", PATCH_PREC, this);
+
+ if (access(mkpath("%s/%s", dotest, patch_no), F_OK)) {
+ resume = 0;
+ this = go_next(this);
+ continue;
+ }
+
+ /*
+ If we are not resuming, parse and extract the patch information
+ into separate files:
+ - info records the authorship and title
+ - msg is the rest of commit log message
+ - patch is the patch body.
+
+ When we are resuming, these files are either already prepared
+ by the user, or the user can tell us to do so by --resolved flag.
+ */
+ if (!resume) {
+ FILE *out, *in;
+ char msg_path[PATH_MAX];
+
+ if ((out = fopen(mkpath("%s/info", dotest), "w")) == NULL) {
+ perror(mkpath("%s/info", dotest));
+ die("fopen failed");
+ }
+ if ((in = fopen(mkpath("%s/%s", dotest, patch_no), "r")) == NULL) {
+ perror(mkpath("%s/%s", dotest, patch_no));
+ die("fopen failed");
+ }
+
+ snprintf(msg_path, sizeof(msg_path), "%s/msg", dotest);
+ if (mailinfo(in, out, keep_subject, utf8 ? git_commit_encoding : NULL,
+ msg_path, mkpath("%s/patch",dotest)))
+ stop_here(this);
+ fclose(in);
+ fclose(out);
+
+ in = fopen(msg_path, "r");
+ out = fopen(mkpath("%s/msg-clean", dotest), "w");
+ stripspace(in, out);
+ fclose(in);
+ fclose(out);
+ }
+
+ fcat("info", "Author: %1000[^\n]\nEmail: %1000s\n"
+ "Subject: %992[^\n]\nDate: %1000[^\n]\n\n",
+ name, email, subject + 8 /*[PATCH] */, date);
+
+ if (!keep_subject)
+ subject = subject + 8; /*[PATCH] */
+
+ if (email == NULL || !strcmp(email, "")) {
+ printf("Patch does not have a valid e-mail address.\n");
+ stop_here(this);
+ }
+
+ if (!resume) { /* Prepare the commit-message and the patch */
+ char c, *t;
+ char line[1000];
+ char last_signoff[1000] = "";
+ FILE *cmt, *msg;
+
+ /* Find the last Signed-off line */
+ msg = fopen(mkpath("%s/msg-clean", dotest), "r");
+ while ((fgets(line, sizeof(line), msg))) {
+ if ((t = strstr(line, "Signed-off-by: ")))
+ strncpy(last_signoff, t, sizeof(last_signoff));
+ }
+ if ((t = strrchr(last_signoff, '>')))
+ *++t = '\0';
+
+ /* Write the commit-mesage */
+ cmt = fopen(mkpath("%s/final-commit", dotest), "w");
+ fprintf(cmt, "%s\n", subject);
+
+ rewind(msg);
+ if ((c = fgetc(msg)) != EOF) {
+ fprintf(cmt, "\n");
+ ungetc(c, msg);
+ }
+ while (fgets(line, sizeof(line), msg))
+ fputs(line, cmt);
+
+ /* Add a signoff */
+ if (signoff && strcmp(last_signoff, sign)) {
+ if (!strcmp(last_signoff, ""))
+ fputc('\n', cmt);
+ fputs(sign, cmt);
+ }
+ fclose(cmt);
+ fclose(msg);
+ } else
+ if (resolved && interactive)
+ /* This is used only for interactive view option. */
+ system(mkpath("git-diff-index -p --cached HEAD >\"%s/patch\"", dotest));
+
+ resume = 0;
+ if (interactive)
+ action = go_interactive();
+ else
+ action = YES;
+
+ if (action == SKIP) {
+ this = go_next(this);
+ continue;
+ }
+
+ if (!access(mkpath("%s/hooks/applypatch-msg", get_git_dir()), X_OK))
+ if (system(mkpath("%s/hooks/applypatch-msg %s/final-commit", get_git_dir(), dotest)))
+ stop_here(this);
+
+ printf("\nApplying %s\n\n", subject);
+
+ if (!resolved) {
+ /*git-apply $binary --index $ws "$dotest/patch" */
+ char patch[PATH_MAX];
+ char *opts[6] = { "git-apply", "--allow-binary-replacement", "--index", NULL, NULL, NULL };
+ char **opt = &opts[0];
+ int optc = 5;
+
+ if (!binary) {
+ opts[1] = "git-apply";
+ opt++; optc--;
+ }
+ opts[3] = whitespace;
+ snprintf(patch, sizeof(patch), "%s/patch", dotest);
+ opts[4] = patch;
+ apply_status = cmd_apply(optc, (const char**)opt, envp);
+ } else {
+ /* Resolved means the user did all the hard work, and
+ we do not have to do any patch application. Just
+ trust what the user has in the index file and the
+ working tree.*/
+ resolved = 0;
+
+ if (has_zero_output("git-diff-index --cached --name-only HEAD")) {
+ printf("No changes - did you forget update-index?\n");
+ stop_here_user_resolve(this);
+ }
+ if (!has_zero_output("git-ls-files -u")) {
+ printf("You still have unmerged paths in your index,\n"
+ "did you forget update-index?");
+ stop_here_user_resolve(this);
+ }
+ apply_status = 0;
+ }
+
+ if (apply_status && threeway) {
+ fall_back_3way();
+ /* Applying the patch to an earlier tree and merging the
+ result may have produced the same tree as ours. */
+ if (has_zero_output("git-diff-index --cached --name-only HEAD")) {
+ printf("No changes -- Patch already applied.\n");
+ this = go_next(this);
+ continue;
+ }
+ /* We have merged successfully */
+ apply_status = 0;
+ }
+
+ if (apply_status) {
+ printf("Patch failed at %s\n.", patch_no);
+ stop_here_user_resolve(this);
+ }
+
+ if (!access(mkpath("%s/hooks/pre-applypatch", get_git_dir()), X_OK))
+ if (system(mkpath("%s/hooks/pre-applypatch", get_git_dir())))
+ stop_here(this);
+
+ if (commit(subject) == -1)
+ stop_here(this);
+
+ if (!access(mkpath("%s/hooks/post-applypatch", get_git_dir()), X_OK))
+ system(mkpath("%s/hooks/post-applypatch", get_git_dir()));
+
+ this = go_next(this);
+ }
+ rm_rf(dotest);
+ return 0;
+}
diff --git a/builtin.h b/builtin.h
index c1f3395..8771e36 100644
--- a/builtin.h
+++ b/builtin.h
@@ -49,6 +49,7 @@ extern int cmd_cat_file(int argc, const
extern int cmd_rev_parse(int argc, const char **argv, char **envp);
extern int cmd_update_index(int argc, const char **argv, char **envp);
extern int cmd_update_ref(int argc, const char **argv, char **envp);
+extern int cmd_am(int argc, const char **argv, char **envp);
extern int cmd_write_tree(int argc, const char **argv, char **envp);
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
diff --git a/git-am.sh b/git-am.sh
deleted file mode 100755
index 4232e27..0000000
--- a/git-am.sh
+++ /dev/null
@@ -1,427 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2005, 2006 Junio C Hamano
-
-USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way]
- [--interactive] [--whitespace=<option>] <mbox>...
- or, when resuming [--skip | --resolved]'
-. git-sh-setup
-
-git var GIT_COMMITTER_IDENT >/dev/null || exit
-
-stop_here () {
- echo "$1" >"$dotest/next"
- exit 1
-}
-
-stop_here_user_resolve () {
- if [ -n "$resolvemsg" ]; then
- echo "$resolvemsg"
- stop_here $1
- fi
- cmdline=$(basename $0)
- if test '' != "$interactive"
- then
- cmdline="$cmdline -i"
- fi
- if test '' != "$threeway"
- then
- cmdline="$cmdline -3"
- fi
- if test '.dotest' != "$dotest"
- then
- cmdline="$cmdline -d=$dotest"
- fi
- echo "When you have resolved this problem run \"$cmdline --resolved\"."
- echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
-
- stop_here $1
-}
-
-go_next () {
- rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \
- "$dotest/patch" "$dotest/info"
- echo "$next" >"$dotest/next"
- this=$next
-}
-
-fall_back_3way () {
- O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
-
- rm -fr "$dotest"/patch-merge-*
- mkdir "$dotest/patch-merge-tmp-dir"
-
- # First see if the patch records the index info that we can use.
- if git-apply -z --index-info "$dotest/patch" \
- >"$dotest/patch-merge-index-info" 2>/dev/null &&
- GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
- GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git-write-tree >"$dotest/patch-merge-base+" &&
- # index has the base tree now.
- GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git-apply $binary --cached <"$dotest/patch"
- then
- echo Using index info to reconstruct a base tree...
- mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
- mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
- fi
-
- test -f "$dotest/patch-merge-index" &&
- his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git-write-tree) &&
- orig_tree=$(cat "$dotest/patch-merge-base") &&
- rm -fr "$dotest"/patch-merge-* || exit 1
-
- echo Falling back to patching base and 3-way merge...
-
- # This is not so wrong. Depending on which base we picked,
- # orig_tree may be wildly different from ours, but his_tree
- # has the same set of wildly different changes in parts the
- # patch did not touch, so resolve ends up cancelling them,
- # saying that we reverted all those changes.
-
- git-merge-resolve $orig_tree -- HEAD $his_tree || {
- if test -d "$GIT_DIR/rr-cache"
- then
- git-rerere
- fi
- echo Failed to merge in the changes.
- exit 1
- }
-}
-
-prec=4
-dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg=
-
-while case "$#" in 0) break;; esac
-do
- case "$1" in
- -d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
- dotest=`expr "$1" : '-[^=]*=\(.*\)'`; shift ;;
- -d|--d|--do|--dot|--dote|--dotes|--dotest)
- case "$#" in 1) usage ;; esac; shift
- dotest="$1"; shift;;
-
- -i|--i|--in|--int|--inte|--inter|--intera|--interac|--interact|\
- --interacti|--interactiv|--interactive)
- interactive=t; shift ;;
-
- -b|--b|--bi|--bin|--bina|--binar|--binary)
- binary=t; shift ;;
-
- -3|--3|--3w|--3wa|--3way)
- threeway=t; shift ;;
- -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
- sign=t; shift ;;
- -u|--u|--ut|--utf|--utf8)
- utf8=t; shift ;;
- -k|--k|--ke|--kee|--keep)
- keep=t; shift ;;
-
- -r|--r|--re|--res|--reso|--resol|--resolv|--resolve|--resolved)
- resolved=t; shift ;;
-
- --sk|--ski|--skip)
- skip=t; shift ;;
-
- --whitespace=*)
- ws=$1; shift ;;
-
- --resolvemsg=*)
- resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;;
-
- --)
- shift; break ;;
- -*)
- usage ;;
- *)
- break ;;
- esac
-done
-
-# If the dotest directory exists, but we have finished applying all the
-# patches in them, clear it out.
-if test -d "$dotest" &&
- last=$(cat "$dotest/last") &&
- next=$(cat "$dotest/next") &&
- test $# != 0 &&
- test "$next" -gt "$last"
-then
- rm -fr "$dotest"
-fi
-
-if test -d "$dotest"
-then
- test ",$#," = ",0," ||
- die "previous dotest directory $dotest still exists but mbox given."
- resume=yes
-else
- # Make sure we are not given --skip nor --resolved
- test ",$skip,$resolved," = ,,, ||
- die "Resolve operation not in progress, we are not resuming."
-
- # Start afresh.
- mkdir -p "$dotest" || exit
-
- git-mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
- rm -fr "$dotest"
- exit 1
- }
-
- # -b, -s, -u, -k and --whitespace flags are kept for the
- # resuming session after a patch failure.
- # -3 and -i can and must be given when resuming.
- echo "$binary" >"$dotest/binary"
- echo " $ws" >"$dotest/whitespace"
- echo "$sign" >"$dotest/sign"
- echo "$utf8" >"$dotest/utf8"
- echo "$keep" >"$dotest/keep"
- echo 1 >"$dotest/next"
-fi
-
-case "$resolved" in
-'')
- files=$(git-diff-index --cached --name-only HEAD) || exit
- if [ "$files" ]; then
- echo "Dirty index: cannot apply patches (dirty: $files)" >&2
- exit 1
- fi
-esac
-
-if test "$(cat "$dotest/binary")" = t
-then
- binary=--allow-binary-replacement
-fi
-if test "$(cat "$dotest/utf8")" = t
-then
- utf8=-u
-fi
-if test "$(cat "$dotest/keep")" = t
-then
- keep=-k
-fi
-ws=`cat "$dotest/whitespace"`
-if test "$(cat "$dotest/sign")" = t
-then
- SIGNOFF=`git-var GIT_COMMITTER_IDENT | sed -e '
- s/>.*/>/
- s/^/Signed-off-by: /'
- `
-else
- SIGNOFF=
-fi
-
-last=`cat "$dotest/last"`
-this=`cat "$dotest/next"`
-if test "$skip" = t
-then
- this=`expr "$this" + 1`
- resume=
-fi
-
-if test "$this" -gt "$last"
-then
- echo Nothing to do.
- rm -fr "$dotest"
- exit
-fi
-
-while test "$this" -le "$last"
-do
- msgnum=`printf "%0${prec}d" $this`
- next=`expr "$this" + 1`
- test -f "$dotest/$msgnum" || {
- resume=
- go_next
- continue
- }
-
- # If we are not resuming, parse and extract the patch information
- # into separate files:
- # - info records the authorship and title
- # - msg is the rest of commit log message
- # - patch is the patch body.
- #
- # When we are resuming, these files are either already prepared
- # by the user, or the user can tell us to do so by --resolved flag.
- case "$resume" in
- '')
- git-mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
- <"$dotest/$msgnum" >"$dotest/info" ||
- stop_here $this
- git-stripspace < "$dotest/msg" > "$dotest/msg-clean"
- ;;
- esac
-
- GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
- GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
- GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
-
- if test -z "$GIT_AUTHOR_EMAIL"
- then
- echo "Patch does not have a valid e-mail address."
- stop_here $this
- fi
-
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
-
- SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
- case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
-
- case "$resume" in
- '')
- if test '' != "$SIGNOFF"
- then
- LAST_SIGNED_OFF_BY=`
- sed -ne '/^Signed-off-by: /p' \
- "$dotest/msg-clean" |
- tail -n 1
- `
- ADD_SIGNOFF=`
- test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
- test '' = "$LAST_SIGNED_OFF_BY" && echo
- echo "$SIGNOFF"
- }`
- else
- ADD_SIGNOFF=
- fi
- {
- echo "$SUBJECT"
- if test -s "$dotest/msg-clean"
- then
- echo
- cat "$dotest/msg-clean"
- fi
- if test '' != "$ADD_SIGNOFF"
- then
- echo "$ADD_SIGNOFF"
- fi
- } >"$dotest/final-commit"
- ;;
- *)
- case "$resolved$interactive" in
- tt)
- # This is used only for interactive view option.
- git-diff-index -p --cached HEAD >"$dotest/patch"
- ;;
- esac
- esac
-
- resume=
- if test "$interactive" = t
- then
- test -t 0 ||
- die "cannot be interactive without stdin connected to a terminal."
- action=again
- while test "$action" = again
- do
- echo "Commit Body is:"
- echo "--------------------------"
- cat "$dotest/final-commit"
- echo "--------------------------"
- printf "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "
- read reply
- case "$reply" in
- [yY]*) action=yes ;;
- [aA]*) action=yes interactive= ;;
- [nN]*) action=skip ;;
- [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit"
- action=again ;;
- [vV]*) action=again
- LESS=-S ${PAGER:-less} "$dotest/patch" ;;
- *) action=again ;;
- esac
- done
- else
- action=yes
- fi
-
- if test $action = skip
- then
- go_next
- continue
- fi
-
- if test -x "$GIT_DIR"/hooks/applypatch-msg
- then
- "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
- stop_here $this
- fi
-
- echo
- echo "Applying '$SUBJECT'"
- echo
-
- case "$resolved" in
- '')
- git-apply $binary --index $ws "$dotest/patch"
- apply_status=$?
- ;;
- t)
- # Resolved means the user did all the hard work, and
- # we do not have to do any patch application. Just
- # trust what the user has in the index file and the
- # working tree.
- resolved=
- changed="$(git-diff-index --cached --name-only HEAD)"
- if test '' = "$changed"
- then
- echo "No changes - did you forget update-index?"
- stop_here_user_resolve $this
- fi
- unmerged=$(git-ls-files -u)
- if test -n "$unmerged"
- then
- echo "You still have unmerged paths in your index"
- echo "did you forget update-index?"
- stop_here_user_resolve $this
- fi
- apply_status=0
- ;;
- esac
-
- if test $apply_status = 1 && test "$threeway" = t
- then
- if (fall_back_3way)
- then
- # Applying the patch to an earlier tree and merging the
- # result may have produced the same tree as ours.
- changed="$(git-diff-index --cached --name-only HEAD)"
- if test '' = "$changed"
- then
- echo No changes -- Patch already applied.
- go_next
- continue
- fi
- # clear apply_status -- we have successfully merged.
- apply_status=0
- fi
- fi
- if test $apply_status != 0
- then
- echo Patch failed at $msgnum.
- stop_here_user_resolve $this
- fi
-
- if test -x "$GIT_DIR"/hooks/pre-applypatch
- then
- "$GIT_DIR"/hooks/pre-applypatch || stop_here $this
- fi
-
- tree=$(git-write-tree) &&
- echo Wrote tree $tree &&
- parent=$(git-rev-parse --verify HEAD) &&
- commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") &&
- echo Committed: $commit &&
- git-update-ref -m "am: $SUBJECT" HEAD $commit $parent ||
- stop_here $this
-
- if test -x "$GIT_DIR"/hooks/post-applypatch
- then
- "$GIT_DIR"/hooks/post-applypatch
- fi
-
- go_next
-done
-
-rm -fr "$dotest"
diff --git a/git.c b/git.c
index 652e3c4..b9261e4 100644
--- a/git.c
+++ b/git.c
@@ -184,7 +184,8 @@ static void handle_internal_command(int
{ "mailinfo", cmd_mailinfo },
{ "stripspace", cmd_stripspace },
{ "update-index", cmd_update_index },
- { "update-ref", cmd_update_ref }
+ { "update-ref", cmd_update_ref },
+ { "am", cmd_am }
};
int i;
--
1.4.0
^ permalink raw reply related
* Re: git-cvsimport doesn't quite work, wrt branches
From: Yann Dirson @ 2006-06-13 21:13 UTC (permalink / raw)
To: Linus Torvalds
Cc: Jim Meyering, Git Mailing List, Matthias Urlichs, Pavel Roskin
In-Reply-To: <Pine.LNX.4.64.0606131008470.5498@g5.osdl.org>
On Tue, Jun 13, 2006 at 10:20:10AM -0700, Linus Torvalds wrote:
> Sadly, it also seems to be one that isn't fixed by the patches _I_ have,
> and looking at Yann's set of patches, I don't think they fix it either.
I don't think so either.
> So CVSps basically tells git-cvsimport that commit 2 (on branch B) is
> based on commit 1, and doesn't say that "on-trunk" has gone away, so the
> resulting git repository has branch B containing "on-trunk" version 1.1,
> and "on-br" version 1.1.2.1.
>
> CVS branches obviously sometimes confuse CVSps. Sadly, they also confuse
> _me_, so I don't see how to fix this particular CVSps bug, because I'm as
> confused as CVSps is ;)
>
> We'd need to have CVSps tell git that the "on-trunk" file was never added
> to branch B: the simplest way to do that would be to say that it has
> become (DEAD) in PatchSet 2 (which is not technically true in CVS terms,
> but _is_ technically true on git terms - on branch B, that file is
> obviously dead).
>
> Yann? Pavel? Anybody? Ideas?
This is exactly the problem I encountered one week ago with one my old
cvs repos, where I had created a branch only for a part of a source
hierarchy :)
One thing that amused me, is that in that case cvsps was DWIM enough
that the result was indeed what I expected from the conversion (I had
forgotten about the particular way that branch was created 3 years
ago). I only discovered the problem when tailor's cvs backend
generated deletions when starting my branch.
So basically, because of how awkward cvs branches are, cvsps may
indeed do what many users expect here, because branches in cvs repos
are sometimes created in strange ways, (in my case, to avoid having to
merge changes in unrelevant areas of the tree - nowadays, I'd just use
stgit to isolate changes).
I don't know what was the particular thing in coreutils developement
that led to branching only some files. In my case, it can be seen as
the cvs idiom for "branching a part of the tree" - something I don't
think there is a need to have a special idiom in GIT for.
If we want cvsps to output the exact history derived from cvs
(ie. what Jim expected, and I think it is reasonable), I fear it would
require substential modification to cvsps. I should check, but I
don't think it currently keeps track of which files are part of the
tree resulting from a changeset, but only of the files actually touhed
by the changeset. So the change would probably have a big ram
usage impact, if we store the file refs in each changeset.
That reminds me of another funny cs behaviour I noticed a couple of
months ago (not sure if it was in 1.11.x or 1.12.x): "cvs import" was
not marking files as dead on the vendor branch when it disappeared
from one upstream version to another, it was just not tagged in the
new version. I guess cvsps would have a hard time figuring out what
happenned, and would just mark the taks as invalid.
For this type of cvsps issues and cvs tags in general, my latest idea
would be to add "fake" patchsets on which to apply tags and
branchpoints. The ideal way would seem to make those similar to git's
merge commits, having as parents all patchsets the tag takes revision
from (obviously it's so biased towards the git model it would be a
pleasure to add support for this in git-cvsimport :) - but that would
produce patchsets not fitting well into the current cvsps model, so
that may require more thinking.
Anyway, it should provide a way to make sense out of what cvsps
currently considers to be "invalid" tags.
Best regards,
--
Yann Dirson <ydirson@altern.org> |
Debian-related: <dirson@debian.org> | Support Debian GNU/Linux:
| Freedom, Power, Stability, Gratis
http://ydirson.free.fr/ | Check <http://www.debian.org/>
^ permalink raw reply
* [BUG] stgit branch renaming into new dir crashes
From: Yann Dirson @ 2006-06-13 21:40 UTC (permalink / raw)
To: Catalin Marinas; +Cc: GIT list
When trying to rename a branch to a name including a slash, there is
no explicit creation of leading dirs, and stgit crashes:
$ stg branch -r multitag dev/multitag
Traceback (most recent call last):
File "/usr/bin/stg", line 43, in ?
main()
File "/usr/lib/python2.3/site-packages/stgit/main.py", line 187, in main
command.func(parser, options, args)
File "/usr/lib/python2.3/site-packages/stgit/commands/branch.py", line 214, in func
stack.Series(args[0]).rename(args[1])
File "/usr/lib/python2.3/site-packages/stgit/stack.py", line 497, in rename
os.rename(self.__series_dir, to_stack.__series_dir)
OSError: [Errno 2] No such file or directory
--
Yann Dirson <ydirson@altern.org> |
Debian-related: <dirson@debian.org> | Support Debian GNU/Linux:
| Freedom, Power, Stability, Gratis
http://ydirson.free.fr/ | Check <http://www.debian.org/>
^ permalink raw reply
* Re: [PATCH 0/8] Make a couple of commands builtin
From: Timo Hirvonen @ 2006-06-13 21:54 UTC (permalink / raw)
To: lukass; +Cc: junkio, git
In-Reply-To: <448F1E41.1040607@etek.chalmers.se>
Lukas Sandström <lukass@etek.chalmers.se> wrote:
> This patchseries has the ultimate goal of making
> git-am a builtin.
>
> The version of git-am I'm sending out makes quite heavy
> use of system(), but I think that can be worked around.
> I just haven't figured out how, yet.
I don't think git-stripspace needs to be a built-in. It doesn't even
depend on git. It is just a tiny helper program used by git-am,
git-applymbox, git-commit and git-tag. If all these commands are made
built-in then git-stripspace becomes useless.
--
http://onion.dynserv.net/~timo/
^ permalink raw reply
* Re: [PATCH 0/8] Make a couple of commands builtin
From: Lukas Sandström @ 2006-06-13 22:03 UTC (permalink / raw)
To: Timo Hirvonen; +Cc: junkio, git, Lukas Sandström
In-Reply-To: <20060614005437.69ff6a62.tihirvon@gmail.com>
Timo Hirvonen wrote:
> Lukas Sandström <lukass@etek.chalmers.se> wrote:
>
>> This patchseries has the ultimate goal of making
>> git-am a builtin.
>>
>> The version of git-am I'm sending out makes quite heavy
>> use of system(), but I think that can be worked around.
>> I just haven't figured out how, yet.
>
> I don't think git-stripspace needs to be a built-in. It doesn't even
> depend on git. It is just a tiny helper program used by git-am,
> git-applymbox, git-commit and git-tag. If all these commands are made
> built-in then git-stripspace becomes useless.
>
The reason I made it builtin was to de able to call it easily from git-am.
As you say, once all the users are builtin it could be removed, unless somone
is using it in their scripts.
/Lukas
^ permalink raw reply
* Re: git-cvsimport doesn't quite work, wrt branches
From: Martin Langhoff @ 2006-06-13 22:55 UTC (permalink / raw)
To: Keith Packard
Cc: Linus Torvalds, Jim Meyering, Git Mailing List, Matthias Urlichs,
Yann Dirson, Pavel Roskin
In-Reply-To: <1150224411.20536.79.camel@neko.keithp.com>
On 6/14/06, Keith Packard <keithp@keithp.com> wrote:
> cvs rlog is designed to 'represent' the history of the repository to
> users. Cvsps was built as a software analysis tool, and is used by
> putative software engineering researchers. Basing a supposedly lossless
> repository conversion system on this pair seems foolish to me,
> notwithstanding the heroic efforts to make it work.
Yes, cvsps is relying on the wrong things. I am looking at parsecvs
and the cvs2svn tool and wondering where to from here.
In terms of history parsing, parsecvs and cvs2svn are similar. I like
cvs2svn "many passes" approach better, though the Python source is
really messy. A good thing about cvs2svn is that it is a lot more
conservative WRT memory use.
So far, I have been relying on parsecvs for initial imports, and for
cvsps+git-cvsimport for incrementals on top of that initial import.
But parsecvs falls over with large repos.
I am starting to look at what I can do with cvs2svn to get the import
into git. It seems to get very good patchsets, and it yields an easily
readable DB. I'll either learn Python, or read the DB from Perl
(probably from git-cvsimport).
The main problem, however, is that it doesn't do incremental imports,
so this would be a roundabout way of fixing parsecvs's
memory-bound-ness. We still need cvsps :(
martin
^ permalink raw reply
* Re: git-cvsimport doesn't quite work, wrt branches
From: Keith Packard @ 2006-06-13 23:30 UTC (permalink / raw)
To: Martin Langhoff
Cc: keithp, Linus Torvalds, Jim Meyering, Git Mailing List,
Matthias Urlichs, Yann Dirson, Pavel Roskin
In-Reply-To: <46a038f90606131555m7b1fa744g9770140c87598b7b@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]
On Wed, 2006-06-14 at 10:55 +1200, Martin Langhoff wrote:
> In terms of history parsing, parsecvs and cvs2svn are similar. I like
> cvs2svn "many passes" approach better, though the Python source is
> really messy. A good thing about cvs2svn is that it is a lot more
> conservative WRT memory use.
I will try to fix parsecvs so it doesn't take so much memory. Of course,
my goal was to import various X.org repositories which have horrible
issues, but aren't all that huge. And, for them, it works just fine.
> So far, I have been relying on parsecvs for initial imports, and for
> cvsps+git-cvsimport for incrementals on top of that initial import.
> But parsecvs falls over with large repos.
I'd like some help figuring out how to do incremental imports with
parsecvs. As parsecvs already constructs the project history from the
present into the past, it should be possible to "notice" when it hits
existing bits in the repository and stop automatically. I think this
will just take saving a bit of state in the git repository to mark where
in CVS the tips of each branch come from.
> The main problem, however, is that it doesn't do incremental imports,
> so this would be a roundabout way of fixing parsecvs's
> memory-bound-ness. We still need cvsps :(
Parsecvs is currently O(nrev * nfile), and I'd like to make it O(nrev)
instead.
--
keith.packard@intel.com
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply
* oprofile on svn import
From: Jon Smirl @ 2006-06-14 1:10 UTC (permalink / raw)
To: git
I'm going back to cvsimport tomorrow. My svn import that had been
running for five days got killed this morning when the city decided to
move the telephone pole that provides my electricty.
Some oprofile data, this doesn't make a lot of sense to me. Why is it
in libcypto so much?
12632739 30.6077 /lib/libcrypto.so.0.9.8a
11762639 28.4995 /home/good/vmlinux
6310191 15.2889 /lib/libc-2.4.so
2498812 6.0543 /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so
2079975 5.0395 /usr/local/bin/git-update-index
1103116 2.6727 /usr/lib/libz.so.1.2.3
617395 1.4959 /usr/lib/libapr-1.so.0.2.2
484625 1.1742 /usr/local/bin/git-read-tree
kernel breakdown
2035561 16.4450 copy_page_range
1110813 8.9741 get_page_from_freelist
851064 6.8756 check_poison_obj
759296 6.1342 unmap_vmas
670659 5.4181 release_pages
667657 5.3939 page_remove_rmap
595826 4.8136 page_fault
241962 1.9548 __copy_from_user_ll
185876 1.5017 do_wp_page
176506 1.4260 do_page_fault
I reset the statistics and took another snapshot half an hour later.
2232310 44.3485 /home/good/vmlinux
757114 15.0413 /lib/libcrypto.so.0.9.8a
507282 10.0780 /lib/libc-2.4.so
203440 4.0417 /usr/lib/libz.so.1.2.3
179105 3.5582 /usr/lib/libapr-1.so.0.2.2
169724 3.3718 /usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so
114384 2.2724 /usr/local/bin/git-update-index
102350 2.0334 /usr/lib/libsvn_subr-1.so.0.0.0
74673 1.4835 /usr/lib/libaprutil-1.so.0.2.2
69987 1.3904 /usr/lib/libsvn_fs_fs-1.so.0.0.0
Kernel:
543264 21.2518 copy_page_range
243383 9.5208 check_poison_obj
227788 8.9108 unmap_vmas
161806 6.3296 page_remove_rmap
153201 5.9930 release_pages
119092 4.6587 page_fault
100116 3.9164 get_page_from_freelist
45014 1.7609 do_wp_page
42130 1.6481 vm_normal_page
34804 1.3615 poison_obj
28231 1.1044 do_page_fault
27403 1.0720 __handle_mm_fault
24558 0.9607 __copy_to_user_ll
20618 0.8066 flush_tlb_page
--
Jon Smirl
jonsmirl@gmail.com
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox