Nathan Durnan committed ef078b1 Merge

Merge with BBI#37 - Save Only Committed Timestamps

Comments (0)

Files changed (3)

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


+:: 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 Test #1: Modify both files, commit only one.
+echo ----------
+echo Timestamps before changes
+type .hgtimestamp
+echo "abc" >> abc.txt
+echo "efg" >> bcd.txt
+echo hg commit -m "commit bcd only" bcd.txt
+hg commit -m "commit bcd only" bcd.txt
+echo ----------
+echo Timestamps after committing only bcd.txt
+type .hgtimestamp
+echo ------------------------------------------------------
+echo CHECK: ONLY the bcd.txt timestamp should have changed.
+echo ======================================================
+echo ==============================================
+echo Test #2: Modify both files, commit everything.
+echo ----------
+echo Timestamps before commit
+type .hgtimestamp
+echo "123" >> abc.txt
+echo "456" >> bcd.txt
+echo hg commit -m "commit all (no match)"
+hg commit -m "commit all (no match)"
+echo ----------
+echo Timestamps after committing with no Match
+type .hgtimestamp
+echo -------------------------------------------
+echo CHECK: BOTH timestamps should have changed.
+echo ===========================================
 # end help text
 # - Automatically save and restore the modification times of files
-File_Version = '0.2.5'	# Version number definition
+File_Version = ''	# Version number definition
 # --> !!BETA RELEASE!!! <--
 # Copyright 2011-2012 Nathan Durnan <>
 	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')