public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] GitSync.update: respect sync-depth (bug 552814)
@ 2016-07-14  8:38 Zac Medico
  2016-07-14 16:28 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
  0 siblings, 1 reply; 5+ messages in thread
From: Zac Medico @ 2016-07-14  8:38 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Fix updates to respect sync-depth (previously it was only respected
for clone operations). Since the default merge strategy typically
fails when the the depth is not unlimited, use `git fetch` followed
by `git reset --hard`.

X-Gentoo-Bug: 552814
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=552814
---
 pym/portage/sync/modules/git/git.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index 02eeb16..62c24f6 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -83,7 +83,21 @@ class GitSync(NewBase):
 			git_cmd_opts += " --quiet"
 		if self.repo.module_specific_options.get('sync-git-pull-extra-opts'):
 			git_cmd_opts += " %s" % self.repo.module_specific_options['sync-git-pull-extra-opts']
-		git_cmd = "%s pull%s" % (self.bin_command, git_cmd_opts)
+		if self.repo.sync_depth is None:
+			git_cmd = "%s pull%s" % (self.bin_command, git_cmd_opts)
+		else:
+			# Since the default merge strategy typically fails when
+			# the depth is not unlimited, use `git fetch` followed by
+			# `git reset --hard`.
+			remote_branch = portage._unicode_decode(
+				subprocess.check_output([self.bin_command, 'rev-parse',
+				'--abbrev-ref', '--symbolic-full-name', '@{upstream}'],
+				cwd=portage._unicode_encode(self.repo.location))).rstrip('\n')
+
+			git_cmd_opts += " --depth %d" % self.repo.sync_depth
+			git_cmd = "%s fetch %s%s" % (self.bin_command,
+				remote_branch.partition('/')[0], git_cmd_opts)
+
 		writemsg_level(git_cmd + "\n")
 
 		rev_cmd = [self.bin_command, "rev-list", "--max-count=1", "HEAD"]
@@ -93,6 +107,12 @@ class GitSync(NewBase):
 		exitcode = portage.process.spawn_bash("cd %s ; exec %s" % (
 				portage._shell_quote(self.repo.location), git_cmd),
 			**self.spawn_kwargs)
+
+		if exitcode == os.EX_OK and self.repo.sync_depth is not None:
+			exitcode = subprocess.call(
+				[self.bin_command, 'reset', '--hard', remote_branch],
+				cwd=portage._unicode_encode(self.repo.location))
+
 		if exitcode != os.EX_OK:
 			msg = "!!! git pull error in %s" % self.repo.location
 			self.logger(self.xterm_titles, msg)
-- 
2.7.4



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

* [gentoo-portage-dev] [PATCH v2] GitSync.update: respect sync-depth (bug 552814)
  2016-07-14  8:38 [gentoo-portage-dev] [PATCH] GitSync.update: respect sync-depth (bug 552814) Zac Medico
@ 2016-07-14 16:28 ` Zac Medico
  2016-07-14 17:08   ` Brian Dolbec
  0 siblings, 1 reply; 5+ messages in thread
From: Zac Medico @ 2016-07-14 16:28 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Fix updates to respect sync-depth (previously it was only respected
for clone operations). Since the default merge strategy typically
fails when the the depth is not unlimited, use `git fetch` followed
by `git reset --hard`.

