404
404
"""Inventory for the working copy.""")
407
def add(self, files, ids=None):
407
def add(self, files, verbose=False, ids=None):
408
408
"""Make files versioned.
410
Note that the command line normally calls smart_add instead,
411
which can automatically recurse.
410
Note that the command line normally calls smart_add instead.
413
412
This puts the files in the Added state, so that they will be
414
413
recorded by the next commit.
424
423
TODO: Perhaps have an option to add the ids even if the files do
427
TODO: Perhaps yield the ids and paths as they're added.
426
TODO: Perhaps return the ids of the files? But then again it
427
is easy to retrieve them if they're needed.
429
TODO: Adding a directory should optionally recurse down and
430
add all non-ignored children. Perhaps do that in a
429
433
# TODO: Re-adding a file that is removed in the working copy
430
434
# should probably put it back with the previous ID.
466
470
file_id = gen_file_id(f)
467
471
inv.add_path(f, kind=kind, file_id=file_id)
474
print 'added', quotefn(f)
469
476
mutter("add file %s file_id:{%s} kind=%r" % (f, file_id, kind))
471
478
self._write_inventory(inv)
877
884
def lookup_revision(self, revision):
878
885
"""Return the revision identifier for a given revision information."""
879
revno, info = self.get_revision_info(revision)
886
revno, info = self._get_revision_info(revision)
897
904
revision can also be a string, in which case it is parsed for something like
898
905
'date:' or 'revid:' etc.
907
revno, rev_id = self._get_revision_info(revision)
909
raise bzrlib.errors.NoSuchRevision(self, revision)
912
def get_rev_id(self, revno, history=None):
913
"""Find the revision id of the specified revno."""
917
history = self.revision_history()
918
elif revno <= 0 or revno > len(history):
919
raise bzrlib.errors.NoSuchRevision(self, revno)
920
return history[revno - 1]
922
def _get_revision_info(self, revision):
923
"""Return (revno, revision id) for revision specifier.
925
revision can be an integer, in which case it is assumed to be revno
926
(though this will translate negative values into positive ones)
927
revision can also be a string, in which case it is parsed for something
928
like 'date:' or 'revid:' etc.
930
A revid is always returned. If it is None, the specifier referred to
931
the null revision. If the revid does not occur in the revision
932
history, revno will be None.
900
935
if revision is None:
907
942
revs = self.revision_history()
908
943
if isinstance(revision, int):
911
# Mabye we should do this first, but we don't need it if revision == 0
913
945
revno = len(revs) + revision + 1
948
rev_id = self.get_rev_id(revno, revs)
916
949
elif isinstance(revision, basestring):
917
950
for prefix, func in Branch.REVISION_NAMESPACES.iteritems():
918
951
if revision.startswith(prefix):
919
revno = func(self, revs, revision)
952
result = func(self, revs, revision)
954
revno, rev_id = result
957
rev_id = self.get_rev_id(revno, revs)
922
raise BzrError('No namespace registered for string: %r' % revision)
960
raise BzrError('No namespace registered for string: %r' %
963
raise TypeError('Unhandled revision type %s' % revision)
924
if revno is None or revno <= 0 or revno > len(revs):
925
raise BzrError("no such revision %s" % revision)
926
return revno, revs[revno-1]
967
raise bzrlib.errors.NoSuchRevision(self, revision)
928
970
def _namespace_revno(self, revs, revision):
929
971
"""Lookup a revision by revision number"""
930
972
assert revision.startswith('revno:')
932
return int(revision[6:])
974
return (int(revision[6:]),)
933
975
except ValueError:
935
977
REVISION_NAMESPACES['revno:'] = _namespace_revno
937
979
def _namespace_revid(self, revs, revision):
938
980
assert revision.startswith('revid:')
981
rev_id = revision[len('revid:'):]
940
return revs.index(revision[6:]) + 1
983
return revs.index(rev_id) + 1, rev_id
941
984
except ValueError:
943
986
REVISION_NAMESPACES['revid:'] = _namespace_revid
945
988
def _namespace_last(self, revs, revision):
948
991
offset = int(revision[5:])
949
992
except ValueError:
953
996
raise BzrError('You must supply a positive value for --revision last:XXX')
954
return len(revs) - offset + 1
997
return (len(revs) - offset + 1,)
955
998
REVISION_NAMESPACES['last:'] = _namespace_last
957
1000
def _namespace_tag(self, revs, revision):
1032
1075
# TODO: Handle timezone.
1033
1076
dt = datetime.datetime.fromtimestamp(r.timestamp)
1034
1077
if first >= dt and (last is None or dt >= last):
1037
1080
for i in range(len(revs)):
1038
1081
r = self.get_revision(revs[i])
1039
1082
# TODO: Handle timezone.
1040
1083
dt = datetime.datetime.fromtimestamp(r.timestamp)
1041
1084
if first <= dt and (last is None or dt <= last):
1043
1086
REVISION_NAMESPACES['date:'] = _namespace_date
1045
1088
def revision_tree(self, revision_id):
1111
1154
inv.rename(file_id, to_dir_id, to_tail)
1156
print "%s => %s" % (from_rel, to_rel)
1113
1158
from_abs = self.abspath(from_rel)
1114
1159
to_abs = self.abspath(to_rel)
1135
1180
Note that to_name is only the last component of the new name;
1136
1181
this doesn't change the directory.
1138
This returns a list of (from_path, to_path) pairs for each
1139
entry that is moved.
1142
1183
self.lock_write()
1144
1185
## TODO: Option to move IDs only
1179
1220
for f in from_paths:
1180
1221
name_tail = splitpath(f)[-1]
1181
1222
dest_path = appendpath(to_name, name_tail)
1182
result.append((f, dest_path))
1223
print "%s => %s" % (f, dest_path)
1183
1224
inv.rename(inv.path2id(f), to_dir_id, name_tail)
1185
1226
os.rename(self.abspath(f), self.abspath(dest_path))