threads / patch / 13670

patchhg-to-git: add --verbose option

Subject: [PATCH] hg-to-git: add --verbose option

## tl;dr

9 messages between May 26, 2008 and May 26, 2008. Diffs are folded; open one to read it.

replies: 8people: 6as markdown or json

Johannes Schindelin· May 26, 2008, 12:46 UTC · lore

This patch adds an option to make hg-to-git quiet by default. Note: it only suppresses those messages that would be printed when everything was up-to-date.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	Yeah, I know, a Python hater codes in Python.  Well, somebody told
	me I had to code in it until I do not hate it anymore.
 contrib/hg-to-git/hg-to-git.py |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
Show changes to contrib/hg-to-git/hg-to-git.py +13 −5
diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index d72ffbb..daad399 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -46,6 +46,7 @@ options:
                          for incrementals
     -n, --nrepack=INT:   number of changesets that will trigger
                          a repack (default=0, -1 to deactivate)
+    -v, --verbose:       be verbose
 
 required:
     hgprj:  name of the HG project to import (directory)
@@ -75,15 +76,18 @@ def getgitenv(user, date):
 
 state = ''
 opt_nrepack = 0
+verbose = ''
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], 's:t:n:', ['gitstate=', 'tempdir=', 'nrepack='])
+    opts, args = getopt.getopt(sys.argv[1:], 's:t:n:v', ['gitstate=', 'tempdir=', 'nrepack=', 'verbose'])
     for o, a in opts:
         if o in ('-s', '--gitstate'):
             state = a
             state = os.path.abspath(state)
         if o in ('-n', '--nrepack'):
             opt_nrepack = int(a)
+        if o in ('-v', '--verbose'):
+            verbose = true
     if len(args) != 1:
         raise('params')
 except:
@@ -95,17 +99,20 @@ os.chdir(hgprj)
 
 if state:
     if os.path.exists(state):
-        print 'State does exist, reading'
+        if verbose:
+            print 'State does exist, reading'
         f = open(state, 'r')
         hgvers = pickle.load(f)
     else:
         print 'State does not exist, first run'
 
 tip = os.popen('hg tip --template "{rev}"').read()
-print 'tip is', tip
+if verbose:
+    print 'tip is', tip
 
 # Calculate the branches
-print 'analysing the branches...'
+if verbose:
+    print 'analysing the branches...'
 hgchildren["0"] = ()
 hgparents["0"] = (None, None)
 hgbranch["0"] = "master"
@@ -232,7 +239,8 @@ if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
 
 # write the state for incrementals
 if state:
-    print 'Writing state'
+    if verbose:
+        print 'Writing state'
     f = open(state, 'w')
     pickle.dump(hgvers, f)
 
-- 
1.5.5.GIT
Johan Herland· May 26, 2008, 13:09 UTC · re: Johannes Schindelin · lore

Re: [PATCH] hg-to-git: add --verbose option

On Monday 26 May 2008, Johannes Schindelin wrote:
Show 9 quoted lines
> This patch adds an option to make hg-to-git quiet by default.  Note:
> it only suppresses those messages that would be printed when
> everything was up-to-date.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>
> 	Yeah, I know, a Python hater codes in Python.  Well, somebody told
> 	me I had to code in it until I do not hate it anymore.
Looks ok to me. :)
Show 20 quoted lines
>  contrib/hg-to-git/hg-to-git.py |   18 +++++++++++++-----
>  1 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/contrib/hg-to-git/hg-to-git.py
> b/contrib/hg-to-git/hg-to-git.py index d72ffbb..daad399 100755
> --- a/contrib/hg-to-git/hg-to-git.py
> +++ b/contrib/hg-to-git/hg-to-git.py
> @@ -46,6 +46,7 @@ options:
>                           for incrementals
>      -n, --nrepack=INT:   number of changesets that will trigger
>                           a repack (default=0, -1 to deactivate)
> +    -v, --verbose:       be verbose
>
>  required:
>      hgprj:  name of the HG project to import (directory)
> @@ -75,15 +76,18 @@ def getgitenv(user, date):
>
>  state = ''
>  opt_nrepack = 0
> +verbose = ''
Maybe this should be
	verbose = false
since it indicates your intent to exclusively use this variable as a
boolean.
The rest is ok, AFAICS.
Have fun! :)
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Johannes Schindelin· May 26, 2008, 13:14 UTC · re: Johan Herland · lore

Re: [PATCH] hg-to-git: add --verbose option

Hi,
On Mon, 26 May 2008, Johan Herland wrote:
Show 12 quoted lines
> On Monday 26 May 2008, Johannes Schindelin wrote:
>
> > @@ -75,15 +76,18 @@ def getgitenv(user, date):
> >
> >  state = ''
> >  opt_nrepack = 0
> > +verbose = ''
> 
> Maybe this should be
> 	verbose = false
> since it indicates your intent to exclusively use this variable as a
> boolean.

Now, that is not even funny, as that was my initial version, and Python complained about not knowing "false".

Ciao, Dscho

Sverre Rabbelier· May 26, 2008, 13:28 UTC · re: Johannes Schindelin · lore

Re: [PATCH] hg-to-git: add --verbose option

On Mon, May 26, 2008 at 3:14 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

> Now, that is not even funny, as that was my initial version, and Python
> complained about not knowing "false".
That is because in python the keyword is "False" (note the capital 'F').
-- 
Cheers,

