/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to commit.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-18 09:43:41 UTC
  • mto: (2778.5.1 vila)
  • mto: This revision was merged to the branch mainline in revision 2789.
  • Revision ID: v.ladeuil+lp@free.fr-20070718094341-edmgsog3el06yqow
Add performance analysis of missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
"""Support for committing in native Git working trees."""
19
 
 
20
 
 
21
 
from dulwich.index import (
22
 
    commit_tree,
23
 
    )
24
 
import stat
25
 
 
26
 
from bzrlib.repository import (
27
 
    CommitBuilder,
28
 
    )
29
 
 
30
 
from dulwich.objects import (
31
 
    Blob,
32
 
    Commit,
33
 
    Tree,
34
 
    )
35
 
 
36
 
 
37
 
class GitCommitBuilder(CommitBuilder):
38
 
 
39
 
    def __init__(self, *args, **kwargs):
40
 
        super(GitCommitBuilder, self).__init__(*args, **kwargs)
41
 
        self._blobs = {}
42
 
 
43
 
    def record_delete(self, path, file_id):
44
 
        self._blobs[path] = None
45
 
 
46
 
    def record_iter_changes(self, workingtree, basis_revid, iter_changes):
47
 
        index = getattr(workingtree, "index", None)
48
 
        if index is not None:
49
 
            def index_sha1(path, file_id):
50
 
                return index.get_sha1(path.encode("utf-8"))
51
 
            text_sha1 = link_sha1 = index_sha1
52
 
        else:
53
 
            def link_sha1(path, file_id):
54
 
                blob = Blob()
55
 
                blob.data = workingtree.get_symlink_target(file_id)
56
 
                return blob.id
57
 
            def text_sha1(path, file_id):
58
 
                blob = Blob()
59
 
                blob.data = workingtree.get_file_text(file_id, path)
60
 
                return blob.id
61
 
        for (file_id, path, changed_content, versioned, parent, name, kind, 
62
 
             executable) in iter_changes:
63
 
            if kind[1] in ("directory",):
64
 
                if kind[0] in ("file", "symlink"):
65
 
                    self.record_delete(path[0], file_id)
66
 
                continue
67
 
            if path[1] is None:
68
 
                self.record_delete(path[0], file_id)
69
 
                continue
70
 
            if kind == "file":
71
 
                mode = stat.S_IFREG
72
 
                sha = text_sha1(path[1], file_id)
73
 
            else:
74
 
                mode = stat.S_IFLNK
75
 
                sha = link_sha1(path[1], file_id)
76
 
            if executable:
77
 
                mode |= 0111
78
 
            self._blobs[path[1].encode("utf-8")] = (mode, sha)
79
 
            yield file_id, path, (None, None)
80
 
        # FIXME: Import all blobs not set yet, and eliminate blobs set to None
81
 
 
82
 
    def commit(self, message):
83
 
        c = Commit()
84
 
        c.tree = commit_tree(self.repository._git.object_store, self._blobs)
85
 
        c.committer = self._committer
86
 
        c.author = self._revprops.get('author', self._committer)
87
 
        c.commit_timestamp = self._timestamp
88
 
        c.author_timestamp = self._timestamp
89
 
        c.commit_timezone = self._timezone
90
 
        c.author_timezone = self._timezone
91
 
        c.message = message.encode("utf-8")
92
 
        self.repository._git.object_store.add_object(c)
93
 
        return self.repository.mapping.revision_id_foreign_to_bzr(c.id)