From 843626e47f203f59db082483db9bd7536c6a01fa Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sat, 21 Jun 2008 00:21:32 +0200 Subject: [PATCH] gitstats: Added a bumpTime to make the commit history look a bit more sane The result is that all the hashes changed, the testcases that made use of a specific hash will need to be updated. --- src/scripts/setupRepo.py | 65 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/scripts/setupRepo.py b/src/scripts/setupRepo.py index 106f49b..49e05b2 100755 --- a/src/scripts/setupRepo.py +++ b/src/scripts/setupRepo.py @@ -34,37 +34,55 @@ def setupRepo(path): repo = Repo.create(path) os.chdir(path) +def setDefaultTime(): + """Configures GIT_COMMITTER_DATE and GIT_AUTHOR_DATE to a default value + + The actual date set is 2005-05-26 23:30, which was taken + from t/t1400-update-ref.sh and then converted to UNIX + time manually. + """ + + os.environ["GIT_COMMITTER_DATE"] = "1211844600" + os.environ["GIT_AUTHOR_DATE"] = "1211844600" + os.environ["TZ"] = "UTC" + def setDefaultInfo(): - """Configures GIT_COMMITTER_DATE etc to a default value. + """Configures GIT_COMMITTER_NAME 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 + These values are taken from t/test-lib.sh from git.git. """ - # Date taken from t/t1400-update-ref.sh os.environ["GIT_COMMITTER_NAME"] = "C O Mitter" os.environ["GIT_COMMITTER_EMAIL"] = "committer@example.com" - os.environ["GIT_COMMITTER_DATE"] = "2005-05-26 23:30" os.environ["GIT_AUTHOR_NAME"] = "A U Thor" os.environ["GIT_AUTHOR_EMAIL"] = "author@example.com" - os.environ["GIT_AUTHOR_DATE"] = "2005-05-26 23:30" - os.environ["TZ"] = "UTC" - + def setSecondaryInfo(): - """Configures GIT_COMMITTER_DATE and GIT_AUTHOR_DATE to a secondary value. + """Configures GIT_COMMITTER_NAME etc. 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 + The values are the default values but in reverse. """ - 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" os.environ["GIT_AUTHOR_NAME"] = "Roh Tua" os.environ["GIT_AUTHOR_EMAIL"] = "roh.tua@example.com" - os.environ["GIT_AUTHOR_DATE"] = "2005-05-26 23:30" - os.environ["TZ"] = "UTC" + +def bumpTime(amount = 60*60): + """Bumps the date in GIT_AUTHOR_DATE and GIT_COMMITTER_DATE + + Args: + amount: The amount by which they should be bumped. + """ + + time = os.environ["GIT_AUTHOR_DATE"] + time = int(time) + time += amount + time = str(time) + + os.environ["GIT_AUTHOR_DATE"] = time + os.environ["GIT_COMMITTER_DATE"] = time + def addFile(filename, createFile=True, commit=True): """Adds the specified file @@ -84,6 +102,7 @@ def addFile(filename, createFile=True, commit=True): if commit: git.commit("-m", "Added file " + filename) + bumpTime() def deleteFile(filename, leaveOnDisk=False): """Deletes the specified file @@ -106,6 +125,7 @@ def deleteFile(filename, leaveOnDisk=False): git.rm(*args) git.commit("-m", "Deleted file " + filename) + bumpTime() def createLinearHistory(filename, createFile=False, initialCommit=False, start=1, count=10, finalCommit=False): """Creates a linear history in the directory of the current repository. @@ -138,7 +158,8 @@ def createLinearHistory(filename, createFile=False, initialCommit=False, start=1 file.flush() # Add the file and create the initial commit - git.commit("-a", "-m", "Initial commit") + git.commit("-a", "-m", "Initial commit") + bumpTime() # Create a linear history for i in range(start, stop): @@ -146,6 +167,7 @@ def createLinearHistory(filename, createFile=False, initialCommit=False, start=1 file.flush() git.commit("-a", "-m", "Commit " + str(i)) + bumpTime() if finalCommit: # Finish it up with a final change @@ -154,6 +176,7 @@ def createLinearHistory(filename, createFile=False, initialCommit=False, start=1 # And a final commit git.commit("-a", "-m", "Last commit") + bumpTime() def createBranch(name, checkout=True): """Creates a branch with the specified name and optionally checks it out @@ -166,6 +189,7 @@ def createBranch(name, checkout=True): git = Git(".") git.branch(name) + bumpTime() if checkout: checkoutBranch(name) @@ -182,6 +206,7 @@ def deleteBranch(name): git = Git(".") git.branch("-d", name) + bumpTime() def createDir(name, changeDir=False): """Creates a directory with the specified name @@ -222,6 +247,7 @@ def mergeBranch(name): git = Git(".") git.merge(name) + bumpTime() def revertLastCommit(commitChanges=True): """Reverts the last commit made @@ -239,6 +265,9 @@ def revertLastCommit(commitChanges=True): git.revert(*options) + if commitChanges: + bumpTime() + def tagRelease(releaseNumber): """Tags a release. @@ -251,6 +280,7 @@ def tagRelease(releaseNumber): git = Git(".") git.tag('v' + str(releaseNumber)) + bumpTime() def createRemoteBranch(name, start="HEAD"): """Creates a new remote branch with the specified name @@ -263,6 +293,7 @@ def createRemoteBranch(name, start="HEAD"): git = Git(".") git.update_ref('refs/remotes/' + name, start) + bumpTime() def checkHead(HEAD): """Verifies that the HEAD is as expected. @@ -314,6 +345,7 @@ def createTestRepository(): # Set the default author/committer setDefaultInfo() + setDefaultTime() # Create some linear history createLinearHistory(c, createFile=True, initialCommit=True, finalCommit=True) @@ -420,6 +452,7 @@ def createMetricsRepository(): # Set the info setDefaultInfo() + setDefaultTime() # And create some history createLinearHistory(c, createFile=True, count=2) -- 2.11.4.GIT