comparison hgext/mq.py @ 13229:f3058dd05281

mq: record more data in patchheader class (no behavior changes) * parse branch and nodeid header lines * remember the line number where diffs started Combined, these make mq.patchheader() very useful for parsing and preserving a patch header through edits. TortoiseHg will use the nodeid and parent to display these header datums in the graph when patches are unapplied, and uses diffstartline to parse patch files using record.parsepatch().
author Steve Borho <steve@borho.org>
date Fri, 31 Dec 2010 17:09:38 -0600
parents d18a748d9c33
children 6bf39d88c857
comparison
equal deleted inserted replaced
13228:d18a748d9c33 13229:f3058dd05281
84 user = None 84 user = None
85 date = None 85 date = None
86 parent = None 86 parent = None
87 format = None 87 format = None
88 subject = None 88 subject = None
89 branch = None
90 nodeid = None
89 diffstart = 0 91 diffstart = 0
90 92
91 for line in file(pf): 93 for line in file(pf):
92 line = line.rstrip() 94 line = line.rstrip()
93 if (line.startswith('diff --git') 95 if (line.startswith('diff --git')
104 user = line[7:] 106 user = line[7:]
105 elif line.startswith("# Date "): 107 elif line.startswith("# Date "):
106 date = line[7:] 108 date = line[7:]
107 elif line.startswith("# Parent "): 109 elif line.startswith("# Parent "):
108 parent = line[9:] 110 parent = line[9:]
111 elif line.startswith("# Branch "):
112 branch = line[9:]
113 elif line.startswith("# Node ID "):
114 nodeid = line[10:]
109 elif not line.startswith("# ") and line: 115 elif not line.startswith("# ") and line:
110 message.append(line) 116 message.append(line)
111 format = None 117 format = None
112 elif line == '# HG changeset patch': 118 elif line == '# HG changeset patch':
113 message = [] 119 message = []
132 message.append(line) 138 message.append(line)
133 comments.append(line) 139 comments.append(line)
134 140
135 eatdiff(message) 141 eatdiff(message)
136 eatdiff(comments) 142 eatdiff(comments)
143 # Remember the exact starting line of the patch diffs before consuming
144 # empty lines, for external use by TortoiseHg and others
145 self.diffstartline = len(comments)
137 eatempty(message) 146 eatempty(message)
138 eatempty(comments) 147 eatempty(comments)
139 148
140 # make sure message isn't empty 149 # make sure message isn't empty
141 if format and format.startswith("tag") and subject: 150 if format and format.startswith("tag") and subject:
145 self.message = message 154 self.message = message
146 self.comments = comments 155 self.comments = comments
147 self.user = user 156 self.user = user
148 self.date = date 157 self.date = date
149 self.parent = parent 158 self.parent = parent
159 # nodeid and branch are for external use by TortoiseHg and others
160 self.nodeid = nodeid
161 self.branch = branch
150 self.haspatch = diffstart > 1 162 self.haspatch = diffstart > 1
151 self.plainmode = plainmode 163 self.plainmode = plainmode
152 164
153 def setuser(self, user): 165 def setuser(self, user):
154 if not self.updateheader(['From: ', '# User '], user): 166 if not self.updateheader(['From: ', '# User '], user):