def _prepareDescription(): footnote = "" try: ref = self.repo().head.ref footnote += ( "<p>Your current branch is set to <b>%s</b>. GeoGig will track and sync with this branch.</p>" % ref ) c = Commit.fromref(self.repo(), ref) epoch = time.mktime(c.committerdate.timetuple()) offset = datetime.fromtimestamp(epoch) - datetime.utcfromtimestamp(epoch) d = c.committerdate + offset lastDate = d.strftime("%b %d, %Y %I:%M%p") author = c.authorname lastVersion = "%s (%s by %s)" % (c.message.splitlines()[0], lastDate, author) except: lastVersion = "" with open(resourceFile("descriptiontemplate_edit.html")) as f: s = "".join(f.readlines()) s = s.replace("[NAME]", self.name) s = s.replace("[TITLE]", self.title) editIcon = os.path.dirname(__file__) + "/../ui/resources/pencil-icon.png" s = s.replace("[EDIT]", "<img src='" + editIcon + "'>") s = s.replace("[LAST_VERSION]", lastVersion) s = s.replace("[FOOTNOTE]", footnote) layers = "<dl>%s</dl>" % "".join(["<dd>%s</dd>" % tree.path for tree in self.repo().trees]) s = s.replace("[LAYERS]", layers) return s
def testFromRef(self): ref = self.repo.head.ref commit = Commit.fromref(self.repo, ref) log = self.repo.log() headcommit = log[0] self.assertEqual(headcommit.ref, commit.ref) self.assertEqual(headcommit.committerdate, commit.committerdate)
def _prepareDescription(): footnote = "" try: ref = self.repo().head.ref footnote += "<p>Your current branch is set to <b>%s</b>. GeoGig will track and sync with this branch.</p>" % ref c = Commit.fromref(self.repo(), ref) epoch = time.mktime(c.committerdate.timetuple()) offset = datetime.fromtimestamp( epoch) - datetime.utcfromtimestamp(epoch) d = c.committerdate + offset lastDate = d.strftime("%b %d, %Y %I:%M%p") author = c.authorname lastVersion = "%s (%s by %s)" % (c.message.splitlines()[0], lastDate, author) except: lastVersion = "" with open(resourceFile("descriptiontemplate_edit.html")) as f: s = "".join(f.readlines()) s = s.replace("[NAME]", self.name) s = s.replace("[TITLE]", self.title) editIcon = os.path.dirname( __file__) + "/../ui/resources/pencil-icon.png" s = s.replace("[EDIT]", "<img src='" + editIcon + "'>") s = s.replace("[LAST_VERSION]", lastVersion) s = s.replace("[FOOTNOTE]", footnote) layers = "<dl>%s</dl>" % "".join( ["<dd>%s</dd>" % tree.path for tree in self.repo().trees]) s = s.replace("[LAYERS]", layers) return s
def squash(repo, refa, refb, message = None): ''' Squashes all the commits between two given ones, 'refa' and 'refb'. Commits are passed as a string with the corresponding commit id If a message is passed, it uses it for the resulting commit. Otherwise, it uses the messages from the squashed commits ''' head = repo.head commita = Commit.fromref(repo, refa); commitb = Commit.fromref(repo, refb); if commita.committerdate > commitb.committerdate: refa, refb = refb, refa commita, commitb = commitb, commita #store the commits after the last one to squash commits = [] c = head commitid = c.id while commitid != refb: commits.append(commitid) c = c.parent commitid = c.id #squash the selected commmits repo.reset(refb, geogig.RESET_MODE_HARD) repo.reset(commita.parent.id, geogig.RESET_MODE_MIXED) if message is None: messages = [] c = commitb messages.append(c.message) while c.ref != refa: c = c.parent messages.append(c.message) message = "+".join(messages) repo.add() repo.commit(message) #And now add the remaining commits that we previously stored for c in reversed(commits): repo.cherrypick(c)
def commit(self): if self._commit is None: lines = self.repo.connector.cat(self.tagid).split("\n") commitid = lines[3][-40:] self._commit = Commit.fromref(self.repo, commitid) return self._commit