Nathan Durnan avatar Nathan Durnan committed ef078b1 Merge

Merge with BBI#37 - Save Only Committed Timestamps

Comments (0)

Files changed (3)

 {
-"Version": "0.2.4",
+"Version": "0.2.6.0702",
 "FileData":{
 ".hgignore": {"timestamp": 1336516662.38},
 ".hgtags": {"timestamp": 1327960909.75},
 "README.md": {"timestamp": 1339691478.75},
+"Tests/TimestampMod_BBI37_Test.bat": {"timestamp": 1341343207.95},
 "TimeStampMod.png": {"timestamp": 1305052883.0},
-"TimestampMod.py": {"timestamp": 1339691056.98},
+"TimestampMod.py": {"timestamp": 1341339063.7},
 "TimeStampMod.xmind": {"timestamp": 1306451621.66},
 "TimestampMod_LastRecord": {"timestamp": 0}
 }

Tests/TimestampMod_BBI37_Test.bat

+::------------------------------------------------------------------------------
+:: Tests for BitBucket Issue #37 - Save Timestamp for Committed Files ONLY.
+:: When committing specific files, the extension is saving the timestamps of ALL
+:: files tracked in the repository even if they are not included in the commit.
+:: It should only be saving timestamps for files included in the commit.
+::------------------------------------------------------------------------------
+:: This test-script creates a temporary test repository and adds two files to it.
+:: * The first test will modify both files and commit only one of them.
+::    - Only the timestamp for the committed file should be changed.
+:: * The second test will modify both files and commit without specifying a file.
+::    - The timestamps for both of the files should be changed.
+::------------------------------------------------------------------------------
+@echo off
+echo Initializing Test Repository...
+if exist testrepo rmdir /S /Q testrepo
+mkdir testrepo
+cd testrepo
+hg init
+echo Create first file (abc.txt)
+echo "abc" > abc.txt
+hg add abc.txt
+hg commit -m "abc"
+echo Create second file (bcd.txt)
+echo "abc" > bcd.txt
+hg add bcd.txt
+hg commit -m "add bcd"
+echo.
+echo ============================================
+echo Test #1: Modify both files, commit only one.
+echo.
+echo ----------
+echo Timestamps before changes
+type .hgtimestamp
+echo "abc" >> abc.txt
+echo "efg" >> bcd.txt
+echo.
+echo.
+echo hg commit -m "commit bcd only" bcd.txt
+hg commit -m "commit bcd only" bcd.txt
+echo.
+echo ----------
+echo Timestamps after committing only bcd.txt
+type .hgtimestamp
+echo.
+echo ------------------------------------------------------
+echo CHECK: ONLY the bcd.txt timestamp should have changed.
+echo ======================================================
+pause
+echo.
+echo.
+echo ==============================================
+echo Test #2: Modify both files, commit everything.
+echo.
+echo ----------
+echo Timestamps before commit
+type .hgtimestamp
+echo "123" >> abc.txt
+echo "456" >> bcd.txt
+echo.
+echo.
+echo hg commit -m "commit all (no match)"
+hg commit -m "commit all (no match)"
+echo.
+echo ----------
+echo Timestamps after committing with no Match
+type .hgtimestamp
+echo.
+echo -------------------------------------------
+echo CHECK: BOTH timestamps should have changed.
+echo ===========================================
+pause
 # end help text
 #==============================================================================
 # TimestampMod.py - Automatically save and restore the modification times of files
-File_Version = '0.2.5'	# Version number definition
+File_Version = '0.2.6.0702'	# Version number definition
 # --> !!BETA RELEASE!!! <--
 # Copyright 2011-2012 Nathan Durnan <nedmech@gmail.com>
 #
 	myChangedList, myDroppedList = _get_RepoFileList(repo, myMatchList, TimeStamp_dict)
 	# Retrieve existing timestamps from the record file.
 	myErr = _read_TimestampJSONRecords(repo, File_TimestampRecords, TimeStamp_dict)
-	
 	# Check for command optional argument
 	if kwargs['save']:
-		_save_TimestampsJSON(repo, File_TimestampRecords, myChangedList, myDroppedList, TimeStamp_dict)
+		_save_TimestampsJSON( \
+				repo, \
+				File_TimestampRecords, \
+				myMatchList, \
+				myChangedList, \
+				myDroppedList, \
+				TimeStamp_dict)
 	elif not myErr:	# Only evaluate Restore or Display if file was read.
 		if kwargs['restore']:
 			_restore_Timestamps(repo, TimeStamp_dict)
 	repo.ui.debug('______\nGenerating file list from repo...\n------\n')
 	# Establish category lists from repository status.
 	modified, added, removed, deleted, unknown, ignored, clean = repo.status(ignored=True, clean=True, unknown=True)
-	myChanged = IN_ListMatch + modified + added
+	# Changed files include modifications and additions.
+	# Leave the match list out of the changed list contents.
+	myChanged = modified + added
 	myDropped = removed + deleted
-	myFiles = myChanged + clean
+	# Be sure to include in the match list in the files to review.
+	myFiles = IN_ListMatch + myChanged + clean
 	# Rebuild global dictionary collection
 	OUT_TimeStamp_dict.clear() # Be sure to start with a clean collection.
 	for myFile in myFiles:
 #	all the time.  Maybe when Mercurial starts using Python 2.7+, the newer 
 #	OrderedDict object type may be able to be used here.
 #==============================================================================
-def _save_TimestampsJSON(repo, IN_TimestampFileName, IN_ChangedList, IN_DroppedList, INOUT_TimeStamp_dict):
+def _save_TimestampsJSON( \
+		repo, \
+		IN_TimestampFileName, \
+		IN_MatchList, \
+		IN_ChangedList, \
+		IN_DroppedList, \
+		INOUT_TimeStamp_dict):
 	'''Save File Modification Timestamps to JSON record file.'''
 	repo.ui.note('______\nSaving timestamps to JSON file...\n------\n')
 	# Remove the record file from the list.
 	for s_fileName in sorted(INOUT_TimeStamp_dict.keys(), key=str.lower):
 		f_fileModTime = INOUT_TimeStamp_dict[s_fileName]
 		if (s_fileName in IN_ChangedList) or (f_fileModTime<=0):
-			f_fileModTime = INOUT_TimeStamp_dict[s_fileName] = _get_fileModTime(repo, s_fileName)
+			# Make sure to only save new file timestamps if they have  
+			# been included in the commit (will be in the match list).
+			if (f_fileModTime>0) and (len(IN_MatchList)>0) and (s_fileName not in IN_MatchList):
+				# Do not save new timestamp if file is not in specified match list.
+				pass
+			else: #File is in match list, or match list is empty (save all timestamps)
+				f_fileModTime = INOUT_TimeStamp_dict[s_fileName] = _get_fileModTime(repo, s_fileName)
+			# end of check for file in match list
 		# end of update timestamps for changed items or missing timestamps.
 		if (s_fileName in IN_DroppedList) or (f_fileModTime<=0):
 			repo.ui.debug('...removing record of dropped file, or file with missing timestamp (', s_fileName, ')\n')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.