Mercurial > hg-stable
diff mercurial/hg.py @ 363:ae96b7e1318d
Add hg copy
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Add hg copy
extend dirstate to remember copies
add copy command
add copy repo operation
write copy metadata with commit
manifest hash: 9f42c7b4a2400d35807b5f18c05a31814fa3e375
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCsMBTywK+sNU5EO8RAjXpAJ9fvNtTP1A/4veqFWQHcWGro7buyACgoVXz
/ngGOFowxS/zGkvUvGavYGQ=
=drb1
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Wed, 15 Jun 2005 15:57:07 -0800 |
parents | 10519e4cbd02 |
children | 4b0f562c61f4 e5d769afd3ef |
line wrap: on
line diff
--- a/mercurial/hg.py Wed Jun 15 15:50:28 2005 -0800 +++ b/mercurial/hg.py Wed Jun 15 15:57:07 2005 -0800 @@ -204,6 +204,7 @@ self.ui = ui self.map = None self.pl = None + self.copies = {} def __del__(self): if self.dirty: @@ -253,8 +254,19 @@ l = e[4] pos += 17 f = st[pos:pos + l] + if '\0' in f: + f, c = f.split('\0') + self.copies[f] = c self.map[f] = e[:4] pos += l + + def copy(self, source, dest): + self.read() + self.dirty = 1 + self.copies[dest] = source + + def copied(self, file): + return self.copies.get(file, None) def update(self, files, state): ''' current states: @@ -292,11 +304,14 @@ st = self.opener("dirstate", "w") st.write("".join(self.pl)) for f, e in self.map.items(): + c = self.copied(f) + if c: + f = f + "\0" + c e = struct.pack(">cllll", e[0], e[1], e[2], e[3], len(f)) st.write(e + f) self.dirty = 0 - def copy(self): + def dup(self): self.read() return self.map.copy() @@ -556,10 +571,17 @@ self.warn("trouble committing %s!\n" % f) raise + meta = {} + cp = self.dirstate.copied(f) + if cp: + meta["copy"] = cp + meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid))) + self.ui.debug(" %s: copy %s:%s\n" % (f, cp, meta["copyrev"])) + r = self.file(f) fp1 = m1.get(f, nullid) fp2 = m2.get(f, nullid) - new[f] = r.add(t, {}, tr, linkrev, fp1, fp2) + new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) # update manifest m1.update(new) @@ -600,7 +622,7 @@ changeset = self.dirstate.parents()[0] change = self.changelog.read(changeset) mf = self.manifest.read(change[0]) - dc = self.dirstate.copy() + dc = self.dirstate.dup() def fcmp(fn): t1 = self.wfile(fn).read() @@ -689,6 +711,15 @@ else: self.dirstate.update([f], "r") + def copy(self, source, dest): + p = self.wjoin(dest) + if not os.path.isfile(dest): + self.ui.warn("%s does not exist!\n" % dest) + else: + if self.dirstate.state(dest) == '?': + self.dirstate.update([dest], "a") + self.dirstate.copy(source, dest) + def heads(self): return self.changelog.heads()