Search code examples
windowscommand-linemercurial

Pass file list to Mercurial 'hg add' command from text file


I'm attempting to add about 40k files to Mercurial using 'hg add' on Win 10. Due to downstream constraints I need to split this up into chunks of 10k files for each add/commit, therefore I need to pass large lists of files to hg add. However I'm hitting Window's commandline argument character limits.

Is there a way to pass file lists stored in a file to hg add? AFAIK can't just use pipes as this is just reading the file and passing it as arguments. I think hg would need to directly read the text file.


Solution

  • You can solve this by using Mercurial's extensive pattern functionality and possibly file sets (see hg help patterns and hg help filesets).

    One type of pattern that you can specify is the listfile: pattern, which takes a filename as an argument, which must contain a newline-separated list of patterns (which of course can be filenames).

    So, you would first produce lists of the files in question, split up across several files. Let's assume they're called files1.txt, files2.txt, ...

    Then you'd do the following:

    hg add listfile:files1.txt
    hg commit
    hg add listfile:files2.txt
    hg commit
    ...
    

    If that by itself isn't sufficient, you can use file sets to further modify what files get added.