Sverre Rabbelier
Junio C Hamano· May 26, 2008, 17:19 UTC · re: Sverre Rabbelier · lore

Re: [PATCH] hg-to-git: add --verbose option

"Sverre Rabbelier" <alturin@gmail.com> writes:
Show 6 quoted lines
> On Mon, May 26, 2008 at 3:14 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
>> Now, that is not even funny, as that was my initial version, and Python
>> complained about not knowing "false".
>
> That is because in python the keyword is "False" (note the capital 'F').

I too write True/False in my recent Python code, but I vaguely recall they were relatively new to the language. I think it was 2.3 which is probably 5 years old by now, so if that is the case we probably are safe (and they are used in p4import anyway).

I think I spotted a bug in Python documentation, by the way ;-)

http://docs.python.org/ref/ref.html does not even list "True" and "False" in its section 2.4 (Literals) yet, and that document is for version 2.5.2.

David Symonds· May 26, 2008, 21:29 UTC · re: Junio C Hamano · lore

Re: [PATCH] hg-to-git: add --verbose option

On Tue, May 27, 2008 at 3:19 AM, Junio C Hamano <gitster@pobox.com> wrote:
> I think I spotted a bug in Python documentation, by the way ;-)
>
> http://docs.python.org/ref/ref.html does not even list "True" and "False"
> in its section 2.4 (Literals) yet, and that document is for version 2.5.2.

That's because they aren't literals. They are, in fact, objects, and redefinable objects at that.

Try:

True=False print True

Dave.
Johannes Schindelin· May 26, 2008, 21:47 UTC · re: David Symonds · lore

Re: [PATCH] hg-to-git: add --verbose option

Hi,
On Tue, 27 May 2008, David Symonds wrote:
Show 15 quoted lines
> On Tue, May 27, 2008 at 3:19 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> > I think I spotted a bug in Python documentation, by the way ;-)
> >
> > http://docs.python.org/ref/ref.html does not even list "True" and 
> > "False" in its section 2.4 (Literals) yet, and that document is for 
> > version 2.5.2.
> 
> That's because they aren't literals. They are, in fact, objects, and 
> redefinable objects at that.
> 
> Try:
> 
> True=False
> print True
Hey, I said that I had to code in Python until I do not hate it anymore!
You just made that task harder.

Thanks, Dscho

Johannes Schindelin· May 26, 2008, 13:20 UTC · re: Johan Herland · lore

[PATCH v2] hg-to-git: add --verbose option

This patch adds an option to make hg-to-git quiet by default. Note: it only suppresses those messages that would be printed when everything was up-to-date.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Mon, 26 May 2008, Johan Herland wrote:
	> 	verbose = false
	Pieter on IRC just pointed out that it should be capitalized.
 contrib/hg-to-git/hg-to-git.py |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
Show changes to contrib/hg-to-git/hg-to-git.py +13 −5
diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index d72ffbb..f68ef72 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -46,6 +46,7 @@ options:
                          for incrementals
     -n, --nrepack=INT:   number of changesets that will trigger
                          a repack (default=0, -1 to deactivate)
+    -v, --verbose:       be verbose
 
 required:
     hgprj:  name of the HG project to import (directory)
@@ -75,15 +76,18 @@ def getgitenv(user, date):
 
 state = ''
 opt_nrepack = 0
+verbose = False
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], 's:t:n:', ['gitstate=', 'tempdir=', 'nrepack='])
+    opts, args = getopt.getopt(sys.argv[1:], 's:t:n:v', ['gitstate=', 'tempdir=', 'nrepack=', 'verbose'])
     for o, a in opts:
         if o in ('-s', '--gitstate'):
             state = a
             state = os.path.abspath(state)
         if o in ('-n', '--nrepack'):
             opt_nrepack = int(a)
+        if o in ('-v', '--verbose'):
+            verbose = True
     if len(args) != 1:
         raise('params')
 except:
@@ -95,17 +99,20 @@ os.chdir(hgprj)
 
 if state:
     if os.path.exists(state):
-        print 'State does exist, reading'
+        if verbose:
+            print 'State does exist, reading'
         f = open(state, 'r')
         hgvers = pickle.load(f)
     else:
         print 'State does not exist, first run'
 
 tip = os.popen('hg tip --template "{rev}"').read()
-print 'tip is', tip
+if verbose:
+    print 'tip is', tip
 
 # Calculate the branches
-print 'analysing the branches...'
+if verbose:
+    print 'analysing the branches...'
 hgchildren["0"] = ()
 hgparents["0"] = (None, None)
 hgbranch["0"] = "master"
@@ -232,7 +239,8 @@ if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
 
 # write the state for incrementals
 if state:
-    print 'Writing state'
+    if verbose:
+        print 'Writing state'
     f = open(state, 'w')
     pickle.dump(hgvers, f)
 
-- 
1.5.5.GIT
Stelian Pop· May 26, 2008, 14:33 UTC · re: Johannes Schindelin · lore

Re: [PATCH v2] hg-to-git: add --verbose option

Le lundi 26 mai 2008 à 14:20 +0100, Johannes Schindelin a écrit :
Show 5 quoted lines
> This patch adds an option to make hg-to-git quiet by default.  Note:
> it only suppresses those messages that would be printed when everything
> was up-to-date.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Stelian Pop <stelian@popies.net>
Thanks, 
-- 
Stelian Pop <stelian@popies.net>

← back to recent threads