[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Remove excess elements from Atom 1.0 feeds

From: Max Bowsher <maxb1_at_ukf.net>
Date: 2006-07-21 23:19:03 CEST

Bhuvaneswaran Arumugam wrote:
> Hello,
>
> Please find attached the patch.
>
> [[
> Patch by: Bhuvaneswaran Arumugam <bhuvan@collab.net>
>
> Insert the "entry" element before all other "entry" elements and remove
> the elements from the feed file if it reaches --max-items.
>
> * contrib/hook-scripts/svn2feed.py
> (Svn2Atom.add_revision_item): Locate the "author" element (last
> non-entry element) and insert the new element after it's next sibling.
>
> Calculate the total "entry" elements and remove the last child if the
> total is greater than the --max-items.
> ]]
>
> Design: Locate the "author" element (last non-entry element) and insert
> the "entry" element before its next sibling. I'm unsure if it is the
> efficient way, but feel free to change if you find a better way.
>
>
>
> ------------------------------------------------------------------------
>
> Index: contrib/hook-scripts/svn2feed.py
> ===================================================================
> --- contrib/hook-scripts/svn2feed.py (revision 20819)
> +++ contrib/hook-scripts/svn2feed.py (working copy)
> @@ -208,9 +208,22 @@
>
> def add_revision_item(self, revision):
> item = self._make_atom_item(revision)
> - self.feed.appendChild(item)
> - # FIXME: Process max_items
>
> + total = 0
> + for childNode in self.feed.childNodes:
> + # author is the last non-entry element. We insert the new
> + # element before its next sibling because it is obviously an
> + # 'entry' element. If there is no such element, then next
> + # sibling will be None and the element will be inserted
> + # after the 'author' element
> + if(childNode.nodeName == 'author'):
> + self.feed.insertBefore(item, childNode.nextSibling)
> + elif(childNode.nodeName == 'entry'):
> + total += 1
> +
> + if (total > self.max_items):
> + self.feed.removeChild(self.feed.lastChild)

Two problems here:

1) It would be a lot safer to base the insertion point on the first
<entry>, not the position of <author>. <author> doesn't carry any useful
information in the feeds we generate, and in fact I'm considering
removing it.

2) Do not use parentheses around an if condition. It's very abnormal
Python style.

Max.

Received on Fri Jul 21 23:19:41 2006

This is an archived mail posted to the Subversion Dev mailing list.