def get_commits(self, branch=None): command = "log --pretty=format:'<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commiter_date><message><![CDATA[%s]]></message></item>'" if branch: command += " " + branch # logs = self.get_pretty_format(command) output = self.client.run(self, command) output = "<result>" + output + "</result>" # self.logger.debug(output) dom = xml.dom.minidom.parseString(output) items = dom.getElementsByTagName("item") commits = [] for item in items: commit = GitCommit() commit.set_hash(item.getElementsByTagName("hash")[0].firstChild.nodeValue) commit.set_short_hash(item.getElementsByTagName("short_hash")[0].firstChild.nodeValue) commit.set_tree(item.getElementsByTagName("tree")[0].firstChild.nodeValue) if item.getElementsByTagName("parents")[0].firstChild: commit.set_parents(item.getElementsByTagName("parents")[0].firstChild.nodeValue) else: commit.set_parents("") commit.set_author(item.getElementsByTagName("author")[0].firstChild.nodeValue) commit.set_author_email(item.getElementsByTagName("author_email")[0].firstChild.nodeValue) timestamp = item.getElementsByTagName("date")[0].firstChild.nodeValue date = datetime.fromtimestamp(float(timestamp)) thedate = date.strftime("%s" % ("%m/%d/%Y")) commit.set_date(thedate) # self.logger.debug('date %s' % item.getElementsByTagName("date")[0].firstChild.nodeValue) commit.set_commiter(item.getElementsByTagName("commiter")[0].firstChild.nodeValue) commit.set_commiter_email(item.getElementsByTagName("commiter_email")[0].firstChild.nodeValue) commit.set_commiter_date(item.getElementsByTagName("commiter_date")[0].firstChild.nodeValue) commit.set_message(item.getElementsByTagName("message")[0].firstChild.nodeValue) commits.append(commit) return commits
def get_commit(self, commit): logs = self.client.run( self, 'show --pretty=format:"<item><hash>%H</hash><short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents><author>%an</author><author_email>%ae</author_email><date>%at</date><commiter>%cn</commiter><commiter_email>%ce</commiter_email><commiter_date>%ct</commiter_date><message><![CDATA[%s]]></message></item>"' + commit, ) # self.logger.debug(data) lines = "".join(logs) lines = lines.split("\n") # self.logger.debug(lines[0]) thexml = lines[0].strip(commit) output = "<result>" + thexml + "</result>" # self.logger.debug(output) dom = xml.dom.minidom.parseString(output) items = dom.getElementsByTagName("item") item = items[0] # self.logger.debug(items[0]) thecommit = GitCommit() thecommit.set_hash(item.getElementsByTagName("hash")[0].firstChild.nodeValue) thecommit.set_short_hash(item.getElementsByTagName("short_hash")[0].firstChild.nodeValue) thecommit.set_tree(item.getElementsByTagName("tree")[0].firstChild.nodeValue) if item.getElementsByTagName("parents")[0].firstChild: thecommit.set_parents(item.getElementsByTagName("parents")[0].firstChild.nodeValue) else: thecommit.set_parents("") thecommit.set_author(item.getElementsByTagName("author")[0].firstChild.nodeValue) thecommit.set_author_email(item.getElementsByTagName("author_email")[0].firstChild.nodeValue) timestamp = item.getElementsByTagName("date")[0].firstChild.nodeValue date = datetime.fromtimestamp(float(timestamp)) thedate = date.strftime("%s" % ("%m/%d/%Y")) thecommit.set_date(thedate) # self.logger.debug('date %s' % item.getElementsByTagName("date")[0].firstChild.nodeValue) thecommit.set_commiter(item.getElementsByTagName("commiter")[0].firstChild.nodeValue) thecommit.set_commiter_email(item.getElementsByTagName("commiter_email")[0].firstChild.nodeValue) thecommit.set_commiter_date(item.getElementsByTagName("commiter_date")[0].firstChild.nodeValue) thecommit.set_message(item.getElementsByTagName("message")[0].firstChild.nodeValue) diff = self.client.run(self, "diff " + commit + "~1.." + commit) # self.logger.debug(diff) difflines = "".join(diff) difflines = difflines.split("\n") thecommit.set_diffs(self.read_diff_lines(difflines)) # self.logger.debug(thecommit.get_diffs()[0].get_lines()) return thecommit