How to commit many numbered old versions of a file

83 Views Asked by At

I'm looking for an elegant way to populate Mercurial with different versions of the same program, from 50 old versions that have numbered filenames: prog1.py, prog2.py ... prog50.py For each version I'd like to retain the dates and original filename, perhaps in the change comment.

I'm new to Mercurial and have searched without finding an answer.

2

There are 2 best solutions below

1
On BEST ANSWER

hg commit has -d to specify a date and -m to specify 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
1
On

One can of course automate the whole thing in a small bash script:

You obtain the modification date of a file via stat -c %y ${FILENAME}. Thus assuming that 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

Mind, natural filename sorting is prog1, prog11 prog12, ... prog19, prog2, prog21, .... You might want to rename prog1 to prog01 etc to ensure normal sorting or sort the filenames before processing them, e.g.:

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