git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Andrey Mazo <ahippo@yandex.ru>
Cc: "Philip.McGraw" <Philip.McGraw@bentley.com>,
	Luke Diamand <luke@diamand.org>,
	Lars Schneider <larsxschneider@gmail.com>,
	Andrey Mazo <ahippo@yandex.com>,
	git@vger.kernel.org, gitgitgadget@gmail.com
Subject: Re: [PATCH v2 1/1] git-p4: auto-delete named temporary file
Date: Tue, 27 Aug 2019 15:31:33 -0700	[thread overview]
Message-ID: <xmqq1rx62qbe.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <7e59b5cec2f267820feeeeb63a20814fe67d61e3.1566876175.git.ahippo@yandex.com> (Andrey Mazo's message of "Tue, 27 Aug 2019 06:43:58 +0300")

Andrey Mazo <ahippo@yandex.ru> writes:

> From: "Philip.McGraw" <Philip.McGraw@bentley.com>
>
> Avoid double-open exceptions on Windows platform when
> calculating for lfs compressed size threshold
> (git-p4.largeFileCompressedThreshold) comparisons.
>
> Take new approach using the NamedTemporaryFile()
> file-like object as input to the ZipFile() which
> auto-deletes after implicit close leaving with scope.
>
> Original code had double-open exception on Windows
> platform because file still open from NamedTemporaryFile()
> using generated filename instead of object.
>
> Thanks to Andrey for patiently suggesting several
> iterations on this change for avoiding exceptions!
>
> Also print error details after resulting IOError to make
> debugging cause of exception less mysterious when it has
> nothing to do with "git version recent enough."
>
> Signed-off-by: Philip.McGraw <Philip.McGraw@bentley.com>
> Reviewed-by: Andrey Mazo <ahippo@yandex.com>
> ---

Luke, does this look good?

I know Mazo is the only other contributor who has multiple commits
to git-p4.py in the past 2 years, to make Reviewed-by carry some
weight ;-) but as we have so small number of people touching this
script anyway, I'd rather see what the main contributor in the past
2 years thinks.

Thanks.

>  git-p4.py | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index c71a6832e2..33bdb14fd1 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1158,17 +1158,15 @@ def exceedsLargeFileThreshold(self, relPath, contents):
>          if gitConfigInt('git-p4.largeFileCompressedThreshold'):
>              contentsSize = sum(len(d) for d in contents)
>              if contentsSize <= gitConfigInt('git-p4.largeFileCompressedThreshold'):
>                  return False
>              contentTempFile = self.generateTempFile(contents)
> -            compressedContentFile = tempfile.NamedTemporaryFile(prefix='git-p4-large-file', delete=False)
> -            zf = zipfile.ZipFile(compressedContentFile.name, mode='w')
> -            zf.write(contentTempFile, compress_type=zipfile.ZIP_DEFLATED)
> -            zf.close()
> -            compressedContentsSize = zf.infolist()[0].compress_size
> +            compressedContentFile = tempfile.NamedTemporaryFile(prefix='git-p4-large-file', delete=True)
> +            with zipfile.ZipFile(compressedContentFile, mode='w') as zf:
> +                zf.write(contentTempFile, compress_type=zipfile.ZIP_DEFLATED)
> +                compressedContentsSize = zf.infolist()[0].compress_size
>              os.remove(contentTempFile)
> -            os.remove(compressedContentFile.name)
>              if compressedContentsSize > gitConfigInt('git-p4.largeFileCompressedThreshold'):
>                  return True
>          return False
>  
>      def addLargeFile(self, relPath):
> @@ -3512,12 +3510,13 @@ def importHeadRevision(self, revision):
>          details["time"] = res["time"]
>  
>          self.updateOptionDict(details)
>          try:
>              self.commit(details, self.extractFilesFromCommit(details), self.branch)
> -        except IOError:
> +        except IOError as err:
>              print("IO error with git fast-import. Is your git version recent enough?")
> +            print("IO error details: {}".format(err))
>              print(self.gitError.read())
>  
>      def openStreams(self):
>          self.importProcess = subprocess.Popen(["git", "fast-import"],
>                                                stdin=subprocess.PIPE,
>
> base-commit: 1feeaaf26bff51996f9f96c6dc41ca0f95ab5fc4
> Pull-Request: https://github.com/gitgitgadget/git/pull/303

  reply	other threads:[~2019-08-27 22:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-01 21:39 [PATCH 0/1] " Philip McGraw via GitGitGadget
2019-08-02  3:48 ` Andrey
2019-08-02 19:43 ` [PATCH v2 " Philip McGraw via GitGitGadget
2019-08-27  3:43   ` [PATCH v2 1/1] " Andrey Mazo
2019-08-27 22:31     ` Junio C Hamano [this message]
2019-08-28  8:34       ` Luke Diamand
     [not found]         ` <10209481570324845@myt6-4218ece6190d.qloud-c.yandex.net>
2019-10-06  2:43           ` Junio C Hamano
2019-08-26 13:51 ` [PATCH " Git Gadget
2019-08-26 16:39   ` Junio C Hamano
2019-08-28 12:25     ` Johannes Schindelin
2019-08-29  3:57       ` Junio C Hamano
2019-08-29 11:45         ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq1rx62qbe.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=Philip.McGraw@bentley.com \
    --cc=ahippo@yandex.com \
    --cc=ahippo@yandex.ru \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=larsxschneider@gmail.com \
    --cc=luke@diamand.org \
    --subject='Re: [PATCH v2 1/1] git-p4: auto-delete named temporary file' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git