1. Steve Losh
  2. hg-paste

Commits

Rolando Espinoza  committed 80a1475

added option to read paste content from stdin

  • Participants
  • Parent commits 26dc918
  • Branches default

Comments (0)

Files changed (1)

File paste.py

View file
 '''
 
 import base64
+import sys
 import urllib2
 from mercurial import cmdutil, commands, help, util
 from urllib import urlencode
     if not opts['user']:
         opts['user'] = ui.username().replace('<', '').replace('>', '')
     
-    ui.pushbuffer()
-    if opts['rev']:
-        rev = opts.pop('rev')
-        revs = cmdutil.revrange(repo, rev)
-        
-        if len(revs) == 1:
-            opts['change'] = revs[0]
+    if opts['rev'] and opts['stdin']:
+        raise util.Abort('--rev and --stdin options are mutually exclusive')
+
+    if opts['stdin']:
+        content = sys.stdin.read()
+    else:
+        ui.pushbuffer()
+        if opts['rev']:
+            rev = opts.pop('rev')
+            revs = cmdutil.revrange(repo, rev)
+            
+            if len(revs) == 1:
+                opts['change'] = revs[0]
+            else:
+                opts['rev'] = rev
+            
+            commands.diff(ui, repo, *fnames, **opts)
         else:
-            opts['rev'] = rev
-        
-        commands.diff(ui, repo, *fnames, **opts)
-    else:
-        commands.diff(ui, repo, *fnames, **opts)
-    content = ui.popbuffer()
+            commands.diff(ui, repo, *fnames, **opts)
+        content = ui.popbuffer()
     
     if not content.strip():
         raise util.Abort('nothing to paste!')
         ('',  'url', '', 'perform request against this url'),
         ('',  'httpauth', '', 'http authorization (user:pass)'),
         ('',  'usenetrc', False, 'use ~/.netrc for http authorization'),
+        ('',  'stdin', False, 'read content from standard input'),
     ] + commands.diffopts + commands.walkopts,
     'hg paste [OPTION] [-r REV] [FILE...]')
 }