~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2005-09-01 11:19:08 UTC
  • Revision ID: mbp@sourcefrog.net-20050901111907-ff5ac13ee6fedc85
- split commit message editor functions out into own file

Show diffs side-by-side

added added

removed removed

Lines of Context:
950
950
            unchanged=False):
951
951
        from bzrlib.errors import PointlessCommit
952
952
        from bzrlib.msgeditor import edit_commit_message
953
 
        from bzrlib.status import show_status
954
 
        from cStringIO import StringIO
955
953
 
956
 
        b = find_branch('.')
957
 
        if selected_list:
958
 
            selected_list = [b.relpath(s) for s in selected_list]
959
 
            
 
954
        ## Warning: shadows builtin file()
960
955
        if not message and not file:
961
 
            catcher = StringIO()
962
 
            show_status(b, specific_files=selected_list,
963
 
                        to_file=catcher)
964
 
            message = edit_commit_message(catcher.getvalue())
 
956
            # FIXME: Ugly; change status code to send to a provided function?
 
957
            
 
958
            import cStringIO
 
959
            stdout = sys.stdout
 
960
            catcher = cStringIO.StringIO()
 
961
            sys.stdout = catcher
 
962
            cmd_status().run(file_list=selected_list)
 
963
            info = catcher.getvalue()
 
964
            sys.stdout = stdout
 
965
            message = edit_commit_message(info)
965
966
            
966
967
            if message is None:
967
 
                raise BzrCommandError("please specify a commit message"
968
 
                                      " with either --message or --file")
 
968
                raise BzrCommandError("please specify a commit message",
 
969
                                      ["use either --message or --file"])
969
970
        elif message and file:
970
971
            raise BzrCommandError("please specify either --message or --file")
971
972
        
973
974
            import codecs
974
975
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
975
976
 
 
977
        b = find_branch('.')
 
978
        if selected_list:
 
979
            selected_list = [b.relpath(s) for s in selected_list]
 
980
            
976
981
        try:
977
982
            b.commit(message, verbose=verbose,
978
983
                     specific_files=selected_list,
1144
1149
class cmd_merge(Command):
1145
1150
    """Perform a three-way merge.
1146
1151
    
1147
 
    The branch is the branch you will merge from.  By default, it will
1148
 
    merge the latest revision.  If you specify a revision, that
1149
 
    revision will be merged.  If you specify two revisions, the first
1150
 
    will be used as a BASE, and the second one as OTHER.  Revision
1151
 
    numbers are always relative to the specified branch.
1152
 
 
1153
 
    By default bzr will try to merge in all new work from the other
1154
 
    branch, automatically determining an appropriate base.  If this
1155
 
    fails, you may need to give an explicit base.
 
1152
    The branch is the branch you will merge from.  By default, it will merge
 
1153
    the latest revision.  If you specify a revision, that revision will be
 
1154
    merged.  If you specify two revisions, the first will be used as a BASE, 
 
1155
    and the second one as OTHER.  Revision numbers are always relative to the
 
1156
    specified branch.
1156
1157
    
1157
1158
    Examples:
1158
1159
 
1180
1181
 
1181
1182
        if revision is None or len(revision) < 1:
1182
1183
            base = [None, None]
1183
 
            other = [branch, -1]
 
1184
            other = (branch, -1)
1184
1185
        else:
1185
1186
            if len(revision) == 1:
1186
 
                other = [branch, revision[0]]
1187
 
                base = [None, None]
 
1187
                other = (branch, revision[0])
 
1188
                base = (None, None)
1188
1189
            else:
1189
1190
                assert len(revision) == 2
1190
1191
                if None in revision:
1191
1192
                    raise BzrCommandError(
1192
1193
                        "Merge doesn't permit that revision specifier.")
1193
 
                base = [branch, revision[0]]
1194
 
                other = [branch, revision[1]]
1195
 
 
1196
 
        try:
1197
 
            merge(other, base, check_clean=(not force), merge_type=merge_type)
1198
 
        except bzrlib.errors.AmbiguousBase, e:
1199
 
            m = ("sorry, bzr can't determine the write merge base yet\n"
1200
 
                 "candidates are:\n  "
1201
 
                 + "\n  ".join(e.bases)
1202
 
                 + "\n"
1203
 
                 "please specify an explicit base with -r,\n"
1204
 
                 "and (if you want) report this to the bzr developers\n")
1205
 
            log_error(m)
 
1194
                base = (branch, revision[0])
 
1195
                other = (branch, revision[1])
 
1196
            
 
1197
        merge(other, base, check_clean=(not force), merge_type=merge_type)
1206
1198
 
1207
1199
 
1208
1200
class cmd_revert(Command):