hg site extension
 
(Arne Babenhauserheide)
2012-10-30: indent empty lines in functions to make outline-mode happy

indent empty lines in functions to make outline-mode happy

diff --git a/staticsite.py b/staticsite.py
--- a/staticsite.py
+++ b/staticsite.py
@@ -114,7 +114,6 @@ def overviewlogstring(ui, repo, revs, te
         t.show(ctx)
     return ui.popbuffer()
 
-
 def writeoverview(ui, repo, target, name):
     """Create the overview page"""
     overview = ""
@@ -143,9 +142,9 @@ def writeoverview(ui, repo, target, name
             overview += "<small>(" + str(len(incoming))
             outgoing, fn, localother = getoutgoing(ui, repo, otheruri=forkuri, othername=forkname)
             overview += "<small>↓↑</small>" + str(len(outgoing)) + ")</small> "
-
+            
     overview += "</p>"
-
+    
     # now add the 5 most recent log entries
     # divert all following ui output to a string, so we can just use standard functions
     overview += "\n<div id='shortlog'><h2>Changes (<a href='commits'>full changelog</a>)</h2>\n"
@@ -163,7 +162,7 @@ def writeoverview(ui, repo, target, name
     for branch, heads in repo.branchmap().items(): 
         if branch and branch != "default": # not default
             branches.extend(heads)
-
+            
     try: 
         # FIXME: For some reason this does not seem to give the tags anymore.
         tags = repo._tags
@@ -204,7 +203,7 @@ def writeoverview(ui, repo, target, name
     overview += "<div id='readme'><h2>"+_("Readme")+"</h2>\n"
     overview += readme
     overview += "</div>"
-
+    
     # finish the overview
     overview += templates["foot"]
     indexfile = os.path.join(target, "index.html")
@@ -215,7 +214,7 @@ def writeoverview(ui, repo, target, name
 def writelog(ui, repo, target, name):
     """Write the full changelog, in steps of 100."""
     commits = os.path.join(target, "commits")
-
+    
     # create the folders
     if not os.path.isdir(commits):
         os.makedirs(commits)
@@ -223,7 +222,7 @@ def writelog(ui, repo, target, name):
         d = commits+"-"+str(i+1)+"00"
         if not os.path.isdir(d):
             os.makedirs(d)
-
+            
     # create the log files
     t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False)
     t.use_template(templates["commitlog"].replace("{relativepath}", "../"))
@@ -244,13 +243,13 @@ def writelog(ui, repo, target, name):
         else:
             d = commits
             logs.append([os.path.join(d, "index.html"), ""])
-
+            
         logs[-1][-1] += templates["head"].replace("{reponame}", "<a href='../'>"+name+"</a>").replace("{title}", name)
         for c in range(ck*100+1, min(len(repo.changelog)+1, (ck+1)*100)):
             ctx = repo.changectx(str(-c))
             t.show(ctx)
         logs[-1][-1] += ui.popbuffer()
-
+        
     for filepath,data in logs:
         data += templates["foot"].replace("{reponame}", "<a href='../'>"+name+"</a>")
         if not contentequals(filepath,data): 
@@ -259,7 +258,7 @@ def writelog(ui, repo, target, name):
 
 def getlocalother(repo, ui, otheruri, othername):
     """Get a local clone of the repo identified by uri and name within .hg/paths.
-
+    
     This creates that local clone!
     """
     # if we cannot get the changes via bundlerepo, we create a
@@ -297,7 +296,7 @@ def getincoming(ui, repo, otheruri, othe
     if isftpuri or isfreenetpriv:
         chlist = []
         return chlist, cleanupfn, other
-
+    
     if not other:
         other = hg.peer(repo, {}, otheruri)
     ui.pushbuffer() # ignore ui events
@@ -327,10 +326,10 @@ def getoutgoing(ui, repo, otheruri, othe
     if isftpuri or isfreenetpriv:
         chlist = []
         return chlist, cleanupfn, other
-
+    
     if not other: 
         other = hg.peer(repo, {}, otheruri)
-
+        
     def outgoingchanges(repo, other):
         from mercurial import discovery
         fco = discovery.findcommonoutgoing
@@ -343,7 +342,7 @@ def getoutgoing(ui, repo, otheruri, othe
             return o
             
     other.ui.pushbuffer() # ignore ui events
-
+    
     try:
         chlist = outgoingchanges(repo, other)
     except (AttributeError, util.Abort):
@@ -351,11 +350,10 @@ def getoutgoing(ui, repo, otheruri, othe
         other = getlocalother(repo, ui, otheruri, othername)
         other.ui.pushbuffer()
         chlist = outgoingchanges(repo, other)
-
+        
     other.ui.popbuffer()
     return chlist, cleanupfn, other
 
-
 def getforkinfo(ui, target):
     """Name and Uri of all forks."""
     forks = dict(ui.configitems("paths"))
@@ -379,18 +377,18 @@ def getforkdata(ui, repo, target, name, 
     """Write the site for a single fork."""
     # make sure the forkdir exists.
     other = hg.peer(repo, {}, forkuri)
-
+    
     # incrementally build the html
     html = templates["forkhead"].replace(
             "{forkname}", forkname).replace(
         "{reponame}", name).replace(
                 "{forkuri}", safeuri(forkuri))
-
+        
     # prepare the log templater
     t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False)
     t.use_template(templates["commitlog"].replace(
             "{relativepath}", "../"))
-
+    
     # Add incoming commits
     html += "<div id='incoming'><h2>Incoming commits</h2>"
     chlist, cleanupfn, localother = getincoming(ui, repo, otheruri=forkuri, other=other, othername=forkname)
@@ -401,11 +399,11 @@ def getforkdata(ui, repo, target, name, 
         t.show(ctx)
     html += ui.popbuffer()
     cleanupfn()
-
+    
     # add outgoing commits
     html += "<div id='outgoing'><h2>Outgoing commits</h2>"
     chlist, cleanupfn, localother = getoutgoing(ui, repo, forkuri, other=other, othername=forkname)
-
+    
     ui.pushbuffer()
     for ch in chlist:
         ctx = repo.changectx(ch)
@@ -422,7 +420,7 @@ def getforkdir(target, forkname):
 
 def writeforks(ui, repo, target, name):
     """Write an info-page for each fork, defined in hg paths.
-
+    
     relevant data: incoming commits, outgoing commits, branches and bookmarks not in fork or not in repo. Short: incoming (commits, branches, bookmarks), outgoing (incoming first means, we consider this repo to be the main repo).
     """
     forkinfo = getforkinfo(ui, target)
@@ -437,15 +435,14 @@ def writeforks(ui, repo, target, name):
             f.write(
                 getforkdata(ui, repo, target, name, forkname, forkuri))
 
-
 def writecommits(ui, repo, target, name, force=False):
     """Write all not yet existing commit files."""
     commit = os.path.join(target, "commit")
-
+    
     # create the folders
     if not os.path.isdir(commit):
         os.makedirs(commit)
-
+        
     t = cmdutil.changeset_templater(ui, repo, patch=False, diffopts=None, mapfile=None, buffered=False)
     t.use_template(templates["commitlog"].replace("{relativepath}", "../"))
     for c in range(len(repo.changelog)):
@@ -463,14 +460,12 @@ def writecommits(ui, repo, target, name,
             cf.write("<pre>"+ui.popbuffer().replace("<", "<")+"</pre>")
             cf.write(templates["foot"].replace("{reponame}", "<a href='../'>"+name+"</a>"))
 
-
 def escapename(filename):
     """escape index.html as .index.html and .ind… as ..ind… and so fort."""
     if _indexregexp.match(filename) is not None:
         return "." + filename
     else: return filename
 
-
 def parsesrcdata(data):
     """Parse a src file into a html file."""
     return "<pre>"+data.replace("<", "<")+"</pre>"
@@ -497,6 +492,7 @@ def ctxdiffstat(ui, repo, ctx):
             "[0;31m", "").replace(
                 "","")
     
+
 def createindex(ui, repo, target, ctx):
     """Create an index page for the changecontext: the commit message + the user + all files in the changecontext."""
     # first the head
@@ -516,7 +512,7 @@ def createindex(ui, repo, target, ctx):
 
 def writesourcetree(ui, repo, target, name, force, rawfiles=False):
     """Write manifests for all commits and websites for all files.
-
+    
     * For each file, write sites for all revisions where the file was changed: under src/<hex>/path as html site (with linenumbers and maybe colored source), under raw/<hex>/<path> as plain files. If there is an index.html file, write it as .index.html. If there also is .index.html, turn it to ..index.html, …
     * For each commit write an index with links to the included files at their latest revisions before/at the commit.
     """
@@ -578,12 +574,12 @@ def parsesite(ui, repo, target, **opts):
                 return
             with open(idfile, "w") as i:
                 i.write("")
-
+                
     if opts["sitename"]:
         name = opts["sitename"]
     elif target != "static": name = target
     else: name = os.path.basename(repo.root)
-
+    
     # first the stylesheets
     screenstyle = opts["screenstyle"]
     screenfile = os.path.join(target, "style.css")
@@ -599,23 +595,22 @@ def parsesite(ui, repo, target, **opts):
     elif not contentequals(printfile, templates["printstyle"]):
         with open(printfile, "w") as f:
             f.write(templates["printstyle"])
-
+            
     # then the overview
     writeoverview(ui, repo, target, name)
-
+    
     # and the log
     writelog(ui, repo, target, name)
-
+    
     # and all commit files
     writecommits(ui, repo, target, name, force=opts["force"])
-
+    
     # and all file data
     writesourcetree(ui, repo, target, name, force=opts["force"])
-
+    
     # and all forks
     writeforks(ui, repo, target, name)
 
-
 def addrepo(ui, repo, target, bookmarks, force):
     """Add the repo to the target and make sure it is up to date."""
     try:
@@ -623,7 +618,7 @@ def addrepo(ui, repo, target, bookmarks,
     except mercurial.error.RepoError, e:
         # already exists
         pass
-
+    
     ui.pushbuffer()
     if bookmarks: 
         commands.push(ui, repo, dest=target, bookmark=repo._bookmarks, force=force)
@@ -631,7 +626,6 @@ def addrepo(ui, repo, target, bookmarks,
         commands.push(ui, repo, dest=target, force=force)
     ui.popbuffer()
 
-
 def upload(ui, repo, target, ftpstring, force):
     """upload the repo to the FTP server identified by the ftp string."""
     try:
@@ -649,9 +643,9 @@ def upload(ui, repo, target, ftpstring, 
     except socket.timeout:
         ui.warn(_("connection to "), server, _(" timed out after "), timeout, _(" seconds.\n"))
         return
-
+    
     ui.status(ftp.getwelcome(), "\n")
-
+    
     # create the target dir.
     serverdir = os.path.dirname(ftppath)
     serverdirparts = ftppath.split("/")
@@ -663,26 +657,26 @@ def upload(ui, repo, target, ftpstring, 
         sd = os.path.join(sd, sdp)
         if not sd in ftp.nlst(sdo):
             ftp.mkd(sd)
-
-
+            
+            
     ftp.cwd(ftppath)
     if not ftp.pwd() == "/" + ftppath:
         ui.warn(_("not in the correct ftp directory. Cowardly bailing out.\n"))
         return
-
+    
     #ftp.dir()
     #return
     ftpfeatures = ftp.sendcmd("FEAT")
     featuremtime = " MDTM" in ftpfeatures.splitlines()
     _ftplistcache = set()
-
+    
     for d, dirnames, filenames in os.walk(target):
         for filename in filenames:
             localfile = os.path.join(d, filename)
             serverfile = localfile[len(target)+1:]
             serverdir = os.path.dirname(serverfile)
             serverdirparts = serverdir.split("/")
-#            print serverdirparts, serverfile
+            # print serverdirparts, serverfile
             with open(localfile, "rb") as f:
                 sd = serverdirparts[0]
                 if sd and not sd in _ftplistcache: # should happen only once per superdir
@@ -695,7 +689,7 @@ def upload(ui, repo, target, ftpstring, 
                     except ftplib.error_perm, resp:
                         ui.warn(_("could not create directory "), sd, ": " , resp, "\n")
                     else: _ftplistcache.add(sd)
-
+                    
                 for sdp in serverdirparts[1:]:
                     sdold = sd
                     sd = os.path.join(sd, sdp)
@@ -711,7 +705,7 @@ def upload(ui, repo, target, ftpstring, 
                         except ftplib.error_perm, resp:
                             ui.warn(_("could not create directory "),
                                     sd, ": " , resp, "\n")
-
+                            
                 if not serverfile in _ftplistcache: # should happen for existing files only once per dir.
                     _ftplistcache.update(set(ftp.nlst(serverdir)))
                 if not serverfile in _ftplistcache or force:
@@ -721,7 +715,7 @@ def upload(ui, repo, target, ftpstring, 
                     else:
                         ui.status(_("uploading "), serverfile,
                                   _(" because it is not yet online.\n"))
-
+                        
                     ftp.storbinary("STOR "+ serverfile, f)
                 else:
                     # reupload the file if the file on the server is older than the local file.
@@ -735,8 +729,6 @@ def upload(ui, repo, target, ftpstring, 
                                       _(" because it is newer than the file on the FTP server.\n"))
                             ftp.storbinary("STOR "+ serverfile, f)
 
-
-
 def staticsite(ui, repo, target=None, **opts):
     """Create a static copy of the repository and/or upload it to an FTP server."""
     if repo.root == target:
@@ -755,7 +747,6 @@ def staticsite(ui, repo, target=None, **
         # upload the repo
         upload(ui, repo, target, opts["upload"], opts["force"])
 
-
 cmdtable = {
     # "command-name": (function-call, options-list, help-string)
     "site": (staticsite,