hgext/largefiles/reposetup.py
changeset 19056 ac41bb76c737
parent 18969 257afe5489d4
child 19088 ce4472b2edb2
equal deleted inserted replaced
19055:0fc41f88f148 19056:ac41bb76c737
   124                         return False
   124                         return False
   125 
   125 
   126                 if match is None:
   126                 if match is None:
   127                     match = match_.always(self.root, self.getcwd())
   127                     match = match_.always(self.root, self.getcwd())
   128 
   128 
   129                 # First check if there were files specified on the
   129                 wlock = None
   130                 # command line.  If there were, and none of them were
   130                 try:
   131                 # largefiles, we should just bail here and let super
   131                     try:
   132                 # handle it -- thus gaining a big performance boost.
   132                         # updating the dirstate is optional
   133                 lfdirstate = lfutil.openlfdirstate(ui, self)
   133                         # so we don't wait on the lock
   134                 if match.files() and not match.anypats():
   134                         wlock = self.wlock(False)
   135                     for f in lfdirstate:
   135                     except error.LockError:
   136                         if match(f):
   136                         pass
   137                             break
   137 
   138                     else:
   138                     # First check if there were files specified on the
   139                         return super(lfilesrepo, self).status(node1, node2,
   139                     # command line.  If there were, and none of them were
   140                                 match, listignored, listclean,
   140                     # largefiles, we should just bail here and let super
   141                                 listunknown, listsubrepos)
   141                     # handle it -- thus gaining a big performance boost.
   142 
   142                     lfdirstate = lfutil.openlfdirstate(ui, self)
   143                 # Create a copy of match that matches standins instead
   143                     if match.files() and not match.anypats():
   144                 # of largefiles.
   144                         for f in lfdirstate:
   145                 def tostandins(files):
   145                             if match(f):
   146                     if not working:
   146                                 break
   147                         return files
       
   148                     newfiles = []
       
   149                     dirstate = self.dirstate
       
   150                     for f in files:
       
   151                         sf = lfutil.standin(f)
       
   152                         if sf in dirstate:
       
   153                             newfiles.append(sf)
       
   154                         elif sf in dirstate.dirs():
       
   155                             # Directory entries could be regular or
       
   156                             # standin, check both
       
   157                             newfiles.extend((f, sf))
       
   158                         else:
   147                         else:
   159                             newfiles.append(f)
   148                             return super(lfilesrepo, self).status(node1, node2,
   160                     return newfiles
   149                                     match, listignored, listclean,
   161 
   150                                     listunknown, listsubrepos)
   162                 m = copy.copy(match)
   151 
   163                 m._files = tostandins(m._files)
   152                     # Create a copy of match that matches standins instead
   164 
   153                     # of largefiles.
   165                 result = super(lfilesrepo, self).status(node1, node2, m,
   154                     def tostandins(files):
   166                     ignored, clean, unknown, listsubrepos)
   155                         if not working:
   167                 if working:
   156                             return files
   168 
   157                         newfiles = []
   169                     def sfindirstate(f):
       
   170                         sf = lfutil.standin(f)
       
   171                         dirstate = self.dirstate
   158                         dirstate = self.dirstate
   172                         return sf in dirstate or sf in dirstate.dirs()
   159                         for f in files:
   173 
   160                             sf = lfutil.standin(f)
   174                     match._files = [f for f in match._files
   161                             if sf in dirstate:
   175                                     if sfindirstate(f)]
   162                                 newfiles.append(sf)
   176                     # Don't waste time getting the ignored and unknown
   163                             elif sf in dirstate.dirs():
   177                     # files from lfdirstate
   164                                 # Directory entries could be regular or
   178                     s = lfdirstate.status(match, [], False,
   165                                 # standin, check both
   179                             listclean, False)
   166                                 newfiles.extend((f, sf))
   180                     (unsure, modified, added, removed, missing, _unknown,
       
   181                             _ignored, clean) = s
       
   182                     if parentworking:
       
   183                         for lfile in unsure:
       
   184                             standin = lfutil.standin(lfile)
       
   185                             if standin not in ctx1:
       
   186                                 # from second parent
       
   187                                 modified.append(lfile)
       
   188                             elif ctx1[standin].data().strip() \
       
   189                                     != lfutil.hashfile(self.wjoin(lfile)):
       
   190                                 modified.append(lfile)
       
   191                             else:
   167                             else:
   192                                 clean.append(lfile)
   168                                 newfiles.append(f)
   193                                 lfdirstate.normal(lfile)
   169                         return newfiles
   194                     else:
   170 
   195                         tocheck = unsure + modified + added + clean
   171                     m = copy.copy(match)
   196                         modified, added, clean = [], [], []
   172                     m._files = tostandins(m._files)
   197 
   173 
   198                         for lfile in tocheck:
   174                     result = super(lfilesrepo, self).status(node1, node2, m,
   199                             standin = lfutil.standin(lfile)
   175                         ignored, clean, unknown, listsubrepos)
   200                             if inctx(standin, ctx1):
   176                     if working:
   201                                 if ctx1[standin].data().strip() != \
   177 
   202                                         lfutil.hashfile(self.wjoin(lfile)):
   178                         def sfindirstate(f):
       
   179                             sf = lfutil.standin(f)
       
   180                             dirstate = self.dirstate
       
   181                             return sf in dirstate or sf in dirstate.dirs()
       
   182 
       
   183                         match._files = [f for f in match._files
       
   184                                         if sfindirstate(f)]
       
   185                         # Don't waste time getting the ignored and unknown
       
   186                         # files from lfdirstate
       
   187                         s = lfdirstate.status(match, [], False,
       
   188                                 listclean, False)
       
   189                         (unsure, modified, added, removed, missing, _unknown,
       
   190                                 _ignored, clean) = s
       
   191                         if parentworking:
       
   192                             for lfile in unsure:
       
   193                                 standin = lfutil.standin(lfile)
       
   194                                 if standin not in ctx1:
       
   195                                     # from second parent
       
   196                                     modified.append(lfile)
       
   197                                 elif ctx1[standin].data().strip() \
       
   198                                         != lfutil.hashfile(self.wjoin(lfile)):
   203                                     modified.append(lfile)
   199                                     modified.append(lfile)
   204                                 else:
   200                                 else:
   205                                     clean.append(lfile)
   201                                     clean.append(lfile)
   206                             else:
   202                                     lfdirstate.normal(lfile)
   207                                 added.append(lfile)
   203                         else:
   208 
   204                             tocheck = unsure + modified + added + clean
   209                     # Standins no longer found in lfdirstate has been removed
   205                             modified, added, clean = [], [], []
   210                     for standin in ctx1.manifest():
   206 
   211                         if not lfutil.isstandin(standin):
   207                             for lfile in tocheck:
   212                             continue
   208                                 standin = lfutil.standin(lfile)
   213                         lfile = lfutil.splitstandin(standin)
   209                                 if inctx(standin, ctx1):
   214                         if not match(lfile):
   210                                     if ctx1[standin].data().strip() != \
   215                             continue
   211                                             lfutil.hashfile(self.wjoin(lfile)):
   216                         if lfile not in lfdirstate:
   212                                         modified.append(lfile)
   217                             removed.append(lfile)
   213                                     else:
   218 
   214                                         clean.append(lfile)
   219                     # Filter result lists
   215                                 else:
   220                     result = list(result)
   216                                     added.append(lfile)
   221 
   217 
   222                     # Largefiles are not really removed when they're
   218                         # Standins no longer found in lfdirstate has been
   223                     # still in the normal dirstate. Likewise, normal
   219                         # removed
   224                     # files are not really removed if they are still in
   220                         for standin in ctx1.manifest():
   225                     # lfdirstate. This happens in merges where files
   221                             if not lfutil.isstandin(standin):
   226                     # change type.
   222                                 continue
   227                     removed = [f for f in removed if f not in self.dirstate]
   223                             lfile = lfutil.splitstandin(standin)
   228                     result[2] = [f for f in result[2] if f not in lfdirstate]
   224                             if not match(lfile):
   229 
   225                                 continue
   230                     lfiles = set(lfdirstate._map)
   226                             if lfile not in lfdirstate:
   231                     # Unknown files
   227                                 removed.append(lfile)
   232                     result[4] = set(result[4]).difference(lfiles)
   228 
   233                     # Ignored files
   229                         # Filter result lists
   234                     result[5] = set(result[5]).difference(lfiles)
   230                         result = list(result)
   235                     # combine normal files and largefiles
   231 
   236                     normals = [[fn for fn in filelist
   232                         # Largefiles are not really removed when they're
   237                                 if not lfutil.isstandin(fn)]
   233                         # still in the normal dirstate. Likewise, normal
   238                                for filelist in result]
   234                         # files are not really removed if they are still in
   239                     lfiles = (modified, added, removed, missing, [], [], clean)
   235                         # lfdirstate. This happens in merges where files
   240                     result = [sorted(list1 + list2)
   236                         # change type.
   241                               for (list1, list2) in zip(normals, lfiles)]
   237                         removed = [f for f in removed
   242                 else:
   238                                    if f not in self.dirstate]
   243                     def toname(f):
   239                         result[2] = [f for f in result[2]
   244                         if lfutil.isstandin(f):
   240                                      if f not in lfdirstate]
   245                             return lfutil.splitstandin(f)
   241 
   246                         return f
   242                         lfiles = set(lfdirstate._map)
   247                     result = [[toname(f) for f in items] for items in result]
   243                         # Unknown files
   248 
   244                         result[4] = set(result[4]).difference(lfiles)
   249                 lfdirstate.write()
   245                         # Ignored files
       
   246                         result[5] = set(result[5]).difference(lfiles)
       
   247                         # combine normal files and largefiles
       
   248                         normals = [[fn for fn in filelist
       
   249                                     if not lfutil.isstandin(fn)]
       
   250                                    for filelist in result]
       
   251                         lfiles = (modified, added, removed, missing, [], [],
       
   252                                   clean)
       
   253                         result = [sorted(list1 + list2)
       
   254                                   for (list1, list2) in zip(normals, lfiles)]
       
   255                     else:
       
   256                         def toname(f):
       
   257                             if lfutil.isstandin(f):
       
   258                                 return lfutil.splitstandin(f)
       
   259                             return f
       
   260                         result = [[toname(f) for f in items]
       
   261                                   for items in result]
       
   262 
       
   263                     if wlock:
       
   264                         lfdirstate.write()
       
   265 
       
   266                 finally:
       
   267                     if wlock:
       
   268                         wlock.release()
   250 
   269 
   251                 if not listunknown:
   270                 if not listunknown:
   252                     result[4] = []
   271                     result[4] = []
   253                 if not listignored:
   272                 if not listignored:
   254                     result[5] = []
   273                     result[5] = []