Ejemplo n.º 1
0
    def _get_bigfiles_status(self):
        """Return the lists of bigfiles to_expand, expanded and deleted as a tuple

        Each list includes for each bigfile the filename, sha, is_pushed bool and size
        """
        to_expand = []
        expanded = []
        deleted = []
        tree_entries = util.run('git ls-tree -l -r HEAD --full-tree').split(
            '\n')
        bigfiles = [(entry.split()[-1], entry.split()[2])
                    for entry in tree_entries
                    if entry.split()[-2] == str(SHA_FILE_SIZE)]
        pushed_files = self._transport.pushed()
        for filename, blob in bigfiles:
            relpath = self._get_relpath(filename)
            sha = util.run('git show %s' % blob)
            # Check is this is a sha (size is already correct)
            if not SHA_PATTERN.match(sha):
                # Not a bigfile sha
                continue
            is_pushed = sha in pushed_files
            try:
                size = os.path.getsize(relpath)
            except OSError, e:
                if e.errno == errno.ENOENT:
                    # No such file or directory: file was deleted
                    deleted.append((relpath, sha, is_pushed, None))
                else:
                    raise
            else:
                if size == SHA_FILE_SIZE:
                    to_expand.append((relpath, sha, is_pushed, None))
                else:
                    expanded.append((relpath, sha, is_pushed, size))
Ejemplo n.º 2
0
    def _get_bigfiles_status(self):
        """Return the lists of bigfiles to_expand, expanded and deleted as a tuple

        Each list includes for each bigfile the filename, sha, is_pushed bool and size
        """
        to_expand = []
        expanded = []
        deleted = []
        tree_entries = util.run('git ls-tree -l -r HEAD --full-tree').split('\n')
        bigfiles = [(entry.split()[-1], entry.split()[2])
                    for entry in tree_entries if entry.split()[-2] == str(SHA_FILE_SIZE)]
        pushed_files = self._transport.pushed()
        for filename, blob in bigfiles:
            relpath = self._get_relpath(filename)
            sha = util.run('git show %s' % blob)
            # Check is this is a sha (size is already correct)
            if not SHA_PATTERN.match(sha):
                # Not a bigfile sha
                continue
            is_pushed = sha in pushed_files
            try:
                size = os.path.getsize(relpath)
            except OSError, e:
                if e.errno == errno.ENOENT:
                    # No such file or directory: file was deleted
                    deleted.append((relpath, sha, is_pushed, None))
                else:
                    raise
            else:
                if size == SHA_FILE_SIZE:
                    to_expand.append((relpath, sha, is_pushed, None))
                else:
                    expanded.append((relpath, sha, is_pushed, size))
Ejemplo n.º 3
0
 def add(self, filename):
     """Add filename to .gitattributes and to the index"""
     if os.path.isfile(filename):
         gitattributes = util.get_gitattributes()
         base_name = os.path.basename(filename)
         print 'Adding %s to %s' % (base_name, gitattributes)
         with open(gitattributes, 'a') as f:
             f.write('%s filter=bigfile -crlf\n' % base_name)
         util.run('git add %s' % gitattributes)
         print 'Adding %s to the index' % filename
         util.run('git add %s' % filename)
     else:
         sys.stderr.write('%s did not match any file\n' % filename)
         sys.exit(1)
Ejemplo n.º 4
0
 def add(self, filename):
     """Add filename to .gitattributes and to the index"""
     if os.path.isfile(filename):
         gitattributes = util.get_gitattributes()
         base_name = os.path.basename(filename)
         print 'Adding %s to %s' % (base_name, gitattributes)
         with open(gitattributes, 'a') as f:
             f.write('%s filter=bigfile -crlf\n' % base_name)
         util.run('git add %s' % gitattributes)
         print 'Adding %s to the index' % filename
         util.run('git add %s' % filename)
     else:
         sys.stderr.write('%s did not match any file\n' % filename)
         sys.exit(1)
Ejemplo n.º 5
0
 def pull(self):
     """Expand bigfiles by pulling them from the server if needed"""
     to_expand, expanded, deleted = self._get_bigfiles_status()
     for filename, sha, is_pushed, size in to_expand:
         cache_file = os.path.join(self._objects, sha)
         if not os.path.isfile(cache_file):
             if self._transport.exists(sha):
                 print 'Downloading %s : %s' % (sha[:8], filename)
                 self._transport.get(sha, cache_file)
         try:
             print 'Expanding %s : %s' % (sha[:8], filename)
             shutil.copy(cache_file, filename)
         except IOError:
             print 'Could not get %s' % filename
         else:
             # Update the index
             util.run('git add %s' % filename)
Ejemplo n.º 6
0
 def pull(self):
     """Expand bigfiles by pulling them from the server if needed"""
     to_expand, expanded, deleted = self._get_bigfiles_status()
     for filename, sha, is_pushed, size in to_expand:
         cache_file = os.path.join(self._objects, sha)
         if not os.path.isfile(cache_file):
             if self._transport.exists(sha):
                 print 'Downloading %s : %s' % (sha[:8], filename)
                 self._transport.get(sha, cache_file)
         try:
             print 'Expanding %s : %s' % (sha[:8], filename)
             shutil.copy(cache_file, filename)
         except IOError:
             print 'Could not get %s' % filename
         else:
             # Update the index
             util.run('git add %s' % filename)
Ejemplo n.º 7
0
    def pull(self, files=None):
        """Expand bigfiles by pulling them from the server if needed"""
        to_expand, expanded, deleted = self._get_bigfiles_status()
        for filename, sha, is_pushed, size in to_expand:
            # If they specified a list of files to limit to, check the limit.
            if files and filename not in files:
                continue

            cache_file = os.path.join(self.objects(), sha)
            if not os.path.isfile(cache_file):
                if self.transport().exists(sha):
                    print 'Downloading %s : %s' % (sha[:8], filename)
                    temp = self._get_tempfile()
                    temp.close()  # we just need the name
                    self.transport().get(sha, temp.name)
                    os.rename(temp.name, cache_file)
            try:
                print 'Expanding %s : %s' % (sha[:8], filename)
                shutil.copy(cache_file, filename)
            except IOError:
                print 'Could not get %s' % filename
            else:
                # Update the index
                util.run('git add %s' % filename)
Ejemplo n.º 8
0
    def pull(self, files=None):
        """Expand bigfiles by pulling them from the server if needed"""
        to_expand, expanded, deleted = self._get_bigfiles_status()
        for filename, sha, is_pushed, size in to_expand:
            # If they specified a list of files to limit to, check the limit.
            if files and filename not in files:
                continue

            cache_file = os.path.join(self.objects(), sha)
            if not os.path.isfile(cache_file):
                if self.transport().exists(sha):
                    print 'Downloading %s : %s' % (sha[:8], filename)
                    temp = self._get_tempfile()
                    temp.close()     # we just need the name
                    self.transport().get(sha, temp.name)
                    os.rename(temp.name, cache_file)
            try:
                print 'Expanding %s : %s' % (sha[:8], filename)
                shutil.copy(cache_file, filename)
            except IOError:
                print 'Could not get %s' % filename
            else:
                # Update the index
                util.run('git add %s' % filename)