~ubuntu-branches/ubuntu/precise/dulwich/precise-updates

« back to all changes in this revision

Viewing changes to dulwich/objects.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-08-07 15:03:44 UTC
  • mfrom: (1.2.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20110807150344-a5w6vkqtfy8fr526
Tags: 0.8.0-1
* New upstream release.
 + Adds support for IPv6 to git:// client. Closes: #631490
 + Fixes use of ~username in git:// URLs. Closes: #631483
* Bump standards version to 3.9.2 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
from dulwich.file import GitFile
42
42
from dulwich._compat import (
43
43
    make_sha,
44
 
    TreeEntryTuple,
 
44
    namedtuple,
45
45
    )
46
46
 
47
47
ZERO_SHA = "0" * 40
469
469
        return "<%s %s>" % (self.__class__.__name__, self.id)
470
470
 
471
471
    def __ne__(self, other):
472
 
        return self.id != other.id
 
472
        return not isinstance(other, ShaFile) or self.id != other.id
473
473
 
474
474
    def __eq__(self, other):
475
 
        """Return true if the sha of the two objects match.
 
475
        """Return True if the SHAs of the two objects match.
476
476
 
477
 
        The __le__ etc methods aren't overriden as they make no sense,
478
 
        certainly at this level.
 
477
        It doesn't make sense to talk about an order on ShaFiles, so we don't
 
478
        override the rich comparison methods (__le__, etc.).
479
479
        """
480
 
        return self.id == other.id
 
480
        return isinstance(other, ShaFile) and self.id == other.id
481
481
 
482
482
 
483
483
class Blob(ShaFile):
688
688
    message = serializable_property("message", "The message attached to this tag")
689
689
 
690
690
 
691
 
class TreeEntry(TreeEntryTuple):
692
 
    """Namedtuple encapsulating a single tree entry."""
 
691
class TreeEntry(namedtuple('TreeEntry', ['path', 'mode', 'sha'])):
 
692
    """Named tuple encapsulating a single tree entry."""
693
693
 
694
694
    def in_path(self, path):
695
695
        """Return a copy of this entry with the given path prepended."""
919
919
            text.append("%04o %s %s\t%s\n" % (mode, kind, hexsha, name))
920
920
        return "".join(text)
921
921
 
 
922
    def lookup_path(self, lookup_obj, path):
 
923
        """Look up an object in a Git tree.
 
924
 
 
925
        :param lookup_obj: Callback for retrieving object by SHA1
 
926
        :param path: Path to lookup
 
927
        :return: A tuple of (mode, SHA) of the resulting path.
 
928
        """
 
929
        parts = path.split('/')
 
930
        sha = self.id
 
931
        mode = None
 
932
        for p in parts:
 
933
            if not p:
 
934
                continue
 
935
            obj = lookup_obj(sha)
 
936
            if not isinstance(obj, Tree):
 
937
                raise NotTreeError(sha)
 
938
            mode, sha = obj[p]
 
939
        return mode, sha
 
940
 
922
941
 
923
942
def parse_timezone(text):
924
943
    """Parse a timezone text fragment (e.g. '+0100').