Mercurial > hg
comparison hgext/convert/cvs.py @ 5920:5df7cb799baf
CVS convert: Find correct parent for new branch (issue704)
Previously the parent was determined by the last changeset where the branched
file was changed even if the branch is based on an earlier revision.
Fix written by mpm.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Tue, 22 Jan 2008 00:16:50 +0100 |
parents | 03496d4fa509 |
children | 549a7ebe1607 |
comparison
equal
deleted
inserted
replaced
5919:badf5711bd86 | 5920:5df7cb799baf |
---|---|
47 d = os.getcwd() | 47 d = os.getcwd() |
48 try: | 48 try: |
49 os.chdir(self.path) | 49 os.chdir(self.path) |
50 id = None | 50 id = None |
51 state = 0 | 51 state = 0 |
52 filerevids = {} | |
52 for l in util.popen(cmd): | 53 for l in util.popen(cmd): |
53 if state == 0: # header | 54 if state == 0: # header |
54 if l.startswith("PatchSet"): | 55 if l.startswith("PatchSet"): |
55 id = l[9:-2] | 56 id = l[9:-2] |
56 if maxrev and int(id) > maxrev: | 57 if maxrev and int(id) > maxrev: |
58 # ignore everything | |
57 state = 3 | 59 state = 3 |
58 elif l.startswith("Date"): | 60 elif l.startswith("Date"): |
59 date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) | 61 date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) |
60 date = util.datestr(date) | 62 date = util.datestr(date) |
61 elif l.startswith("Branch"): | 63 elif l.startswith("Branch"): |
62 branch = l[8:-1] | 64 branch = l[8:-1] |
63 self.parent[id] = self.lastbranch.get(branch, 'bad') | 65 self.parent[id] = self.lastbranch.get(branch, 'bad') |
64 self.lastbranch[branch] = id | 66 self.lastbranch[branch] = id |
65 elif l.startswith("Ancestor branch"): | 67 elif l.startswith("Ancestor branch"): |
66 ancestor = l[17:-1] | 68 ancestor = l[17:-1] |
67 self.parent[id] = self.lastbranch[ancestor] | 69 # figure out the parent later |
70 self.parent[id] = None | |
68 elif l.startswith("Author"): | 71 elif l.startswith("Author"): |
69 author = self.recode(l[8:-1]) | 72 author = self.recode(l[8:-1]) |
70 elif l.startswith("Tag:") or l.startswith("Tags:"): | 73 elif l.startswith("Tag:") or l.startswith("Tags:"): |
71 t = l[l.index(':')+1:] | 74 t = l[l.index(':')+1:] |
72 t = [ut.strip() for ut in t.split(',')] | 75 t = [ut.strip() for ut in t.split(',')] |
73 if (len(t) > 1) or (t[0] and (t[0] != "(none)")): | 76 if (len(t) > 1) or (t[0] and (t[0] != "(none)")): |
74 self.tags.update(dict.fromkeys(t, id)) | 77 self.tags.update(dict.fromkeys(t, id)) |
75 elif l.startswith("Log:"): | 78 elif l.startswith("Log:"): |
79 # switch to gathering log | |
76 state = 1 | 80 state = 1 |
77 log = "" | 81 log = "" |
78 elif state == 1: # log | 82 elif state == 1: # log |
79 if l == "Members: \n": | 83 if l == "Members: \n": |
84 # switch to gathering members | |
80 files = {} | 85 files = {} |
86 oldrevs = [] | |
81 log = self.recode(log[:-1]) | 87 log = self.recode(log[:-1]) |
82 state = 2 | 88 state = 2 |
83 else: | 89 else: |
90 # gather log | |
84 log += l | 91 log += l |
85 elif state == 2: | 92 elif state == 2: # members |
86 if l == "\n": # | 93 if l == "\n": # start of next entry |
87 state = 0 | 94 state = 0 |
88 p = [self.parent[id]] | 95 p = [self.parent[id]] |
89 if id == "1": | 96 if id == "1": |
90 p = [] | 97 p = [] |
91 if branch == "HEAD": | 98 if branch == "HEAD": |
92 branch = "" | 99 branch = "" |
100 if branch and p[0] == None: | |
101 latest = None | |
102 # the last changeset that contains a base | |
103 # file is our parent | |
104 for r in oldrevs: | |
105 latest = max(filerevids[r], latest) | |
106 p = [latest] | |
107 | |
108 # add current commit to set | |
93 c = commit(author=author, date=date, parents=p, | 109 c = commit(author=author, date=date, parents=p, |
94 desc=log, branch=branch) | 110 desc=log, branch=branch) |
95 self.changeset[id] = c | 111 self.changeset[id] = c |
96 self.files[id] = files | 112 self.files[id] = files |
97 else: | 113 else: |
98 colon = l.rfind(':') | 114 colon = l.rfind(':') |
99 file = l[1:colon] | 115 file = l[1:colon] |
100 rev = l[colon+1:-2] | 116 rev = l[colon+1:-2] |
101 rev = rev.split("->")[1] | 117 oldrev, rev = rev.split("->") |
102 files[file] = rev | 118 files[file] = rev |
119 | |
120 # save some information for identifying branch points | |
121 oldrevs.append("%s:%s" % (oldrev, file)) | |
122 filerevids["%s:%s" % (rev, file)] = id | |
103 elif state == 3: | 123 elif state == 3: |
124 # swallow all input | |
104 continue | 125 continue |
105 | 126 |
106 self.heads = self.lastbranch.values() | 127 self.heads = self.lastbranch.values() |
107 finally: | 128 finally: |
108 os.chdir(d) | 129 os.chdir(d) |