]> git.phdru.name Git - git-scripts.git/commitdiff
Fix(set-commit-date.py): Consider deleted files
authorOleg Broytman <phd@phdru.name>
Fri, 2 Aug 2019 18:10:42 +0000 (21:10 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 2 Aug 2019 18:10:42 +0000 (21:10 +0300)
If the file was deleted and later readded - ignore deletion.
Otherwise ignore deleted files.

set-commit-date.py

index 7f481f36960251b382b9d0b756fed9563e521619..45302528606e7cc40398a647b87c94a1111668ee 100755 (executable)
@@ -15,11 +15,13 @@ os.chdir(git_root)
 separator = '----- GIT LOG SEPARATOR -----'
 
 git_log = subprocess.Popen(['git', 'log', '-m', '--first-parent',
-                            '--name-only', '--no-color',
+                            '--name-status', '--no-color',
                             '--format=%s%%n%%ct' % separator],
                            stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                            universal_newlines=True)
-filenames = set()
+changed_files = set()
+deleted_files = set()
+
 # stages: 1 - start of commit, 2 - timestamp, 3 - empty line, 4 - files
 stage = 1
 for line in git_log.stdout:
@@ -36,9 +38,16 @@ for line in git_log.stdout:
         stage = 4
         assert line == '', line
     elif stage == 4:
-        filename = line
-        if filename not in filenames:
-            filenames.add(filename)
+        if line.startswith('A') or line.startswith('M') \
+                or line.startswith('D'):
+            filename = line.split(None, 2)[1]
+        elif line.startswith('R'):
+            filename = line.split(None, 3)[2]  # renamed to
+        if line.startswith('D'):
+            if filename not in changed_files:  # The file was not readded
+                deleted_files.add(filename)
+        if filename not in deleted_files and filename not in changed_files:
+            changed_files.add(filename)
             if os.path.exists(filename):
                 os.utime(filename, (time, time))
     else: