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

前端 未结 9 2136
迷失自我
迷失自我 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.

    0 讨论(0)
  • 2021-02-04 16:50

    I know you already have a few answers to this one but a friend of mine had a similar issue and I created a simple program in VB.Net to do this for him perhaps it could help for you too, the prog and a copy of the source is at the bottom of the article linked below.

    http://www.simianenterprises.co.uk/blog/mercurial-export-changed-files-80.html

    Although this does not let you pick an end revision at the moment, it would be very easy to add that in using the source, however you would have to update to the target revision manually before extracting the files. If needed you could even mod it to create the zip instead of a folder of files (which is also nice and easy to manually zip)

    hope this helps either you or anyone else who wants this functionality.

    0 讨论(0)
  • 2021-02-04 16:55

    Here is a small and ugly bash script that will do the job, at least if you work in an Linux environment. This has absolutely no checks what so ever and will most likely break when you have moved a file but it is a start.

    Command:

    zipChanges.sh REVISION REPOSITORY DESTINATION
    zipChanges.sh 3 /home/hg/repo /home/hg/files.tgz
    

    Code:

    #!/bin/sh
    REV=$1
    SRC_REPO=$2
    DST_ZIP=$3
    
    cd $SRC_REPO
    FILES=$(hg status --rev $1 $SRC_REPO | cut -c3-)
    
    IFS=$'\n'
    FILENAMES=""
    for line in ${FILES}
    do
        FILENAMES=$FILENAMES" \""$SRC_REPO"/"$line"\""
    done
    
    CMD="tar czf \"$DST_ZIP\" $FILENAMES"
    
    eval $CMD
    
    0 讨论(0)
  • 2021-02-04 17:01

    I ran into this problem recently. My solution:

    hg update null
    hg debugsetparents (starting revision)
    hg update (ending revision)
    

    This will have the effect of deleting all tracked files that were not changed between those two revisions. You will have to remove any untracked files yourself, though. After doing this, the local branch will be in an inconsistent state; you can fix this by running hg debugrebuildstate (or simply deleting the local branch, if you no longer need it).

    0 讨论(0)
  • 2021-02-04 17:04

    In UNIX this can be done with:

    hg status --rev 1 --rev 2 -m -a -n | xargs zip changes.zip
    
    0 讨论(0)
  • 2021-02-04 17:04

    i just contributed an extension here https://sites.google.com/site/alessandronegrin/pack-mercurial-extension

    0 讨论(0)
提交回复
热议问题