From f40ae5cee61f35bdc46b17ccc11fbc6eb7977c89 Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Sun, 31 Jul 2011 09:44:50 -0400 Subject: [PATCH 1/5] git-p4: use test_when_finished in tests Cleanup nicely when tests fail. This avoids many duplicated lines in the tests, and adds cleanup in a couple of tests that did not have it. When one fails, now all the rest will not fail too. Signed-off-by: Pete Wyckoff Acked-by: Luke Diamand Signed-off-by: Junio C Hamano --- t/t9800-git-p4.sh | 93 ++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index 33b0127651..aec3ba1641 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -45,29 +45,33 @@ test_expect_success 'add p4 files' ' cd "$TRASH_DIRECTORY" ' +cleanup_git() { + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && + mkdir "$git" +} + test_expect_success 'basic git-p4 clone' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && git log --oneline >lines && - test_line_count = 1 lines && - cd .. && - rm -rf "$git" && mkdir "$git" + test_line_count = 1 lines ' test_expect_success 'git-p4 clone @all' ' "$GITP4" clone --dest="$git" //depot@all && + test_when_finished cleanup_git && cd "$git" && git log --oneline >lines && - test_line_count = 2 lines && - cd .. && - rm -rf "$git" && mkdir "$git" + test_line_count = 2 lines ' test_expect_success 'git-p4 sync uninitialized repo' ' test_create_repo "$git" && + test_when_finished cleanup_git && cd "$git" && - test_must_fail "$GITP4" sync && - rm -rf "$git" && mkdir "$git" + test_must_fail "$GITP4" sync ' # @@ -76,19 +80,18 @@ test_expect_success 'git-p4 sync uninitialized repo' ' # test_expect_success 'git-p4 sync new branch' ' test_create_repo "$git" && + test_when_finished cleanup_git && cd "$git" && test_commit head && "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all && git log --oneline p4/depot >lines && - cat lines && - test_line_count = 2 lines && - cd .. && - rm -rf "$git" && mkdir "$git" + test_line_count = 2 lines ' test_expect_success 'exit when p4 fails to produce marshaled output' ' badp4dir="$TRASH_DIRECTORY/badp4dir" && mkdir -p "$badp4dir" && + test_when_finished "rm -rf $badp4dir" && cat >"$badp4dir"/p4 <<-EOF && #!$SHELL_PATH exit 1 @@ -106,29 +109,26 @@ test_expect_success 'add p4 files with wildcards in the names' ' echo file-wild-at >file-wild@at && echo file-wild-percent >file-wild%percent && p4 add -f file-wild* && - p4 submit -d "file wildcards" && - cd "$TRASH_DIRECTORY" + p4 submit -d "file wildcards" ' test_expect_success 'wildcard files git-p4 clone' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && test -f file-wild#hash && test -f file-wild\*star && test -f file-wild@at && - test -f file-wild%percent && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + test -f file-wild%percent ' test_expect_success 'clone bare' ' "$GITP4" clone --dest="$git" --bare //depot && + test_when_finished cleanup_git && cd "$git" && test ! -d .git && bare=`git config --get core.bare` && - test "$bare" = true && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + test "$bare" = true ' p4_add_user() { @@ -173,6 +173,7 @@ test_expect_success 'preserve users' ' p4_add_user bob Bob && p4_grant_admin alice && "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && echo "username: a change by alice" >> file1 && echo "username: a change by bob" >> file2 && @@ -181,27 +182,25 @@ test_expect_success 'preserve users' ' git config git-p4.skipSubmitEditCheck true && P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user && p4_check_commit_author file1 alice && - p4_check_commit_author file2 bob && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + p4_check_commit_author file2 bob ' # Test username support, submitting as bob, who lacks admin rights. Should # not submit change to p4 (git diff should show deltas). test_expect_success 'refuse to preserve users without perms' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && echo "username-noperms: a change by alice" >> file1 && git commit --author "Alice " -m "perms: a change by alice" file1 && ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user && - ! git diff --exit-code HEAD..p4/master > /dev/null && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + ! git diff --exit-code HEAD..p4/master > /dev/null ' # What happens with unknown author? Without allowMissingP4Users it should fail. test_expect_success 'preserve user where author is unknown to p4' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && git config git-p4.skipSubmitEditCheck true echo "username-bob: a change by bob" >> file1 && @@ -215,9 +214,7 @@ test_expect_success 'preserve user where author is unknown to p4' ' git config git-p4.preserveUser true && P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit && git diff --exit-code HEAD..p4/master > /dev/null && - p4_check_commit_author file1 alice && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + p4_check_commit_author file1 alice ' # If we're *not* using --preserve-user, git-p4 should warn if we're submitting @@ -226,31 +223,29 @@ test_expect_success 'preserve user where author is unknown to p4' ' # Test: warning disabled and user is the same. test_expect_success 'not preserving user with mixed authorship' ' "$GITP4" clone --dest="$git" //depot && - ( - cd "$git" && - git config git-p4.skipSubmitEditCheck true && - p4_add_user derek Derek && + test_when_finished cleanup_git && + cd "$git" && + git config git-p4.skipSubmitEditCheck true && + p4_add_user derek Derek && - make_change_by_user usernamefile3 Derek derek@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - grep "git author derek@localhost does not match" actual && + make_change_by_user usernamefile3 Derek derek@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + grep "git author derek@localhost does not match" actual && - make_change_by_user usernamefile3 Charlie charlie@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - grep "git author charlie@localhost does not match" actual && + make_change_by_user usernamefile3 Charlie charlie@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + grep "git author charlie@localhost does not match" actual && - make_change_by_user usernamefile3 alice alice@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - ! grep "git author.*does not match" actual && + make_change_by_user usernamefile3 alice alice@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + ! grep "git author.*does not match" actual && - git config git-p4.skipUserNameCheck true && - make_change_by_user usernamefile3 Charlie charlie@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - ! grep "git author.*does not match" actual && + git config git-p4.skipUserNameCheck true && + make_change_by_user usernamefile3 Charlie charlie@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + ! grep "git author.*does not match" actual && - p4_check_commit_author usernamefile3 alice - ) && - rm -rf "$git" && mkdir "$git" + p4_check_commit_author usernamefile3 alice ' From 83cf0fe49fc6a7124377ef6dec75a9776c753346 Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Sun, 31 Jul 2011 09:45:17 -0400 Subject: [PATCH 2/5] git-p4: add missing && in test Signed-off-by: Pete Wyckoff Acked-by: Luke Diamand Signed-off-by: Junio C Hamano --- t/t9800-git-p4.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index aec3ba1641..b7eda82894 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -202,7 +202,7 @@ test_expect_success 'preserve user where author is unknown to p4' ' "$GITP4" clone --dest="$git" //depot && test_when_finished cleanup_git && cd "$git" && - git config git-p4.skipSubmitEditCheck true + git config git-p4.skipSubmitEditCheck true && echo "username-bob: a change by bob" >> file1 && git commit --author "Bob " -m "preserve: a change by bob" file1 && echo "username-unknown: a change by charlie" >> file1 && From eab30818a9d0b874f9b339374349043f2c4aee5d Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Sun, 31 Jul 2011 09:45:38 -0400 Subject: [PATCH 3/5] git-p4: one test missing config git-p4.skipSubmitEditCheck Add this missing line in one of the tests. Otherwise, on fast machines, the following git-p4 commit will complain that nobody edited the submission message. Signed-off-by: Pete Wyckoff Acked-by: Luke Diamand Signed-off-by: Junio C Hamano --- t/t9800-git-p4.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index b7eda82894..b3047077e9 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -191,6 +191,7 @@ test_expect_success 'refuse to preserve users without perms' ' "$GITP4" clone --dest="$git" //depot && test_when_finished cleanup_git && cd "$git" && + git config git-p4.skipSubmitEditCheck true && echo "username-noperms: a change by alice" >> file1 && git commit --author "Alice " -m "perms: a change by alice" file1 && ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user && From 4e2e6ce45047fe2713546127f3d1ded576e1bf7e Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Sun, 31 Jul 2011 09:45:55 -0400 Subject: [PATCH 4/5] git-p4: commit time should be most recent p4 change time When importing a repo, the time on the initial commit had been just "now". But this causes problems when trying to share among git-p4 repos that were created identically, although at different times. Instead, use the time in the top-most p4 change as the time for the git import commit. Signed-off-by: Pete Wyckoff Acked-by: Luke Diamand Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 15 ++++++++++++++- t/t9800-git-p4.sh | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 98d2aee67f..6b9de9e7e0 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1649,7 +1649,8 @@ class P4Sync(Command, P4UserMap): def importHeadRevision(self, revision): print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch) - details = { "user" : "git perforce import user", "time" : int(time.time()) } + details = {} + details["user"] = "git perforce import user" details["desc"] = ("Initial import of %s from the state at revision %s\n" % (' '.join(self.depotPaths), revision)) details["change"] = revision @@ -1689,6 +1690,18 @@ class P4Sync(Command, P4UserMap): fileCnt = fileCnt + 1 details["change"] = newestRevision + + # Use time from top-most change so that all git-p4 clones of + # the same p4 repo have the same commit SHA1s. + res = p4CmdList("describe -s %d" % newestRevision) + newestTime = None + for r in res: + if r.has_key('time'): + newestTime = int(r['time']) + if newestTime is None: + die("\"describe -s\" on newest change %d did not give a time") + details["time"] = newestTime + self.updateOptionDict(details) try: self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths) diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index b3047077e9..97ec9753b4 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -249,6 +249,25 @@ test_expect_success 'not preserving user with mixed authorship' ' p4_check_commit_author usernamefile3 alice ' +marshal_dump() { + what=$1 + python -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]' +} + +# Sleep a bit so that the top-most p4 change did not happen "now". Then +# import the repo and make sure that the initial import has the same time +# as the top-most change. +test_expect_success 'initial import time from top change time' ' + p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) && + p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) && + sleep 3 && + "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && + cd "$git" && + gittime=$(git show -s --raw --pretty=format:%at HEAD) && + echo $p4time $gittime && + test $p4time = $gittime +' test_expect_success 'shutdown' ' pid=`pgrep -f p4d` && From e08afecd7fe04b519b72f136c4a24b151c748f49 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 1 Aug 2011 13:16:09 +0200 Subject: [PATCH 5/5] connect: correctly number ipv6 network adapter In ba50532, the variable 'cnt' was added to both the IPv6 and the IPv4 version of git_tcp_connect_sock, intended to identify which network adapter the connection failed on. But in the IPv6 version, the variable was never increased, leaving it constantly at zero. This behaviour isn't very useful, so let's fix it by increasing the variable at every loop-iteration. Signed-off-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- connect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.c b/connect.c index 2119c3f74e..b3585aba22 100644 --- a/connect.c +++ b/connect.c @@ -216,7 +216,7 @@ static int git_tcp_connect_sock(char *host, int flags) if (flags & CONNECT_VERBOSE) fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port); - for (ai0 = ai; ai; ai = ai->ai_next) { + for (ai0 = ai; ai; ai = ai->ai_next, cnt++) { sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (sockfd < 0) {