6

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 Answers2

3

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
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • Thanks Mark. That looks practical enough. I'll just wait a day or so in case someone knows a more automated method. – stephenbgood Jun 17 '15 at 06:38
2

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
planetmaker
  • 5,884
  • 3
  • 28
  • 37
  • Thanks planetmaker for your answer which is informative and probably useful to others. Unfortunately for my case of only 50 files and Windows, I'm using the first answer above. – stephenbgood Jun 23 '15 at 14:03