How to execute many numbered old versions of a file

I'm looking for an elegant way to populate Mercurial with different versions of the same program from 50 old versions with numbered file names: prog1.py, prog2.py ... prog50.py For each version I would like to keep the dates and the original file name, maybe in the comment to the change.

I am new to Mercurial and searched without finding an answer.

+6
source share
2 answers

hg commit has -d to indicate a date and -m to indicate a comment.

 hg init copy prog1.py prog.py /y hg ci -A prog.py -d 1/1/2015 -m prog1.py copy prog2.py prog.py /y hg ci -A prog.py -d 1/2/2015 -m prog2.py # repeat as needed 
+3
source

Of course, you can automate all this in a small bash script:

You get the file modification date through stat -c %y ${FILENAME} . Thus, assuming the files are ordered:

 hg init for i in /path/to/old/versions/*.py do; cp $i . hg ci -d `stat -c %y $i` -m "Import $i" done 

Um, the natural sorting of the file name is prog1, prog11, prog12, ... prog19, prog2, prog21, .... You might want to rename prog1 to prog01, etc., to allow normal sorting or sorting of file names before processing them , eg:

 hg init for i in `ls -tr /path/to/old/versions/*.py` do; cp /path/to/old/versions/$i . hg ci -d `stat -c %y /path/to/old/versions/$i` -m "Import $i" done 
+2
source

Source: https://habr.com/ru/post/989263/


All Articles