Mercurial - How do I create a .zip of files changed between two revisions?

前端 未结 9 2135
迷失自我
迷失自我 2021-02-04 16:29

I have a personal Mercurial repository tracking some changes I am working on. I\'d like to share these changes with a collaborator, however they don\'t have/can\'t get Mercuria

9条回答
  •  梦谈多话
    2021-02-04 16:46

    The best case scenario is to put the proper pressure on these folks to get Mercurial, but barring that, a patch is probably better than a zipped set of files, since the patch will track deletes and renames. If you still want a zip file, I've written a short script that makes a zip file:

    import os, subprocess, sys
    from zipfile import ZipFile, ZIP_DEFLATED
    
    def main(revfrom, revto, destination, *args):
        root, err = getoutput("hg root")
        if "no Merurial repository" in err:
            print "This script must be run from within an Hg repository"
            return
        root = root.strip()
    
        filelist, _ = getoutput("hg status --rev %s:%s" % (revfrom, revto))
        paths = []
    
        for line in filelist.split('\n'):
            try:
                (status, path) = line.split(' ', 1)
            except ValueError:
                continue
            if status != 'D':
                paths.append(path)
    
        if len(paths) < 1:
            print "No changed files could be found."
            return
    
        z = ZipFile(destination, "w", ZIP_DEFLATED)
        os.chdir(root)
        for path in paths:
            z.write(path)
        z.close()
    
        print "Done."
    
    
    def getoutput(cmd):
        p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        return p.communicate()
    
    
    if __name__ == '__main__':
        main(*sys.argv[1:])
    

    The usage would be nameofscript.py fromrevision torevision destination. E.g., nameofscript.py 45 51 c:\updates.zip

    Sorry about the poor command line interface, but hey the script only took 25 minutes to write.

    Note: this should be run from a working directory within a repository.

提交回复
热议问题