Example #1
0
def create_tag_object(name, head):
    """Create an annotated tag object from the given history.

	This rewrites a 'tag creation' history so that the head is a tag
	instead of a commit. This relies on the fact that in Subversion,
	tags are created using a 'svn cp' copy.

	Args:
	  name: Name of the tag.
	  head: Object ID of the head commit of a chain to be tagged.
	Returns:
	  The object ID of an annotated tag object, or the value of 'head'
	  if the tag could not be created.
	"""
    head_commit = gitrepo.get_object(head)

    # The tree of the commit should exactly match the tree of its parent.
    # If not, then is not a pure 'tagging' commit.
    if len(head_commit.parents) != 1:
        return head
    head_hat_commit = gitrepo.get_object(head_commit.parents[0])
    if head_commit.tree != head_hat_commit.tree:
        return head

    tag = Tag()
    tag.name = name
    tag.message = head_commit.message
    tag.tag_time = head_commit.commit_time
    tag.tag_timezone = head_commit.commit_timezone
    tag.object = (Commit, head_hat_commit.id)
    tag.tagger = head_commit.committer
    gitrepo.object_store.add_object(tag)

    return tag.id
Example #2
0
def create_commit(data, marker='Default', blob=None):
    if not blob:
        blob = Blob.from_string('The blob content %s' % marker)
    tree = Tree()
    tree.add("thefile_%s" % marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = "John Doe %s <*****@*****.**>" % marker
    cmt.author = cmt.committer = author
    tz = parse_timezone('-0200')[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = "UTF-8"
    cmt.message = "The commit message %s" % marker
    tag = Tag()
    tag.tagger = "*****@*****.**"
    tag.message = "Annotated tag"
    tag.tag_timezone = parse_timezone('-0200')[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = "v_%s_0.1" % marker
    return blob, tree, tag, cmt
def create_commit(data, marker=b"Default", blob=None):
    if not blob:
        blob = Blob.from_string(b"The blob content " + marker)
    tree = Tree()
    tree.add(b"thefile_" + marker, 0o100644, blob.id)
    cmt = Commit()
    if data:
        assert isinstance(data[-1], Commit)
        cmt.parents = [data[-1].id]
    cmt.tree = tree.id
    author = b"John Doe " + marker + b" <*****@*****.**>"
    cmt.author = cmt.committer = author
    tz = parse_timezone(b"-0200")[0]
    cmt.commit_time = cmt.author_time = int(time())
    cmt.commit_timezone = cmt.author_timezone = tz
    cmt.encoding = b"UTF-8"
    cmt.message = b"The commit message " + marker
    tag = Tag()
    tag.tagger = b"*****@*****.**"
    tag.message = b"Annotated tag"
    tag.tag_timezone = parse_timezone(b"-0200")[0]
    tag.tag_time = cmt.author_time
    tag.object = (Commit, cmt.id)
    tag.name = b"v_" + marker + b"_0.1"
    return blob, tree, tag, cmt
Example #4
0
 def tag_handler(self, cmd):
     """Process a TagCommand."""
     tag = Tag()
     tag.tagger = cmd.tagger
     tag.message = cmd.message
     tag.name = cmd.tag
     self.repo.add_object(tag)
     self.repo.refs["refs/tags/" + tag.name] = tag.id
def tag_create(repo,
               tag,
               author=None,
               message=None,
               annotated=False,
               objectish="HEAD",
               tag_time=None,
               tag_timezone=None,
               sign=False):
    """Creates a tag in git via dulwich calls:

    Args:
      repo: Path to repository
      tag: tag string
      author: tag author (optional, if annotated is set)
      message: tag message (optional)
      annotated: whether to create an annotated tag
      objectish: object the tag should point at, defaults to HEAD
      tag_time: Optional time for annotated tag
      tag_timezone: Optional timezone for annotated tag
      sign: GPG Sign the tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity(r.get_config_stack())
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            if tag_time is None:
                tag_time = int(time.time())
            tag_obj.tag_time = tag_time
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            if sign:
                import gpg
                with gpg.Context(armor=True) as c:
                    tag_obj.signature, unused_result = c.sign(
                        tag_obj.as_raw_string())
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[_make_tag_ref(tag)] = tag_id
Example #6
0
 def test_parse_no_message(self):
     x = Tag()
     x.set_raw_string(self.make_tag_text(message=None))
     self.assertEqual(None, x.message)
     self.assertEqual(
         b'Linus Torvalds <*****@*****.**>', x.tagger)
     self.assertEqual(datetime.datetime.utcfromtimestamp(x.tag_time),
                      datetime.datetime(2007, 7, 1, 19, 54, 34))
     self.assertEqual(-25200, x.tag_timezone)
     self.assertEqual(b'v2.6.22-rc7', x.name)
Example #7
0
 def add_tag(self, tag_name):
     commit = self._repo['refs/heads/master']
     tag = Tag()
     tag.name = tag_name
     tag.message = 'Tagged %s as %s' % (commit.id, tag_name)
     tag.tagger = self._author
     tag.object = (Commit, commit.id)
     tag.tag_time = int(time())
     tag.tag_timezone = self._time_zone
     self._update_store(tag)
     self._repo.refs['refs/tags/%s' % tag_name] = tag.id
Example #8
0
 def test_parse(self):
     x = Tag()
     x.set_raw_string(self.make_tag_text())
     self.assertEqual(
         "Linus Torvalds <*****@*****.**>", x.tagger)
     self.assertEqual("v2.6.22-rc7", x.name)
     object_type, object_sha = x.object
     self.assertEqual("a38d6181ff27824c79fc7df825164a212eff6a3f",
                       object_sha)
     self.assertEqual(Commit, object_type)
     self.assertEqual(datetime.datetime.utcfromtimestamp(x.tag_time),
                       datetime.datetime(2007, 7, 1, 19, 54, 34))
     self.assertEqual(-25200, x.tag_timezone)
Example #9
0
    def test_serialize_simple(self):
        x = Tag()
        x.tagger = "Jelmer Vernooij <*****@*****.**>"
        x.name = "0.1"
        x.message = "Tag 0.1"
        x.object = (3, "d80c186a03f423a81b39df39dc87fd269736ca86")
        x.tag_time = 423423423
        x.tag_timezone = 0
        self.assertEquals("""object d80c186a03f423a81b39df39dc87fd269736ca86
type blob
tag 0.1
tagger Jelmer Vernooij <*****@*****.**> 423423423 +0000

Tag 0.1""", x.as_raw_string())
Example #10
0
def tag_create(repo,
               tag,
               author=None,
               message=None,
               annotated=False,
               objectish="HEAD",
               tag_time=None,
               tag_timezone=None):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author (optional, if annotated is set)
    :param message: tag message (optional)
    :param annotated: whether to create an annotated tag
    :param objectish: object the tag should point at, defaults to HEAD
    :param tag_time: Optional time for annotated tag
    :param tag_timezone: Optional timezone for annotated tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity()
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            tag_obj.tag_time = tag_time
            if tag_time is None:
                tag_time = int(time.time())
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[b'refs/tags/' + tag] = tag_id
Example #11
0
 def test_tag_annotated(self):
     reva = self.simple_commit_a()
     o = Tag()
     o.name = b"foo"
     o.tagger = b"Jelmer <*****@*****.**>"
     o.message = b"add tag"
     o.object = (Commit, reva)
     o.tag_timezone = 0
     o.tag_time = 42
     r = GitRepo(".")
     r.object_store.add_object(o)
     r[b'refs/tags/foo'] = o.id
     thebranch = Branch.open('.')
     self.assertEqual(
         {"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
         thebranch.tags.get_tag_dict())
Example #12
0
    def test_parse_no_tagger(self):
        x = Tag()
        x.set_raw_string("""object a38d6181ff27824c79fc7df825164a212eff6a3f
type commit
tag v2.6.22-rc7

Linux 2.6.22-rc7
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGiAaAF3YsRnbiHLsRAitMAKCiLboJkQECM/jpYsY3WPfvUgLXkACgg3ql
OK2XeQOiEeXtT76rV4t2WR4=
=ivrA
-----END PGP SIGNATURE-----
""")
        self.assertEquals(None, x.tagger)
        self.assertEquals("v2.6.22-rc7", x.name)
Example #13
0
    def test_parse_ctime(self):
        x = Tag()
        x.set_raw_string("""object a38d6181ff27824c79fc7df825164a212eff6a3f
type commit
tag v2.6.22-rc7
tagger Linus Torvalds <*****@*****.**> Sun Jul 1 12:54:34 2007 -0700

Linux 2.6.22-rc7
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGiAaAF3YsRnbiHLsRAitMAKCiLboJkQECM/jpYsY3WPfvUgLXkACgg3ql
OK2XeQOiEeXtT76rV4t2WR4=
=ivrA
-----END PGP SIGNATURE-----
""")
        self.assertEquals("Linus Torvalds <*****@*****.**>", x.tagger)
        self.assertEquals("v2.6.22-rc7", x.name)
Example #14
0
 def test_tagged_tree(self):
     r = self.make_git_repo("d")
     os.chdir("d")
     bb = GitBranchBuilder()
     bb.set_file("foobar", b"fooll\nbar\n", False)
     mark = bb.commit(b"Somebody <*****@*****.**>", b"nextmsg")
     marks = bb.finish()
     gitsha = marks[mark]
     tag = Tag()
     tag.name = b"sometag"
     tag.tag_time = int(time.time())
     tag.tag_timezone = 0
     tag.tagger = b"Somebody <*****@*****.**>"
     tag.message = b"Created tag pointed at tree"
     tag.object = (Tree, r[gitsha].tree)
     r.object_store.add_object(tag)
     r[b"refs/tags/sometag"] = tag
     os.chdir("..")
     oldrepo = self.open_git_repo("d")
     revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
     newrepo = self.clone_git_repo("d", "f")
     self.assertEqual(set([revid]), set(newrepo.all_revision_ids()))
Example #15
0
def tag(repo, tag, author, message):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author
    :param repo: tag message
    """

    r = open_repo(repo)

    # Create the tag object
    tag_obj = Tag()
    tag_obj.tagger = author
    tag_obj.message = message
    tag_obj.name = tag
    tag_obj.object = (Commit, r.refs['HEAD'])
    tag_obj.tag_time = int(time.time())
    tag_obj.tag_timezone = parse_timezone('-0200')[0]

    # Add tag to the object store
    r.object_store.add_object(tag_obj)
    r.refs['refs/tags/' + tag] = tag_obj.id
Example #16
0
 def test_parse_no_tagger(self):
     x = Tag()
     x.set_raw_string(self.make_tag_text(tagger=None))
     self.assertEqual(None, x.tagger)
     self.assertEqual("v2.6.22-rc7", x.name)