/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 bzrlib/commit.py

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
 
19
 
# FIXME: "bzr commit doc/format" commits doc/format.txt!
20
 
 
21
19
def commit(branch, message,
22
20
           timestamp=None,
23
21
           timezone=None,
24
22
           committer=None,
25
23
           verbose=True,
26
24
           specific_files=None,
27
 
           rev_id=None,
28
 
           allow_pointless=True):
 
25
           rev_id=None):
29
26
    """Commit working copy as a new revision.
30
27
 
31
28
    The basic approach is to add all the file texts into the
42
39
    be robust against files disappearing, moving, etc.  So the
43
40
    whole thing is a bit hard.
44
41
 
45
 
    This raises PointlessCommit if there are no changes, no new merges,
46
 
    and allow_pointless  is false.
47
 
 
48
42
    timestamp -- if not None, seconds-since-epoch for a
49
43
         postdated/predated commit.
50
44
 
63
57
 
64
58
    from bzrlib.osutils import local_time_offset, username
65
59
    from bzrlib.branch import gen_file_id
66
 
    from bzrlib.errors import BzrError, PointlessCommit
 
60
    from bzrlib.errors import BzrError
67
61
    from bzrlib.revision import Revision, RevisionReference
68
62
    from bzrlib.trace import mutter, note
69
 
    from bzrlib.xml import pack_xml
70
63
 
71
64
    branch.lock_write()
72
65
 
87
80
        if verbose:
88
81
            note('looking for changes...')
89
82
 
90
 
        pending_merges = branch.pending_merges()
91
 
 
92
 
        missing_ids, new_inv, any_changes = \
93
 
                     _gather_commit(branch,
94
 
                                    work_tree,
95
 
                                    work_inv,
96
 
                                    basis_inv,
97
 
                                    specific_files,
98
 
                                    verbose)
99
 
 
100
 
        if not (any_changes or allow_pointless or pending_merges):
101
 
            raise PointlessCommit()
 
83
        missing_ids, new_inv = _gather_commit(branch,
 
84
                                              work_tree,
 
85
                                              work_inv,
 
86
                                              basis_inv,
 
87
                                              specific_files,
 
88
                                              verbose)
102
89
 
103
90
        for file_id in missing_ids:
104
91
            # Any files that have been deleted are now removed from the
121
108
        inv_id = rev_id
122
109
 
123
110
        inv_tmp = tempfile.TemporaryFile()
124
 
        pack_xml(new_inv, inv_tmp)
 
111
        new_inv.write_xml(inv_tmp)
125
112
        inv_tmp.seek(0)
126
113
        branch.inventory_store.add(inv_tmp, inv_id)
127
114
        mutter('new inventory_id is {%s}' % inv_id)
151
138
                       inventory_sha1=inv_sha1,
152
139
                       revision_id=rev_id)
153
140
 
154
 
        rev.parents = []
155
141
        precursor_id = branch.last_patch()
156
142
        if precursor_id:
157
143
            precursor_sha1 = branch.get_revision_sha1(precursor_id)
158
 
            rev.parents.append(RevisionReference(precursor_id, precursor_sha1))
159
 
        for merge_rev in pending_merges:
160
 
            rev.parents.append(RevisionReference(merge_rev))            
 
144
            rev.parents = [RevisionReference(precursor_id, precursor_sha1)]
161
145
 
162
146
        rev_tmp = tempfile.TemporaryFile()
163
 
        pack_xml(rev, rev_tmp)
 
147
        rev.write_xml(rev_tmp)
164
148
        rev_tmp.seek(0)
165
149
        branch.revision_store.add(rev_tmp, rev_id)
166
150
        mutter("new revision_id is {%s}" % rev_id)
177
161
 
178
162
        branch.append_revision(rev_id)
179
163
 
180
 
        branch.set_pending_merges([])
181
 
 
182
164
        if verbose:
183
165
            note("commited r%d" % branch.revno())
184
166
    finally:
200
182
                   verbose):
201
183
    """Build inventory preparatory to commit.
202
184
 
203
 
    Returns missing_ids, new_inv, any_changes.
204
 
 
205
185
    This adds any changed files into the text store, and sets their
206
186
    test-id, sha and size in the returned inventory appropriately.
207
187
 
211
191
        working inventory.
212
192
    """
213
193
    from bzrlib.inventory import Inventory
214
 
    from bzrlib.osutils import isdir, isfile, sha_string, quotefn, \
 
194
    from osutils import isdir, isfile, sha_string, quotefn, \
215
195
         local_time_offset, username, kind_marker, is_inside_any
216
196
    
217
 
    from bzrlib.branch import gen_file_id
218
 
    from bzrlib.errors import BzrError
219
 
    from bzrlib.revision import Revision
 
197
    from branch import gen_file_id
 
198
    from errors import BzrError
 
199
    from revision import Revision
220
200
    from bzrlib.trace import mutter, note
221
201
 
222
 
    any_changes = False
223
 
    inv = Inventory(work_inv.root.file_id)
 
202
    inv = Inventory()
224
203
    missing_ids = []
225
204
    
226
205
    for path, entry in work_inv.iter_entries():
232
211
        mutter('commit prep file %s, id %r ' % (p, file_id))
233
212
 
234
213
        if specific_files and not is_inside_any(specific_files, path):
235
 
            mutter('  skipping file excluded from commit')
236
214
            if basis_inv.has_id(file_id):
237
215
                # carry over with previous state
238
216
                inv.add(basis_inv[file_id].copy())
244
222
        if not work_tree.has_id(file_id):
245
223
            if verbose:
246
224
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
247
 
                any_changes = True
248
225
            mutter("    file is missing, removing from inventory")
249
226
            missing_ids.append(file_id)
250
227
            continue
296
273
            marked = path + kind_marker(entry.kind)
297
274
            if not old_ie:
298
275
                print 'added', marked
299
 
                any_changes = True
300
276
            elif old_ie == entry:
301
277
                pass                    # unchanged
302
278
            elif (old_ie.name == entry.name
303
279
                  and old_ie.parent_id == entry.parent_id):
304
280
                print 'modified', marked
305
 
                any_changes = True
306
281
            else:
307
282
                print 'renamed', marked
308
 
                any_changes = True
309
283
                        
310
 
    return missing_ids, inv, any_changes
 
284
    return missing_ids, inv
311
285
 
312
286