~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Aaron Bentley
  • Date: 2005-10-03 19:50:36 UTC
  • mfrom: (1399)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: abentley@panoramicfeedback.com-20051003195036-28dbd56f0e852b08
Merged latest from Robert Collins

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from bzrlib.revision import common_ancestor, MultipleRevisionSources
37
37
from bzrlib.errors import NoSuchRevision
38
38
 
 
39
# TODO: build_working_dir can be built on something simpler than merge()
 
40
 
 
41
# FIXME: merge() parameters seem oriented towards the command line
39
42
 
40
43
# comments from abentley on irc: merge happens in two stages, each
41
44
# of which generates a changeset object
224
227
        self.tree = tree
225
228
        self.tempdir = tempdir
226
229
        os.mkdir(os.path.join(self.tempdir, "texts"))
 
230
        os.mkdir(os.path.join(self.tempdir, "symlinks"))
227
231
        self.cached = {}
228
232
 
229
233
    def __iter__(self):
238
242
    def get_file_sha1(self, id):
239
243
        return self.tree.get_file_sha1(id)
240
244
 
 
245
    def is_executable(self, id):
 
246
        return self.tree.is_executable(id)
 
247
 
241
248
    def id2path(self, file_id):
242
249
        return self.tree.id2path(file_id)
243
250
 
260
267
        if self.root is not None:
261
268
            return self.tree.abspath(self.tree.id2path(id))
262
269
        else:
263
 
            if self.tree.inventory[id].kind in ("directory", "root_directory"):
 
270
            kind = self.tree.inventory[id].kind
 
271
            if kind in ("directory", "root_directory"):
264
272
                return self.tempdir
265
273
            if not self.cached.has_key(id):
266
 
                path = os.path.join(self.tempdir, "texts", id)
267
 
                outfile = file(path, "wb")
268
 
                outfile.write(self.tree.get_file(id).read())
269
 
                assert(os.path.exists(path))
 
274
                if kind == "file":
 
275
                    path = os.path.join(self.tempdir, "texts", id)
 
276
                    outfile = file(path, "wb")
 
277
                    outfile.write(self.tree.get_file(id).read())
 
278
                    assert(bzrlib.osutils.lexists(path))
 
279
                    if self.tree.is_executable(id):
 
280
                        os.chmod(path, 0755)
 
281
                else:
 
282
                    assert kind == "symlink"
 
283
                    path = os.path.join(self.tempdir, "symlinks", id)
 
284
                    target = self.tree.get_symlink_target(id)
 
285
                    os.symlink(target, path)
270
286
                self.cached[id] = path
271
287
            return self.cached[id]
272
288
 
273
289
 
 
290
def build_working_dir(to_dir):
 
291
    """Build a working directory in an empty directory.
 
292
 
 
293
    to_dir is a directory containing branch metadata but no working files,
 
294
    typically constructed by cloning an existing branch. 
 
295
 
 
296
    This is split out as a special idiomatic case of merge.  It could
 
297
    eventually be done by just building the tree directly calling into 
 
298
    lower-level code (e.g. constructing a changeset).
 
299
    """
 
300
    merge((to_dir, -1), (to_dir, 0), this_dir=to_dir,
 
301
          check_clean=False, ignore_zero=True)
 
302
 
274
303
 
275
304
def merge(other_revision, base_revision,
276
305
          check_clean=True, ignore_zero=False,
287
316
    check_clean
288
317
        If true, this_dir must have no uncommitted changes before the
289
318
        merge begins.
 
319
    ignore_zero - If true, suppress the "zero conflicts" message when 
 
320
        there are no conflicts; should be set when doing something we expect
 
321
        to complete perfectly.
290
322
 
291
323
    All available ancestors of other_revision and base_revision are
292
324
    automatically pulled into the branch.