github.com/whamcloud/lemur@v0.0.0-20190827193804-4655df8a52af/packaging/ci/lambda/GitPullS3/pygit2/submodule.py (about)

     1  # -*- coding: utf-8 -*-
     2  #
     3  # Copyright 2010-2015 The pygit2 contributors
     4  #
     5  # This file is free software; you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License, version 2,
     7  # as published by the Free Software Foundation.
     8  #
     9  # In addition to the permissions in the GNU General Public License,
    10  # the authors give you unlimited permission to link the compiled
    11  # version of this file into combinations with other programs,
    12  # and to distribute those combinations without any restriction
    13  # coming from the use of this file.  (The General Public License
    14  # restrictions do apply in other respects; for example, they cover
    15  # modification of the file, and distribution when not linked into
    16  # a combined executable.)
    17  #
    18  # This file is distributed in the hope that it will be useful, but
    19  # WITHOUT ANY WARRANTY; without even the implied warranty of
    20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    21  # General Public License for more details.
    22  #
    23  # You should have received a copy of the GNU General Public License
    24  # along with this program; see the file COPYING.  If not, write to
    25  # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
    26  # Boston, MA 02110-1301, USA.
    27  
    28  
    29  # Import from the future
    30  from __future__ import absolute_import, unicode_literals
    31  
    32  from .errors import check_error
    33  from .ffi import ffi, C
    34  
    35  class Submodule(object):
    36  
    37      @classmethod
    38      def _from_c(cls, repo, cptr):
    39          subm = cls.__new__(cls)
    40  
    41          subm._repo = repo
    42          subm._subm = cptr
    43  
    44          return subm
    45  
    46      def __del__(self):
    47          C.git_submodule_free(self._subm)
    48  
    49      def open(self):
    50          """Open the repository for a submodule."""
    51          crepo = ffi.new('git_repository **')
    52          err = C.git_submodule_open(crepo, self._subm)
    53          check_error(err)
    54  
    55          return self._repo._from_c(crepo[0], True)
    56  
    57      @property
    58      def name(self):
    59          """Name of the submodule."""
    60          name = C.git_submodule_name(self._subm)
    61          return ffi.string(name).decode('utf-8')
    62  
    63      @property
    64      def path(self):
    65          """Path of the submodule."""
    66          path = C.git_submodule_path(self._subm)
    67          return ffi.string(path).decode('utf-8')
    68  
    69      @property
    70      def url(self):
    71          """URL of the submodule."""
    72          url = C.git_submodule_url(self._subm)
    73          return ffi.string(url).decode('utf-8')
    74  
    75      @property
    76      def branch(self):
    77          """Branch that is to be tracked by the submodule."""
    78          branch = C.git_submodule_branch(self._subm)
    79          return ffi.string(branch).decode('utf-8')