195
def _add_full_text(self, text):
200
def _add_full_text(self, text, text_sha):
196
201
"""Add a full text to the file.
198
203
This is not compressed against any reference version.
200
205
Returns the index for that text."""
201
return self._add_common(sha.new(text).digest(), text, 0, _NO_RECORD)
204
def _add_delta(self, text, base):
206
return self._add_common(text_sha, text, 0, _NO_RECORD)
209
def _add_delta(self, text, text_sha, base):
205
210
"""Add a text stored relative to a previous text."""
206
211
self._check_index(base)
207
text_sha = sha.new(text).digest()
208
212
base_text = self.get(base)
209
213
data = mdiff.bdiff(base_text, text)
210
214
return self._add_common(text_sha, data, 0, base)
213
def add(self, text, base=None):
214
# TODO: check it's not already present?
217
def add(self, text, base=_NO_RECORD):
218
text_sha = sha.new(text).digest()
220
idx = self.find_sha(text_sha)
221
if idx != _NO_RECORD:
222
return idx # already present
224
if base == _NO_RECORD:
225
return self._add_full_text(text, text_sha)
227
return self._add_delta(self, text, text_sha, base)
218
230
def addrevision(self, text, changeset):
363
new_idx = r._add_full_text(sys.stdin.read())
376
new_idx = r.add(sys.stdin.read())
364
377
print 'added idx %d' % new_idx
365
378
elif cmd == 'add-delta':
366
379
new_idx = r._add_delta(sys.stdin.read(), int(argv[2]))