296 def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): |
296 def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): |
297 if dry_run is None: |
297 if dry_run is None: |
298 dry_run = opts.get('dry_run') |
298 dry_run = opts.get('dry_run') |
299 if similarity is None: |
299 if similarity is None: |
300 similarity = float(opts.get('similarity') or 0) |
300 similarity = float(opts.get('similarity') or 0) |
301 unknown, deleted = [], [] |
301 # we'd use status here, except handling of symlinks and ignore is tricky |
|
302 added, unknown, deleted, removed = [], [], [], [] |
302 audit_path = util.path_auditor(repo.root) |
303 audit_path = util.path_auditor(repo.root) |
303 m = match(repo, pats, opts) |
304 m = match(repo, pats, opts) |
304 for abs in repo.walk(m): |
305 for abs in repo.walk(m): |
305 target = repo.wjoin(abs) |
306 target = repo.wjoin(abs) |
306 good = True |
307 good = True |
312 exact = m.exact(abs) |
313 exact = m.exact(abs) |
313 if good and abs not in repo.dirstate: |
314 if good and abs not in repo.dirstate: |
314 unknown.append(abs) |
315 unknown.append(abs) |
315 if repo.ui.verbose or not exact: |
316 if repo.ui.verbose or not exact: |
316 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
317 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
317 if repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) |
318 elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) |
318 or (os.path.isdir(target) and not os.path.islink(target))): |
319 or (os.path.isdir(target) and not os.path.islink(target))): |
319 deleted.append(abs) |
320 deleted.append(abs) |
320 if repo.ui.verbose or not exact: |
321 if repo.ui.verbose or not exact: |
321 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
322 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
323 # for finding renames |
|
324 elif repo.dirstate[abs] == 'r': |
|
325 removed.append(abs) |
|
326 elif repo.dirstate[abs] == 'a': |
|
327 added.append(abs) |
322 if not dry_run: |
328 if not dry_run: |
323 repo.remove(deleted) |
329 repo.remove(deleted) |
324 repo.add(unknown) |
330 repo.add(unknown) |
325 if similarity > 0: |
331 if similarity > 0: |
326 for old, new, score in findrenames(repo, unknown, deleted, similarity): |
332 for old, new, score in findrenames(repo, added + unknown, |
|
333 removed + deleted, similarity): |
327 if repo.ui.verbose or not m.exact(old) or not m.exact(new): |
334 if repo.ui.verbose or not m.exact(old) or not m.exact(new): |
328 repo.ui.status(_('recording removal of %s as rename to %s ' |
335 repo.ui.status(_('recording removal of %s as rename to %s ' |
329 '(%d%% similar)\n') % |
336 '(%d%% similar)\n') % |
330 (m.rel(old), m.rel(new), score * 100)) |
337 (m.rel(old), m.rel(new), score * 100)) |
331 if not dry_run: |
338 if not dry_run: |