From 1de477fedad4652a662603cc91a06ae28546265c Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Wed, 18 Jun 2008 23:44:17 +0200 Subject: [PATCH] Refactored setupRepo a bit to make room for a metrics repo These repo will be used to test out more sophisticated metrics that require a repository all of their own. --- src/scripts/setupRepo.py | 92 +++++++++++++++++++++++++++++++++++++++--------- src/t/t8100-stats.sh | 6 ++-- 2 files changed, 78 insertions(+), 20 deletions(-) diff --git a/src/scripts/setupRepo.py b/src/scripts/setupRepo.py index c445b45..dc96f99 100755 --- a/src/scripts/setupRepo.py +++ b/src/scripts/setupRepo.py @@ -6,33 +6,41 @@ import tempfile from git import Repo from git import Git -repopath = os.path.join(tempfile.gettempdir(), "freshrepo") +testPath = os.path.join(tempfile.gettempdir(), "testrepo") +metricsPath = os.path.join(tempfile.gettempdir(), "metricsrepo") class InitializationException(Exception): """This exception is raised when something goes wrong during initialization. """ -def setupFreshRepo(): - """Creates a fresh repo under setupRepo.repopath +def setupRepo(path): + """Creates a fresh repo under the specified path - If setupRepo.repopath already exists an exception is raised. - Configures GIT_COMMITTER_DATE and GIT_AUTHOR_DATE to a default value. - This value is taken from t/t1400-update-ref.sh from git.git. - The actual value is "2005-05-26 23:30" + If the specified path exists an exception is raised. + + Args: + path: The path where the new repo should be created at. """ - if os.path.exists(repopath): + print("Creating a new repository in " + path) + + # Check if the path exists already, if so bail out + if os.path.exists(path): raise InitializationException( - "The specified path, " + repopath + ", exists already, " + "The specified path, " + path + ", exists already, " "please remove it or change the target path.") # Create a new repo - repo = Repo.create(repopath) - os.chdir(repopath) - - setDefaultInfo() + repo = Repo.create(path) + os.chdir(path) def setDefaultInfo(): + """Configures GIT_COMMITTER_DATE etc to a default value. + + These values are taken from t/test-lib.sh and t/t1400-update-ref.sh from + git.git. The actual date used is 2005-05-26 23:30 + """ + # Date taken from t/t1400-update-ref.sh os.environ["GIT_COMMITTER_NAME"] = "C O Mitter" os.environ["GIT_COMMITTER_EMAIL"] = "committer@example.com" @@ -43,6 +51,13 @@ def setDefaultInfo(): os.environ["TZ"] = "UTC" def setSecondaryInfo(): + """Configures GIT_COMMITTER_DATE and GIT_AUTHOR_DATE to a secondary value. + + These values are taken from t/test-lib.sh and t/t1400-update-ref.sh from + git.git. The actual date used is 2005-05-26 23:30 + """ + + os.environ["GIT_COMMITTER_NAME"] = "Retti Mmoc" os.environ["GIT_COMMITTER_EMAIL"] = "retti.mmoc@example.com" os.environ["GIT_COMMITTER_DATE"] = "2005-05-26 23:30" @@ -252,8 +267,9 @@ def checkHead(HEAD): print("Actual: '" + currentHEAD + "'.") return False -def main(): - print("Creating a new repository in " + repopath) +def createTestRepository(): + """Creates a test repository under setupRepo.testpath + """ # Directories d = "docs" @@ -272,7 +288,10 @@ def main(): j = "junio" # Start afresh - setupFreshRepo() + setupRepo(testPath) + + # Set the default author/committer + setDefaultInfo() # Create some linear history createLinearHistory(c, createFile=True, initialCommit=True, finalCommit=True) @@ -360,7 +379,46 @@ def main(): return 0 +def createMetricsRepository(): + """Creates a metrics repository in setupRepo.metricspath + """ + + pass + +def main(args): + """Creates a test and a metrics repository + + Args: + args: An array of arguments, when 2 in size the second + element should either be 'test' to just create the test + repo, or 'metrics' to just create the metrics + repository. If both should be created then the size of + args should be 1. The first element in the array is + always ignored. + + Returns: 0 upon success, or nonzero upon failure. + """ + + size = len(args) + + if size > 1 and (args[1] != "test" and args[1] != "metrics") or size > 2: + print "Please specify either 'test', 'metrics', or nothing to run both" + return 1 + + if len(args) == 1 or args[1] == "test": + ret = createTestRepository() + if ret != 0: + return ret + + if len(args) == 1 or args[1] == "metrics": + ret = createMetricsRepository() + if ret != 0: + return ret + + return 0 + if __name__ == '__main__': import sys - sys.exit(main()) + ret = main(sys.argv) + sys.exit(ret) diff --git a/src/t/t8100-stats.sh b/src/t/t8100-stats.sh index 9fe8dc6..b982851 100755 --- a/src/t/t8100-stats.sh +++ b/src/t/t8100-stats.sh @@ -18,7 +18,7 @@ ORIG_PATH=$PWD test_expect_success pre-clean ' - rm -fr "/tmp/freshrepo" || { + rm -fr "/tmp/testrepo" || { trap - exit echo >&5 "FATAL: Cannot clean the fresh repo" exit 1 @@ -26,8 +26,8 @@ test_expect_success pre-clean ' ' test_expect_success setup ' - ../scripts/setupRepo.py - cd /tmp/freshrepo + ../scripts/setupRepo.py test + cd /tmp/testrepo test_must_fail stats.py ' -- 2.11.4.GIT