cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
884 stars 84 forks source link

Some changes in the backup procedure #484

Closed arkandias closed 1 year ago

arkandias commented 1 year ago

Not sure if this was a minor bug/inconsistency or if it was set this way on purpose, but the switch maxNumberOfBackUps is not actually the maximum number of backup files: the latter is equal to maxNumberOfBackUps + 1 (as it includes 0). (Also, maxNumberOfBackUps=1 yields only 1 backup but maxNumberOfBackUps=2 yields 3 backups, so you cannot have only 2 backups.)

So I took a look at the relevant Perl file to change that, it seemed to me that the procedure could be simplified a bit (but I'll leave that to your appreciation!).

The condition in the while loop was not very intuitive to me, and changing the value of $maxNumberOfBackUps seemed unnatural. I replaced it with a very simple loop to compute the backupCounter. Handling the cases where some file is overwritten is postponed afterwards.

I kept backupFile and backupCounter separated to avoid additional regex substitutions (and possible bugs in some twisted situations where the extension would already appear in the filename) when incrementing backupCounter. Likewise when cycling through backups.

I also kept distinct the cases onlyOneBackUp=1 and maxNumberOfBackUps=1, because they are not formally the same (in the latter you add a number after the extension, which you can enlarge later on).

Finally I moved some logging at the end ("Backing up...") or changed the tense ("will be overwritten...") to make them consistent with the timing of the operations.

Feel free to revert some changes or completely discard the whole thing if you don't like it :)

cmhughes commented 1 year ago

Many thanks. This may take some time to review, as the backup procedure is really important, and hasn't changed for quite some time...

cmhughes commented 1 year ago

Great, many thanks for catching these mistakes, and for making the code cleaner and easier to follow. It has been a while since I've looked at this routine, and you've improved

I changed line 103 from <= to <.

Thanks again!