X-Gentoo-Bug: 552814
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=552814
---
[PATCH v2] fixes the git reset call to use --quiet when appropriate

 pym/portage/sync/modules/git/git.py | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index 02eeb16..09257f3 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -79,11 +79,26 @@ class GitSync(NewBase):
 		'''
 
 		git_cmd_opts = ""
-		if self.settings.get("PORTAGE_QUIET") == "1":
+		quiet = self.settings.get("PORTAGE_QUIET") == "1"
+		if quiet:
 			git_cmd_opts += " --quiet"
 		if self.repo.module_specific_options.get('sync-git-pull-extra-opts'):
 			git_cmd_opts += " %s" % self.repo.module_specific_options['sync-git-pull-extra-opts']
-		git_cmd = "%s pull%s" % (self.bin_command, git_cmd_opts)
+		if self.repo.sync_depth is None:
+			git_cmd = "%s pull%s" % (self.bin_command, git_cmd_opts)
+		else:
+			# Since the default merge strategy typically fails when
+			# the depth is not unlimited, use `git fetch` followed by
+			# `git reset --hard`.
+			remote_branch = portage._unicode_decode(
+				subprocess.check_output([self.bin_command, 'rev-parse',
+				'--abbrev-ref', '--symbolic-full-name', '@{upstream}'],
+				cwd=portage._unicode_encode(self.repo.location))).rstrip('\n')
+
+			git_cmd_opts += " --depth %d" % self.repo.sync_depth
+			git_cmd = "%s fetch %s%s" % (self.bin_command,
+				remote_branch.partition('/')[0], git_cmd_opts)
+
 		writemsg_level(git_cmd + "\n")
 
 		rev_cmd = [self.bin_command, "rev-list", "--max-count=1", "HEAD"]
@@ -93,6 +108,14 @@ class GitSync(NewBase):
 		exitcode = portage.process.spawn_bash("cd %s ; exec %s" % (
 				portage._shell_quote(self.repo.location), git_cmd),
 			**self.spawn_kwargs)
+
+		if exitcode == os.EX_OK and self.repo.sync_depth is not None:
+			reset_cmd = [self.bin_command, 'reset', '--hard', remote_branch]
+			if quiet:
+				reset_cmd.append('--quiet')
+			exitcode = subprocess.call(reset_cmd,
+				cwd=portage._unicode_encode(self.repo.location))
+
 		if exitcode != os.EX_OK:
 			msg = "!!! git pull error in %s" % self.repo.location
 			self.logger(self.xterm_titles, msg)
-- 
2.7.4



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

* Re: [gentoo-portage-dev] [PATCH v2] GitSync.update: respect sync-depth (bug 552814)
  2016-07-14 16:28 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
@ 2016-07-14 17:08   ` Brian Dolbec
  2016-07-14 18:43     ` Zac Medico
  0 siblings, 1 reply; 5+ messages in thread
From: Brian Dolbec @ 2016-07-14 17:08 UTC (permalink / raw
  To: gentoo-portage-dev

On Thu, 14 Jul 2016 09:28:14 -0700
Zac Medico <zmedico@gentoo.org> wrote:

> Fix updates to respect sync-depth (previously it was only respected
> for clone operations). Since the default merge strategy typically
> fails when the the depth is not unlimited, use `git fetch` followed
> by `git reset --hard`.
> 
> X-Gentoo-Bug: 552814
> X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=552814
> ---
> [PATCH v2] fixes the git reset call to use --quiet when appropriate
> 
>  pym/portage/sync/modules/git/git.py | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/pym/portage/sync/modules/git/git.py
> b/pym/portage/sync/modules/git/git.py index 02eeb16..09257f3 100644
> --- a/pym/portage/sync/modules/git/git.py
> +++ b/pym/portage/sync/modules/git/git.py
> @@ -79,11 +79,26 @@ class GitSync(NewBase):
>  		'''
>  
>  		git_cmd_opts = ""
> -		if self.settings.get("PORTAGE_QUIET") == "1":
> +		quiet = self.settings.get("PORTAGE_QUIET") == "1"
> +		if quiet:
>  			git_cmd_opts += " --quiet"
>  		if
> self.repo.module_specific_options.get('sync-git-pull-extra-opts'):
> git_cmd_opts += " %s" %
> self.repo.module_specific_options['sync-git-pull-extra-opts']
> -		git_cmd = "%s pull%s" % (self.bin_command,
> git_cmd_opts)
> +		if self.repo.sync_depth is None:
> +			git_cmd = "%s pull%s" % (self.bin_command,
> git_cmd_opts)
> +		else:
> +			# Since the default merge strategy typically
> fails when
> +			# the depth is not unlimited, use `git
> fetch` followed by
> +			# `git reset --hard`.
> +			remote_branch = portage._unicode_decode(
> +
> subprocess.check_output([self.bin_command, 'rev-parse',
> +				'--abbrev-ref',
> '--symbolic-full-name', '@{upstream}'],
> +
> cwd=portage._unicode_encode(self.repo.location))).rstrip('\n') +
> +			git_cmd_opts += " --depth %d" %
> self.repo.sync_depth
> +			git_cmd = "%s fetch %s%s" %
> (self.bin_command,
> +				remote_branch.partition('/')[0],
> git_cmd_opts) +
>  		writemsg_level(git_cmd + "\n")
>  
>  		rev_cmd = [self.bin_command, "rev-list",
> "--max-count=1", "HEAD"] @@ -93,6 +108,14 @@ class GitSync(NewBase):
>  		exitcode = portage.process.spawn_bash("cd %s ; exec
> %s" % ( portage._shell_quote(self.repo.location), git_cmd),
>  			**self.spawn_kwargs)
> +
> +		if exitcode == os.EX_OK and self.repo.sync_depth is
> not None:
> +			reset_cmd = [self.bin_command, 'reset',
> '--hard', remote_branch]
> +			if quiet:
> +				reset_cmd.append('--quiet')
> +			exitcode = subprocess.call(reset_cmd,
> +
> cwd=portage._unicode_encode(self.repo.location)) +
>  		if exitcode != os.EX_OK:
>  			msg = "!!! git pull error in %s" %
> self.repo.location self.logger(self.xterm_titles, msg)

looks fine

-- 
Brian Dolbec <dolsen>



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

* Re: [gentoo-portage-dev] [PATCH v2] GitSync.update: respect sync-depth (bug 552814)
  2016-07-14 17:08   ` Brian Dolbec
