Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/git/objects/tag.py: 25%

47 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1# objects.py 

2# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors 

3# 

4# This module is part of GitPython and is released under 

5# the BSD License: http://www.opensource.org/licenses/bsd-license.php 

6""" Module containing all object based types. """ 

7from . import base 

8from .util import get_object_type_by_name, parse_actor_and_date 

9from ..util import hex_to_bin 

10from ..compat import defenc 

11 

12from typing import List, TYPE_CHECKING, Union 

13 

14from git.types import Literal 

15 

16if TYPE_CHECKING: 16 ↛ 17line 16 didn't jump to line 17, because the condition on line 16 was never true

17 from git.repo import Repo 

18 from git.util import Actor 

19 from .commit import Commit 

20 from .blob import Blob 

21 from .tree import Tree 

22 

23__all__ = ("TagObject",) 

24 

25 

26class TagObject(base.Object): 

27 

28 """Non-Lightweight tag carrying additional information about an object we are pointing to.""" 

29 

30 type: Literal["tag"] = "tag" 

31 __slots__ = ( 

32 "object", 

33 "tag", 

34 "tagger", 

35 "tagged_date", 

36 "tagger_tz_offset", 

37 "message", 

38 ) 

39 

40 def __init__( 

41 self, 

42 repo: "Repo", 

43 binsha: bytes, 

44 object: Union[None, base.Object] = None, 

45 tag: Union[None, str] = None, 

46 tagger: Union[None, "Actor"] = None, 

47 tagged_date: Union[int, None] = None, 

48 tagger_tz_offset: Union[int, None] = None, 

49 message: Union[str, None] = None, 

50 ) -> None: # @ReservedAssignment 

51 """Initialize a tag object with additional data 

52 

53 :param repo: repository this object is located in 

54 :param binsha: 20 byte SHA1 

55 :param object: Object instance of object we are pointing to 

56 :param tag: name of this tag 

57 :param tagger: Actor identifying the tagger 

58 :param tagged_date: int_seconds_since_epoch 

59 is the DateTime of the tag creation - use time.gmtime to convert 

60 it into a different format 

61 :param tagged_tz_offset: int_seconds_west_of_utc is the timezone that the 

62 authored_date is in, in a format similar to time.altzone""" 

63 super(TagObject, self).__init__(repo, binsha) 

64 if object is not None: 

65 self.object: Union["Commit", "Blob", "Tree", "TagObject"] = object 

66 if tag is not None: 

67 self.tag = tag 

68 if tagger is not None: 

69 self.tagger = tagger 

70 if tagged_date is not None: 

71 self.tagged_date = tagged_date 

72 if tagger_tz_offset is not None: 

73 self.tagger_tz_offset = tagger_tz_offset 

74 if message is not None: 

75 self.message = message 

76 

77 def _set_cache_(self, attr: str) -> None: 

78 """Cache all our attributes at once""" 

79 if attr in TagObject.__slots__: 

80 ostream = self.repo.odb.stream(self.binsha) 

81 lines: List[str] = ostream.read().decode(defenc, "replace").splitlines() 

82 

83 _obj, hexsha = lines[0].split(" ") 

84 _type_token, type_name = lines[1].split(" ") 

85 object_type = get_object_type_by_name(type_name.encode("ascii")) 

86 self.object = object_type(self.repo, hex_to_bin(hexsha)) 

87 

88 self.tag = lines[2][4:] # tag <tag name> 

89 

90 if len(lines) > 3: 

91 tagger_info = lines[3] # tagger <actor> <date> 

92 ( 

93 self.tagger, 

94 self.tagged_date, 

95 self.tagger_tz_offset, 

96 ) = parse_actor_and_date(tagger_info) 

97 

98 # line 4 empty - it could mark the beginning of the next header 

99 # in case there really is no message, it would not exist. Otherwise 

100 # a newline separates header from message 

101 if len(lines) > 5: 

102 self.message = "\n".join(lines[5:]) 

103 else: 

104 self.message = "" 

105 # END check our attributes 

106 else: 

107 super(TagObject, self)._set_cache_(attr)