Commits

Sebastian Sdorra committed 0cbb4ad

added support for subrepositories

Comments (0)

Files changed (1)

 """
 from mercurial import util
 
+class SubRepository:
+  url = None
+  revision = None
+
+def removeTrailingSlash(path):
+  if path.endswith('/'):
+    path = path[0:-1]
+  return path
+  
+def appendTrailingSlash(path):
+  if not path.endswith('/'):
+    path += '/'
+  return path
+
 def collectFiles(revCtx, path, files, directories):
   length = 0
   paths = []
         dirpath += parts[i] + '/'
       if not dirpath in directories:
         directories.append(dirpath)
+        
+def createSubRepositoryMap(revCtx):
+  subrepos = {}
+  try:
+    hgsub = revCtx.filectx('.hgsub').data().split('\n')
+    for line in hgsub:
+      parts = line.split('=')
+      if len(parts) > 1:
+        subrepo = SubRepository()
+        subrepo.url = parts[1].strip()
+        subrepos[parts[0].strip()] = subrepo
+  except Exception:
+    pass
+    
+  try:
+    hgsubstate = revCtx.filectx('.hgsubstate').data().split('\n')
+    for line in hgsubstate:
+      parts = line.split(' ')
+      if len(parts) > 1:
+        subrev = parts[0].strip()
+        subrepo = subrepos[parts[1].strip()]
+        subrepo.revision = subrev
+  except Exception:
+    pass
+    
+  return subrepos
 
 def fileview(ui, repo, **opts):
   files = []
   if revision == None:
     revision = 'tip'
   revCtx = repo[revision]
-  collectFiles(revCtx, opts['path'], files, directories)
+  path = opts['path']
+  collectFiles(revCtx, path, files, directories)
+  subRepositories = createSubRepositoryMap(revCtx)
+  for k, v in subRepositories.iteritems():
+    if k.startswith(path):
+      ui.write('%s %s %s\n' % (appendTrailingSlash(k), v.revision, v.url))
   for d in directories:
     ui.write(d + '\n')
   for f in files: