Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit many numbered old versions of a file

Tags:

mercurial

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.

like image 948
stephenbgood Avatar asked Jun 17 '15 05:06

stephenbgood


2 Answers

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
like image 96
Mark Tolonen Avatar answered Nov 16 '22 10:11

Mark Tolonen


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
like image 20
planetmaker Avatar answered Nov 16 '22 11:11

planetmaker