public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] git sync: silence 'git rev-parse' errors
@ 2015-01-17 12:28 Michał Górny
  2015-01-17 22:07 ` Zac Medico
  0 siblings, 1 reply; 6+ messages in thread
From: Michał Górny @ 2015-01-17 12:28 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

Discard the git-rev-parse error output to avoid 'fatal: Not a git
repository [...]' errors when checking whether the repository exists.
---
 pym/portage/sync/modules/git/git.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index b97d501..02da037 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -36,7 +36,7 @@ class GitSync(SyncBase):
 
 		if not os.path.exists(self.repo.location):
 			return False
-		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
+		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse 2>/dev/null" %\
 			(portage._shell_quote(self.repo.location),),
 			**portage._native_kwargs(self.spawn_kwargs))
 		if exitcode == 128:
-- 
2.2.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] git sync: silence 'git rev-parse' errors
  2015-01-17 12:28 [gentoo-portage-dev] [PATCH] git sync: silence 'git rev-parse' errors Michał Górny
@ 2015-01-17 22:07 ` Zac Medico
  2015-01-18  0:31   ` Michał Górny
  2015-01-18 10:34   ` [gentoo-portage-dev] [PATCH v2] git sync: replace 'git rev-parse' with safer '.git' check Michał Górny
  0 siblings, 2 replies; 6+ messages in thread
From: Zac Medico @ 2015-01-17 22:07 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

On 01/17/2015 04:28 AM, Michał Górny wrote:
> Discard the git-rev-parse error output to avoid 'fatal: Not a git
> repository [...]' errors when checking whether the repository exists.
> ---
>  pym/portage/sync/modules/git/git.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
> index b97d501..02da037 100644
> --- a/pym/portage/sync/modules/git/git.py
> +++ b/pym/portage/sync/modules/git/git.py
> @@ -36,7 +36,7 @@ class GitSync(SyncBase):
>  
>  		if not os.path.exists(self.repo.location):
>  			return False
> -		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
> +		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse 2>/dev/null" %\
>  			(portage._shell_quote(self.repo.location),),
>  			**portage._native_kwargs(self.spawn_kwargs))
>  		if exitcode == 128:
> 

Why don't we just skip the git rev-parse call entirely, if not
os.path.isdir(os.path.join(self.repo.location, ".git"))?
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] git sync: silence 'git rev-parse' errors
  2015-01-17 22:07 ` Zac Medico
@ 2015-01-18  0:31   ` Michał Górny
  2015-01-18  0:52     ` Zac Medico
  2015-01-18 10:34   ` [gentoo-portage-dev] [PATCH v2] git sync: replace 'git rev-parse' with safer '.git' check Michał Górny
  1 sibling, 1 reply; 6+ messages in thread
From: Michał Górny @ 2015-01-18  0:31 UTC (permalink / raw
  To: Zac Medico; +Cc: gentoo-portage-dev

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

Dnia 2015-01-17, o godz. 14:07:46
Zac Medico <zmedico@gentoo.org> napisał(a):

> On 01/17/2015 04:28 AM, Michał Górny wrote:
> > Discard the git-rev-parse error output to avoid 'fatal: Not a git
> > repository [...]' errors when checking whether the repository exists.
> > ---
> >  pym/portage/sync/modules/git/git.py | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
> > index b97d501..02da037 100644
> > --- a/pym/portage/sync/modules/git/git.py
> > +++ b/pym/portage/sync/modules/git/git.py
> > @@ -36,7 +36,7 @@ class GitSync(SyncBase):
> >  
> >  		if not os.path.exists(self.repo.location):
> >  			return False
> > -		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
> > +		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse 2>/dev/null" %\
> >  			(portage._shell_quote(self.repo.location),),
> >  			**portage._native_kwargs(self.spawn_kwargs))
> >  		if exitcode == 128:
> > 
> 
> Why don't we just skip the git rev-parse call entirely, if not
> os.path.isdir(os.path.join(self.repo.location, ".git"))?

I don't know ;). I guess the current magic is more 'correct', i.e.
distinguishes broken repo. Of course, it all will probably fall apart
if it's broken but...!

-- 
Best regards,
Michał Górny

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 949 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] git sync: silence 'git rev-parse' errors
  2015-01-18  0:31   ` Michał Górny
@ 2015-01-18  0:52     ` Zac Medico
  0 siblings, 0 replies; 6+ messages in thread