@ 2016-07-14 18:43     ` Zac Medico
  2016-07-18 16:44       ` Zac Medico
  0 siblings, 1 reply; 5+ messages in thread
From: Zac Medico @ 2016-07-14 18:43 UTC (permalink / raw
  To: gentoo-portage-dev

On 07/14/2016 10:08 AM, Brian Dolbec wrote:
> looks fine

Pushed:

https://gitweb.gentoo.org/proj/portage.git/commit/?id=84413bb1dd9df322568ce25efc5b7854a43d03c7
-- 
Thanks,
Zac


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

* Re: [gentoo-portage-dev] [PATCH v2] GitSync.update: respect sync-depth (bug 552814)
  2016-07-14 18:43     ` Zac Medico
@ 2016-07-18 16:44       ` Zac Medico
  0 siblings, 0 replies; 5+ messages in thread
From: Zac Medico @ 2016-07-18 16:44 UTC (permalink / raw
  To: gentoo-portage-dev

On 07/14/2016 11:43 AM, Zac Medico wrote:
> On 07/14/2016 10:08 AM, Brian Dolbec wrote:
>> looks fine
> 
> Pushed:
> 
> https://gitweb.gentoo.org/proj/portage.git/commit/?id=84413bb1dd9df322568ce25efc5b7854a43d03c7
> 

Now optimized to use `git reset --merge`:

https://gitweb.gentoo.org/proj/portage.git/commit/?id=55aef9bf297ef8cbf29921acb454449d01313818
-- 
Thanks,
Zac


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

end of thread, other threads:[~2016-07-18 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-14  8:38 [gentoo-portage-dev] [PATCH] GitSync.update: respect sync-depth (bug 552814) Zac Medico
2016-07-14 16:28 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
2016-07-14 17:08   ` Brian Dolbec
2016-07-14 18:43     ` Zac Medico
2016-07-18 16:44       ` Zac Medico

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