From db4b65821e65138177de9afbce70f141cc831224 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Tue, 16 Aug 2005 22:35:27 +1200 Subject: [PATCH] Add merge detection to git-cvsimport Added -m and -M flags for git-cvsimport to detect merge commits in cvs. While this trusts the commit message, in repositories where merge commits indicate 'merged from FOOBRANCH' the import works surprisingly well. Even if some merges from CVS are bogus or incomplete, the resulting branches are in better state to go forward (and merge) than without any merge detection. Signed-off-by: Martin Langhoff Signed-off-by: Junio C Hamano --- Documentation/git-cvsimport-script.txt | 12 ++++++++- git-cvsimport-script | 48 +++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Documentation/git-cvsimport-script.txt b/Documentation/git-cvsimport-script.txt index ae46b2f072..d01a15d8a3 100644 --- a/Documentation/git-cvsimport-script.txt +++ b/Documentation/git-cvsimport-script.txt @@ -12,7 +12,7 @@ SYNOPSIS 'git-cvsimport-script' [ -o ] [ -h ] [ -v ] [ -d ] [ -p ] [ -C ] [ -i ] [ -k ] - [ -s ] [ ] + [ -s ] [ -m ] [ -M regex ] [ ] DESCRIPTION @@ -58,6 +58,16 @@ OPTIONS If you need to pass multiple options, separate them with a comma. +-m:: + Attempt to detect merges based on the commit message. This option + will enable default regexes that try to capture the name source + branch name from the commit message. + +-M :: + Attempt to detect merges based on the commit message with a custom + regex. It can be used with -m to also see the default regexes. + You must escape forward slashes. + -v:: Verbosity: let 'cvsimport' report what it is doing. diff --git a/git-cvsimport-script b/git-cvsimport-script index 2f39af33d9..1f36acea22 100755 --- a/git-cvsimport-script +++ b/git-cvsimport-script @@ -28,19 +28,19 @@ use POSIX qw(strftime dup2); $SIG{'PIPE'}="IGNORE"; $ENV{'TZ'}="UTC"; -our($opt_h,$opt_o,$opt_v,$opt_k,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_s); +our($opt_h,$opt_o,$opt_v,$opt_k,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_s,$opt_m,$opt_M); sub usage() { print STDERR <; chomp $cvs_tree; - close $f + close $f; } else { usage(); } +our @mergerx = (); +if ($opt_m) { + @mergerx = ( qr/\W(?:from|of|merge|merging|merged) (\w+)/i ); +} +if ($opt_M) { + push (@mergerx, qr/$opt_M/); +} + select(STDERR); $|=1; select(STDOUT); @@ -375,6 +383,22 @@ sub getwd() { return $pwd; } + +sub get_headref($$) { + my $name = shift; + my $git_dir = shift; + my $sha; + + if (open(C,"$git_dir/refs/heads/$name")) { + chomp($sha = ); + close(C); + length($sha) == 40 + or die "Cannot get head id for $name ($sha): $!\n"; + } + return $sha; +} + + -d $git_tree or mkdir($git_tree,0777) or die "Could not create $git_tree: $!"; @@ -549,6 +573,22 @@ my $commit = sub { my @par = (); @par = ("-p",$parent) if $parent; + + # loose detection of merges + # based on the commit msg + foreach my $rx (@mergerx) { + if ($logmsg =~ $rx) { + my $mparent = $1; + if ($mparent eq 'HEAD') { $mparent = 'origin'}; + if ( -e "$git_dir/refs/heads/$mparent") { + $mparent = get_headref($mparent, $git_dir); + push @par, '-p', $mparent; + # printing here breaks import # + # # print "Merge parent branch: $mparent\n" if $opt_v; + } + } + } + exec("env", "GIT_AUTHOR_NAME=$author", "GIT_AUTHOR_EMAIL=$author", -- cgit v1.2.3 From 049f28c3929fa722634ecb7bb39d78457018815a Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Wed, 17 Aug 2005 09:27:09 +1200 Subject: [PATCH] git-cvsimport - remove hardcoded reference to origin ... in the newly introduced merge detection code. Signed-off-by: Martin Langhoff Signed-off-by: Junio C Hamano --- git-cvsimport-script | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-cvsimport-script b/git-cvsimport-script index 1f36acea22..e3a8e584a5 100755 --- a/git-cvsimport-script +++ b/git-cvsimport-script @@ -579,7 +579,7 @@ my $commit = sub { foreach my $rx (@mergerx) { if ($logmsg =~ $rx) { my $mparent = $1; - if ($mparent eq 'HEAD') { $mparent = 'origin'}; + if ($mparent eq 'HEAD') { $mparent = $opt_o }; if ( -e "$git_dir/refs/heads/$mparent") { $mparent = get_headref($mparent, $git_dir); push @par, '-p', $mparent; -- cgit v1.2.3 From 828cc617c1908a16b36734f62bb10299c2cfba6f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 17 Aug 2005 13:31:49 -0700 Subject: [PATCH] Export relative path handling "prefix_path()" function Not all programs necessarily have a pathspec array of pathnames, some of them (like git-update-cache) want to do things one file at a time. So export the single-path interface too. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 1 + setup.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index 6365381c17..742378f40f 100644 --- a/cache.h +++ b/cache.h @@ -142,6 +142,7 @@ extern char *get_graft_file(void); extern const char **get_pathspec(const char *prefix, char **pathspec); extern const char *setup_git_directory(void); +extern char *prefix_path(const char *prefix, int len, char *path); #define alloc_nr(x) (((x)+16)*3/2) diff --git a/setup.c b/setup.c index 1710b16854..b8789de5c5 100644 --- a/setup.c +++ b/setup.c @@ -1,6 +1,6 @@ #include "cache.h" -static char *prefix_path(const char *prefix, int len, char *path) +char *prefix_path(const char *prefix, int len, char *path) { char *orig = path; for (;;) { -- cgit v1.2.3 From cfb0af1d50247e66ea1d46014650e60e9cfb87b9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 17 Aug 2005 13:32:22 -0700 Subject: [PATCH] Make git-update-cache take relative pathnames This also makes "./filename" acceptable as a side effect, since the pathname normalization handles that too. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- update-cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/update-cache.c b/update-cache.c index 1fcc59a9c0..63815ed658 100644 --- a/update-cache.c +++ b/update-cache.c @@ -321,6 +321,7 @@ int main(int argc, char **argv) { int i, newfd, entries, has_errors = 0; int allow_options = 1; + const char *prefix = setup_git_directory(); newfd = hold_index_file_for_update(&cache_file, get_index_file()); if (newfd < 0) @@ -381,6 +382,7 @@ int main(int argc, char **argv) } die("unknown option %s", path); } + path = prefix_path(prefix, prefix ? strlen(prefix) : 0, path); if (!verify_path(path)) { fprintf(stderr, "Ignoring path %s\n", argv[i]); continue; -- cgit v1.2.3 From 6a0049c07623a387bf7f7e7c90b71344c23decfa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 17 Aug 2005 15:17:03 -0700 Subject: Fix git-commit without paths. The earlier one to grab output from diff-files --name-only has a grave bug that when no paths are given it ended up doing the equivalent of "git-commit --all", which was not what I intended. Signed-off-by: Junio C Hamano --- git-commit-script | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-commit-script b/git-commit-script index f6cd75f024..15d03913d5 100755 --- a/git-commit-script +++ b/git-commit-script @@ -85,11 +85,13 @@ tt*) die "Only one of -c/-C/-F/-m can be used." ;; esac -case "$all" in -t) +case "$all,$#" in +t,*) git-diff-files --name-only -z | xargs -0 git-update-cache -q -- ;; +,0) + ;; *) git-diff-files --name-only -z "$@" | xargs -0 git-update-cache -q -- -- cgit v1.2.3 From 0f87f893657129907ff966f44aed7c7624d7ba1b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 17 Aug 2005 15:18:41 -0700 Subject: Make sure alternates are carried over from the original repository. When we create a cheap local clone by pointing at the object databse of the original repository, we forgot to take the alternates the original repository might have had into account. Signed-off-by: Junio C Hamano --- git-clone-script | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git-clone-script b/git-clone-script index 909ccc5301..99c2459631 100755 --- a/git-clone-script +++ b/git-clone-script @@ -81,7 +81,11 @@ yes,yes) ;; yes) mkdir -p "$D/.git/objects/info" - echo "$repo/objects" >"$D/.git/objects/info/alternates" + { + test -f "$repo/objects/info/alternates" && + cat "$repo/objects/info/alternates"; + echo "$repo/objects" + } >"$D/.git/objects/info/alternates" ;; esac -- cgit v1.2.3 From 99a92f928fd02a87d841a8bb19511e7ce526819d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 17 Aug 2005 15:19:57 -0700 Subject: Make rebase script saner. It did not check to see if the working tree was clean and matched the commit we were starting out as, resulting in the initial rebased commit including whatever dirty state the working tree has had. Signed-off-by: Junio C Hamano --- git-rebase-script | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/git-rebase-script b/git-rebase-script index 026225ab2c..7b1d4900bd 100755 --- a/git-rebase-script +++ b/git-rebase-script @@ -17,16 +17,19 @@ case "$#,$1" in shift ;; esac +git-update-cache --refresh || exit + case "$#" in -1) upstream=`git-rev-parse --verify "$1"` && - ours=`git-rev-parse --verify HEAD` || exit - ;; -2) upstream=`git-rev-parse --verify "$1"` && - ours=`git-rev-parse --verify "$2"` || exit - ;; -*) echo >&2 "$usage"; exit 1 ;; +1) ours_symbolic=HEAD ;; +2) ours_symbolic="$2" ;; +*) die "$usage" ;; esac +upstream=`git-rev-parse --verify "$1"` && +ours=`git-rev-parse --verify "$ours_symbolic^` || exit +test "$(git-diff-cache --cached "$ours")" = "" || +die "Your working tree does not match $ours_symbolic." + git-read-tree -m -u $ours $upstream && git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit -- cgit v1.2.3