From: Zac Medico @ 2015-01-18  0:52 UTC (permalink / raw
  To: Michał Górny, Zac Medico; +Cc: gentoo-portage-dev

On 01/17/2015 04:31 PM, Michał Górny wrote:
> Dnia 2015-01-17, o godz. 14:07:46
> Zac Medico <zmedico@gentoo.org> napisał(a):
> 
>> On 01/17/2015 04:28 AM, Michał Górny wrote:
>>> Discard the git-rev-parse error output to avoid 'fatal: Not a git
>>> repository [...]' errors when checking whether the repository exists.
>>> ---
>>>  pym/portage/sync/modules/git/git.py | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
>>> index b97d501..02da037 100644
>>> --- a/pym/portage/sync/modules/git/git.py
>>> +++ b/pym/portage/sync/modules/git/git.py
>>> @@ -36,7 +36,7 @@ class GitSync(SyncBase):
>>>  
>>>  		if not os.path.exists(self.repo.location):
>>>  			return False
>>> -		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
>>> +		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse 2>/dev/null" %\
>>>  			(portage._shell_quote(self.repo.location),),
>>>  			**portage._native_kwargs(self.spawn_kwargs))
>>>  		if exitcode == 128:
>>>
>>
>> Why don't we just skip the git rev-parse call entirely, if not
>> os.path.isdir(os.path.join(self.repo.location, ".git"))?
> 
> I don't know ;). I guess the current magic is more 'correct', i.e.
> distinguishes broken repo. Of course, it all will probably fall apart
> if it's broken but...!

Well, looking at the git-rev-parse man page, I'm wondering if it's an
"undocumented feature" that it works without any arguments. Maybe we
should use something like this instead:

[ -z "$(git rev-parse --show-prefix 2>/dev/null || echo fail)" ]

This will only return 0 if the current working directory is a valid git
repo (versus a parent directory).
-- 
Thanks,
Zac


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gentoo-portage-dev] [PATCH v2] git sync: replace 'git rev-parse' with safer '.git' check
  2015-01-17 22:07 ` Zac Medico
  2015-01-18  0:31   ` Michał Górny
@ 2015-01-18 10:34   ` Michał Górny
  2015-01-18 16:48     ` Brian Dolbec
  1 sibling, 1 reply; 6+ messages in thread
From: Michał Górny @ 2015-01-18 10:34 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

The 'git rev-parse' could succeed if one of the parent directories
contained a git repository, and it also had unwanted error output.
Instead, just check whether the '.git' directory exists.
---
 pym/portage/sync/modules/git/git.py | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index d4f2cc1..c5c569e 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -29,19 +29,7 @@ class GitSync(SyncBase):
 
 	def exists(self, **kwargs):
 		'''Tests whether the repo actually exists'''
-		if kwargs:
-			self._kwargs(kwargs)
-		elif not self.repo:
-			return False
-
-		if not os.path.exists(self.repo.location):
-			return False
-		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
-			(portage._shell_quote(self.repo.location),),
-			**portage._native_kwargs(self.spawn_kwargs))
-		if exitcode == 128:
-			return False
-		return True
+		return os.path.exists(os.path.join(self.repo.location, '.git'))
 
 
 	def new(self, **kwargs):
-- 
2.2.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] git sync: replace 'git rev-parse' with safer '.git' check
  2015-01-18 10:34   ` [gentoo-portage-dev] [PATCH v2] git sync: replace 'git rev-parse' with safer '.git' check Michał Górny
@ 2015-01-18 16:48     ` Brian Dolbec
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dolbec @ 2015-01-18 16:48 UTC (permalink / raw
  To: gentoo-portage-dev

On Sun, 18 Jan 2015 11:34:24 +0100
Michał Górny <mgorny@gentoo.org> wrote:

> The 'git rev-parse' could succeed if one of the parent directories
> contained a git repository, and it also had unwanted error output.
> Instead, just check whether the '.git' directory exists.
> ---
>  pym/portage/sync/modules/git/git.py | 14 +-------------
>  1 file changed, 1 insertion(+), 13 deletions(-)
> 
>

Looks good. Thanks.
-- 
Brian Dolbec <dolsen>



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-18 16:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-17 12:28 [gentoo-portage-dev] [PATCH] git sync: silence 'git rev-parse' errors Michał Górny
2015-01-17 22:07 ` Zac Medico
2015-01-18  0:31   ` Michał Górny
2015-01-18  0:52     ` Zac Medico
2015-01-18 10:34   ` [gentoo-portage-dev] [PATCH v2] git sync: replace 'git rev-parse' with safer '.git' check Michał Górny
2015-01-18 16:48     ` Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox