[PATCH 01 of 10] largefiles: centralize the logic to get outgoing largefiles

Mads Kiilerich mads at kiilerich.com
Thu Mar 6 08:48:20 CST 2014


Thanks for these patches. They are a nice improvement.

On 03/05/2014 01:12 PM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1394019743 -32400
> #      Wed Mar 05 20:42:23 2014 +0900
> # Node ID 655cacfc3311c174c995e4bab13755b498cb43dc
> # Parent  779ceb84f4f782d32dfe47f6684107c08d2f6142
> largefiles: centralize the logic to get outgoing largefiles
>
> Before this patch, "overrides.getoutgoinglfiles()" (called by
> "overrideoutgoing()" and "overridesummary()") and "lfilesrepo.push()"
> implement similar logic to get outgoing largefiles separately.

Please elaborate a bit. It took me some time to figure the following out 
(feel free to use it):

The difference between these two were that one returned the name of the 
standin across all revisoins, the other returned the largefile hashes 
across all standins.

> This patch centralizes the logic to get outgoing largefiles in
> "lfutil.getlfilestoupload()".
>
> diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
> --- a/hgext/largefiles/lfutil.py
> +++ b/hgext/largefiles/lfutil.py
> @@ -15,6 +15,7 @@
>   
>   from mercurial import dirstate, httpconnection, match as match_, util, scmutil
>   from mercurial.i18n import _
> +from mercurial import node

Please extend the existing 'from mercurial import' list ... or at least 
group them together.

>   shortname = '.hglf'
>   shortnameslash = shortname + '/'
> @@ -365,3 +366,31 @@
>           if f[0] not in filelist:
>               filelist.append(f[0])
>       return filelist
> +
> +def getlfilestoupload(repo, missing, mapfunc=None):
> +    toupload = set()
> +    if not missing:
> +        return toupload

Do this check make any difference? Looping an empty list is free.

> +    if not mapfunc:
> +        mapfunc = lambda f, ctx: f

I not think this mapfunc thing is pretty.

In the end, it would be nice to tell in the UI which largefile we are 
pulling/pushing. Not only the hash, but also the largefile name (or one 
of them).

Currently outgoing and summary will list all largefiles in outgoing 
changesets, no matter if they really need pushing or not. Arguably it 
should only list the largefiles that really are outgoing. For that we 
need the hashes.

So how about letting this function return a dict mapping from hash to a 
filename that uses it? For now the two users of this function can just 
look at either keys or values.

/Mads

> +    for n in missing:
> +        parents = [p for p in repo.changelog.parents(n) if p != node.nullid]
> +        ctx = repo[n]
> +        files = set(ctx.files())
> +        if len(parents) == 2:
> +            mc = ctx.manifest()
> +            mp1 = ctx.parents()[0].manifest()
> +            mp2 = ctx.parents()[1].manifest()
> +            for f in mp1:
> +                if f not in mc:
> +                    files.add(f)
> +            for f in mp2:
> +                if f not in mc:
> +                    files.add(f)
> +            for f in mc:
> +                if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
> +                    files.add(f)
> +        toupload = toupload.union(set([mapfunc(f, ctx)
> +                                       for f in files
> +                                       if isstandin(f) and f in ctx]))
> +    return toupload
> diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
> --- a/hgext/largefiles/overrides.py
> +++ b/hgext/largefiles/overrides.py
> @@ -12,7 +12,7 @@
>   import copy
>   
>   from mercurial import hg, commands, util, cmdutil, scmutil, match as match_, \
> -        node, archival, error, merge, discovery, pathutil, revset
> +        archival, error, merge, discovery, pathutil, revset
>   from mercurial.i18n import _
>   from mercurial.node import hex
>   from hgext import rebase
> @@ -999,27 +999,7 @@
>       if opts.get('newest_first'):
>           o.reverse()
>   
> -    toupload = set()
> -    for n in o:
> -        parents = [p for p in repo.changelog.parents(n) if p != node.nullid]
> -        ctx = repo[n]
> -        files = set(ctx.files())
> -        if len(parents) == 2:
> -            mc = ctx.manifest()
> -            mp1 = ctx.parents()[0].manifest()
> -            mp2 = ctx.parents()[1].manifest()
> -            for f in mp1:
> -                if f not in mc:
> -                        files.add(f)
> -            for f in mp2:
> -                if f not in mc:
> -                    files.add(f)
> -            for f in mc:
> -                if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
> -                    files.add(f)
> -        toupload = toupload.union(
> -            set([f for f in files if lfutil.isstandin(f) and f in ctx]))
> -    return sorted(toupload)
> +    return sorted(lfutil.getlfilestoupload(repo, o))
>   
>   def overrideoutgoing(orig, ui, repo, dest=None, **opts):
>       result = orig(ui, repo, dest, **opts)
> diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
> --- a/hgext/largefiles/reposetup.py
> +++ b/hgext/largefiles/reposetup.py
> @@ -11,7 +11,6 @@
>   import os
>   
>   from mercurial import error, manifest, match as match_, util, discovery
> -from mercurial import node as node_
>   from mercurial.i18n import _
>   from mercurial import localrepo
>   
> @@ -418,32 +417,9 @@
>               outgoing = discovery.findcommonoutgoing(repo, remote.peer(),
>                                                       force=force)
>               if outgoing.missing:
> -                toupload = set()
>                   o = self.changelog.nodesbetween(outgoing.missing, revs)[0]
> -                for n in o:
> -                    parents = [p for p in self.changelog.parents(n)
> -                               if p != node_.nullid]
> -                    ctx = self[n]
> -                    files = set(ctx.files())
> -                    if len(parents) == 2:
> -                        mc = ctx.manifest()
> -                        mp1 = ctx.parents()[0].manifest()
> -                        mp2 = ctx.parents()[1].manifest()
> -                        for f in mp1:
> -                            if f not in mc:
> -                                files.add(f)
> -                        for f in mp2:
> -                            if f not in mc:
> -                                files.add(f)
> -                        for f in mc:
> -                            if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f,
> -                                    None):
> -                                files.add(f)
> -
> -                    toupload = toupload.union(
> -                        set([ctx[f].data().strip()
> -                             for f in files
> -                             if lfutil.isstandin(f) and f in ctx]))
> +                mapfunc = lambda f, ctx: ctx[f].data().strip()
> +                toupload = lfutil.getlfilestoupload(self, o, mapfunc)
>                   lfcommands.uploadlfiles(ui, self, remote, toupload)
>               return super(lfilesrepo, self).push(remote, force=force, revs=revs,
>                   newbranch=newbranch)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list