~arankine/bzr-xmloutput/authors

« back to all changes in this revision

Viewing changes to statusxml.py

  • Committer: guillo.gonzo at gmail
  • Date: 2009-07-02 17:15:59 UTC
  • mfrom: (124.2.4 misc-test-fixes)
  • Revision ID: guillo.gonzo@gmail.com-20090702171559-b5m6q4jyw04ezgrn
mergeĀ lp:~verterok/bzr-xmloutput/misc-test-fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# -*- encoding: utf-8 -*-
3
3
# Copyright (C) 2007, 2008, 2009 Guillermo Gonzalez
4
4
#
5
 
# The code taken from bzrlib is under: Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
5
# The code taken from bzrlib is under: Copyright (C) 2005-2007 Canonical Ltd
6
6
#
7
7
# This program is free software; you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
38
38
import logxml
39
39
""")
40
40
 
41
 
from bzrlib import user_encoding
42
41
 
43
42
def show_tree_status_xml(wt, show_unchanged=None,
44
43
                     specific_files=None,
60
59
    <modified/>
61
60
    <kind changed/>
62
61
    <unknown/>
63
 
    
 
62
 
64
63
    Each group can have multiple child's of this element's:
65
64
 
66
65
    <file [oldpath] [oldkind, newkind] [fid]>
67
66
    <directory [oldpath] [oldkind, newkind] [suffix]>
68
67
 
69
 
    A simple example: 
 
68
    A simple example:
70
69
    <status workingtree_root="/home/guillo/Unison-root/sandbox/bazaar/bzr/0.15/">
71
70
        <renamed>
72
71
            <file oldpath="INSTALL"  >INSTALL.txt</file>
83
82
        </unknown>
84
83
    </status>
85
84
 
86
 
    By default this compares the working tree to a previous revision. 
87
 
    If the revision argument is given, summarizes changes between the 
 
85
    By default this compares the working tree to a previous revision.
 
86
    If the revision argument is given, summarizes changes between the
88
87
    working tree and another, or between two revisions.
89
88
 
90
 
    The result is written out as Unicode and to_file should be able 
 
89
    The result is written out as Unicode and to_file should be able
91
90
    to encode that.
92
91
 
93
92
    If showing the status of a working tree, extra information is included
94
93
    about unknown files, conflicts, and pending merges.
95
94
 
96
 
    :param show_unchanged: Deprecated parameter. If set, includes unchanged 
 
95
    :param show_unchanged: Deprecated parameter. If set, includes unchanged
97
96
        files.
98
97
    :param specific_files: If set, a list of filenames whose status should be
99
 
        shown.  It is an error to give a filename that is not in the working 
 
98
        shown.  It is an error to give a filename that is not in the working
100
99
        tree, or in the working inventory or in the basis inventory.
101
100
    :param show_ids: If set, includes each file's id.
102
101
    :param to_file: If set, write to this file (default stdout.)
113
112
 
114
113
    if to_file is None:
115
114
        to_file = sys.stdout
116
 
    
 
115
 
117
116
    wt.lock_read()
118
117
    try:
119
118
        new_is_working_tree = True
162
161
                delta.unversioned if not new.is_ignored(unversioned[0])]
163
162
            show_tree_xml(delta, to_file,
164
163
                       show_ids=show_ids,
165
 
                       show_unchanged=show_unchanged, 
 
164
                       show_unchanged=show_unchanged,
166
165
                       show_unversioned=want_unversioned)
167
 
            # show the new conflicts only for now. XXX: get them from the 
 
166
            # show the new conflicts only for now. XXX: get them from the
168
167
            # delta.
169
168
            conflicts = new.conflicts()
170
169
            if specific_files is not None:
173
172
            if len(conflicts) > 0:
174
173
                to_file.write("<conflicts>")
175
174
                for conflict in conflicts:
176
 
                    to_file.write('<conflict type="%s">%s</conflict>' % 
177
 
                                  (conflict.typestring, _escape_cdata(conflict.path)))
 
175
                    to_file.write('<conflict type="%s">%s</conflict>' %
 
176
                                  (conflict.typestring,
 
177
                                   _escape_cdata(conflict.path)))
178
178
                to_file.write("</conflicts>")
179
179
            if nonexistents:
180
180
                to_file.write('<nonexistents>')
196
196
    parents = new.get_parent_ids()
197
197
    if len(parents) < 2:
198
198
        return
199
 
    
 
199
 
200
200
    pending = parents[1:]
201
201
    branch = new.branch
202
202
    last_revision = parents[0]
203
203
    to_file.write('<pending_merges>')
204
 
    # TODO: this could be improved using merge_sorted - we'd get the same 
 
204
    # TODO: this could be improved using merge_sorted - we'd get the same
205
205
    # output rather than one level of indent.
206
206
    graph = branch.repository.get_graph()
207
207
    other_revisions = [last_revision]
213
213
            show_ghost(to_file, merge)
214
214
            other_revisions.append(merge)
215
215
            continue
216
 
        
 
216
 
217
217
        # Log the merge, as it gets a slightly different formatting
218
218
        to_file.write(logxml.line_log(rev))
219
219
        # Find all of the revisions in the merge source, which are not in the
236
236
                    revisions[revision_id] = None
237
237
                else:
238
238
                    revisions[revision_id] = rev
239
 
                    
 
239
 
240
240
        # Display the revisions brought in by this merge.
241
241
        rev_id_iterator = status._get_sorted_revisions(merge, merge_extra,
242
242
                            branch.repository.get_parent_map(merge_extra))
273
273
            if len(item) == 5 and item[4]:
274
274
                path += '*'
275
275
            if show_ids:
276
 
                kind_id=''
 
276
                kind_id = ''
277
277
                if fid:
278
 
                    kind_id=get_kind_id_element(kind, fid)
279
 
                to_file.write('<%s %s>%s</%s>' % (kind, kind_id, 
 
278
                    kind_id = get_kind_id_element(kind, fid)
 
279
                to_file.write('<%s %s>%s</%s>' % (kind, kind_id,
280
280
                                                  _escape_cdata(path), kind))
281
281
            else:
282
282
                to_file.write('<%s>%s</%s>' % (kind, _escape_cdata(path), kind))
285
285
        to_file.write('<removed>')
286
286
        show_list(delta.removed)
287
287
        to_file.write('</removed>')
288
 
    
 
288
 
289
289
    if delta.added:
290
290
        to_file.write('<added>')
291
291
        show_list(delta.added)
292
292
        to_file.write('</added>')
293
 
    
 
293
 
294
294
    extra_modified = []
295
295
    if delta.renamed:
296
296
        to_file.write('<renamed>')
297
 
        for (oldpath, newpath, fid, kind, 
 
297
        for (oldpath, newpath, fid, kind,
298
298
             text_modified, meta_modified) in delta.renamed:
299
299
            if text_modified or meta_modified:
300
 
                extra_modified.append((newpath, fid, kind, 
 
300
                extra_modified.append((newpath, fid, kind,
301
301
                                text_modified, meta_modified))
302
302
            metamodified = ''
303
303
            if meta_modified:
304
304
                metamodified = 'meta_modified="true"'
305
305
            if show_ids:
306
 
                kind_id=''
 
306
                kind_id = ''
307
307
                if fid:
308
 
                    kind_id=get_kind_id_element(kind, fid)
 
308
                    kind_id = get_kind_id_element(kind, fid)
309
309
                to_file.write('<%s oldpath="%s" %s %s>%s</%s>' % \
310
 
                        (kind, _escape_cdata(oldpath), metamodified, 
 
310
                        (kind, _escape_cdata(oldpath), metamodified,
311
311
                         kind_id, _escape_cdata(newpath), kind))
312
 
            else: 
 
312
            else:
313
313
                to_file.write('<%s oldpath="%s" %s >%s</%s>' % \
314
 
                        (kind, _escape_cdata(oldpath), metamodified, 
 
314
                        (kind, _escape_cdata(oldpath), metamodified,
315
315
                         _escape_cdata(newpath), kind))
316
316
        to_file.write('</renamed>')
317
317
 
323
323
            else:
324
324
                suffix = ''
325
325
            to_file.write('<%s oldkind="%s" %s>%s</%s>' % \
326
 
                       (new_kind, old_kind, suffix, 
 
326
                       (new_kind, old_kind, suffix,
327
327
                        _escape_cdata(path), new_kind))
328
328
        to_file.write('</kind_changed>')
329
329
 
332
332
        show_list(delta.modified)
333
333
        show_list(extra_modified)
334
334
        to_file.write('</modified>')
335
 
            
 
335
 
336
336
    if show_unchanged and delta.unchanged:
337
337
        to_file.write('<unchanged>')
338
338
        show_list(delta.unchanged)
344
344
        to_file.write('</unknown>')
345
345
 
346
346
def get_kind_id_element(kind, fid):
347
 
    kind_id=''
 
347
    kind_id = ''
348
348
    if kind == 'directory':
349
 
        kind_id='suffix="%s"' % fid
 
349
        kind_id = 'suffix="%s"' % fid
350
350
    elif kind == 'symlink':
351
 
        kind_id=''
 
351
        kind_id = ''
352
352
    else:
353
 
        kind_id='fid="%s"' %fid
 
353
        kind_id = 'fid="%s"' % fid
354
354
    return kind_id
355
355