{"thread":{"id":"34361","subject":"[PATCH 1/2] Git.pm: add new temp_is_locked function","startedAt":"2013-07-06T03:42:03Z","lastAt":"2013-07-07T00:11:48Z","messageCount":2,"participants":["Kyle McKay","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"222663","messageId":"D34E9C76-89B8-44E6-B364-C71B2FC2AC52@gmail.com","threadId":"34361","inReplyTo":null,"subject":"[PATCH 1/2] Git.pm: add new temp_is_locked function","fromName":"Kyle McKay","fromEmail":"mackyle@gmail.com","sentAt":"2013-07-06T03:42:03Z","receivedAt":"2013-07-06T03:42:03Z","isPatch":true,"sender":{"key":"mackyle@gmail.com","avatar":"https://avatars.githubusercontent.com/u/813346?v=4"},"body":"The temp_is_locked function can be used to determine whether\nor not a given name previously passed to temp_acquire is\ncurrently locked.\n\nSigned-off-by: Kyle J. McKay <mackyle@gmail.com>\n---\nperl/Git.pm | 17 ++++++++++++++++-\n1 file changed, 16 insertions(+), 1 deletion(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 7a252ef..5416b5a 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -61,7 +61,7 @@ require Exporter;\n                 remote_refs prompt\n                 get_tz_offset\n                 credential credential_read credential_write\n-                temp_acquire temp_release temp_reset temp_path);\n+                temp_acquire temp_is_locked temp_release temp_reset  \ntemp_path);\n\n\n=head1 DESCRIPTION\n@@ -1206,6 +1206,21 @@ sub temp_acquire {\n\t$temp_fd;\n}\n\n+=item temp_is_locked ( NAME )\n+\n+Returns true if the file mapped to C<NAME> is currently locked.\n+\n+If true is returned, an attempt to C<temp_acquire()> the same C<NAME>  \nwill\n+throw an error.\n+\n+=cut\n+\n+sub temp_is_locked {\n+\tmy ($self, $name) = _maybe_self(@_);\n+\tmy $temp_fd = \\$TEMP_FILEMAP{$name};\n+\tdefined $$temp_fd && $$temp_fd->opened && $TEMP_FILES{$$temp_fd} \n{locked};\n+}\n+\n=item temp_release ( NAME )\n\n=item temp_release ( FILEHANDLE )\n-- \n1.8.3\n"},{"id":"222677","messageId":"20130707001148.GD30132@google.com","threadId":"34361","inReplyTo":"D34E9C76-89B8-44E6-B364-C71B2FC2AC52@gmail.com","subject":"Re: [PATCH 1/2] Git.pm: add new temp_is_locked function","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-07-07T00:11:48Z","receivedAt":"2013-07-07T00:11:48Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nKyle McKay wrote:\n\n> The temp_is_locked function can be used to determine whether\n> or not a given name previously passed to temp_acquire is\n> currently locked.\n[...]\n> +=item temp_is_locked ( NAME )\n> +\n> +Returns true if the file mapped to C<NAME> is currently locked.\n> +\n> +If true is returned, an attempt to C<temp_acquire()> the same\n> C<NAME> will\n> +throw an error.\n\nLooks like this was line-wrapped somewhere in transit.\n\nMore importantly, it's not obvious from the above description what\nthis function will do.  What is a typical value of NAME?  Is it a\nfilename, an arbitrary string, a reference, or something else?  Is\nthis a way of checking if a file is flocked?  What is a typical way to\nuse this function?\n\nLooking more closely, it looks like this is factoring out the idiom\nfor checking if a name is already in use from the _temp_cache\nfunction.  Would it make sense for _temp_cache to call this helper?\n\nWhen is a caller expected to call this function?  What guarantees can\nthe caller rely on?  After a call to temp_acquire(NAME), will\ntemp_is_locked(NAME) always return true until temp_release(NAME) is\ncalled?  Does this only work within the context of a single process or\ncan locks persist beyond a process lifetime?  Do locks ever need to be\nbroken?\n\nI didn't spend a lot of time trying to find the answers to these\nquestions because I want to make sure that people using Git.pm in the\nfuture similarly do not have to spend a lot of time.  So hopefully a\ndocumentation change could fix this.\n\nThanks and hope that helps,\nJonathan\n"}]}