~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/status.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-10 01:12:04 UTC
  • mfrom: (3992.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090210011204-6m3q6f6o07xmzthe
Handle non-existent files in status (Karl Fogel, #306394)

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        old.lock_read()
104
104
        new.lock_read()
105
105
        try:
106
 
            _raise_if_nonexistent(specific_files, old, new)
 
106
            specific_files, nonexistents \
 
107
                = _filter_nonexistent(specific_files, old, new)
107
108
            want_unversioned = not versioned
108
109
            if short:
109
110
                changes = new.iter_changes(old, show_unchanged, specific_files,
137
138
                else:
138
139
                    prefix = ' '
139
140
                to_file.write("%s %s\n" % (prefix, conflict))
 
141
            # Show files that were requested but don't exist (and are
 
142
            # not versioned).  We don't involve delta in this; these
 
143
            # paths are really the province of just the status
 
144
            # command, since they have more to do with how it was
 
145
            # invoked than with the tree it's operating on.
 
146
            if nonexistents and not short:
 
147
                to_file.write("nonexistent:\n")
 
148
            for nonexistent in nonexistents:
 
149
                # We could calculate prefix outside the loop but, given
 
150
                # how rarely this ought to happen, it's OK and arguably
 
151
                # slightly faster to do it here (ala conflicts above)
 
152
                if short:
 
153
                    prefix = 'X  '
 
154
                else:
 
155
                    prefix = ' '
 
156
                to_file.write("%s %s\n" % (prefix, nonexistent))
140
157
            if (new_is_working_tree and show_pending):
141
158
                show_pending_merges(new, to_file, short, verbose=verbose)
142
159
        finally:
143
160
            old.unlock()
144
161
            new.unlock()
 
162
            if nonexistents:
 
163
              raise errors.PathsDoNotExist(nonexistents)
145
164
    finally:
146
165
        wt.unlock()
147
166
 
254
273
            to_file.write(sub_prefix + log_message + '\n')
255
274
 
256
275
 
257
 
def _raise_if_nonexistent(paths, old_tree, new_tree):
258
 
    """Complain if paths are not in either inventory or tree.
259
 
 
260
 
    It's OK with the files exist in either tree's inventory, or 
261
 
    if they exist in the tree but are not versioned.
262
 
    
 
276
def _filter_nonexistent(orig_paths, old_tree, new_tree):
 
277
    """Convert orig_paths to two sorted lists and return them.
 
278
 
 
279
    The first is orig_paths paths minus the items in the second list,
 
280
    and the second list is paths that are not in either inventory or
 
281
    tree (they don't qualify if they exist in the tree's inventory, or
 
282
    if they exist in the tree but are not versioned.)
 
283
 
 
284
    If either of the two lists is empty, return it as an empty list.
 
285
 
263
286
    This can be used by operations such as bzr status that can accept
264
287
    unknown or ignored files.
265
288
    """
266
 
    mutter("check paths: %r", paths)
267
 
    if not paths:
268
 
        return
269
 
    s = old_tree.filter_unversioned_files(paths)
 
289
    mutter("check paths: %r", orig_paths)
 
290
    if not orig_paths:
 
291
        return orig_paths, []
 
292
    s = old_tree.filter_unversioned_files(orig_paths)
270
293
    s = new_tree.filter_unversioned_files(s)
271
 
    s = [path for path in s if not new_tree.has_filename(path)]
272
 
    if s:
273
 
        raise errors.PathsDoNotExist(sorted(s))
274
 
 
275
 
 
 
294
    nonexistent = [path for path in s if not new_tree.has_filename(path)]
 
295
    remaining   = [path for path in orig_paths if not path in nonexistent]
 
296
    # Sorting the 'remaining' list doesn't have much effect in
 
297
    # practice, since the various status output sections will sort
 
298
    # their groups individually.  But for consistency of this
 
299
    # function's API, it's better to sort both than just 'nonexistent'.
 
300
    return sorted(remaining), sorted(nonexistent)