* [PATCH 1/2] Git.pm: add new temp_is_locked function
@ 2013-07-06 3:42 Kyle McKay
2013-07-07 0:11 ` Jonathan Nieder
0 siblings, 1 reply; 2+ messages in thread
From: Kyle McKay @ 2013-07-06 3:42 UTC (permalink / raw)
To: git; +Cc: David Rothenberger, Petr Baudis, Jonathan Nieder, Daniel Shahaf
The temp_is_locked function can be used to determine whether
or not a given name previously passed to temp_acquire is
currently locked.
Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
---
perl/Git.pm | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 7a252ef..5416b5a 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -61,7 +61,7 @@ require Exporter;
remote_refs prompt
get_tz_offset
credential credential_read credential_write
- temp_acquire temp_release temp_reset temp_path);
+ temp_acquire temp_is_locked temp_release temp_reset
temp_path);
=head1 DESCRIPTION
@@ -1206,6 +1206,21 @@ sub temp_acquire {
$temp_fd;
}
+=item temp_is_locked ( NAME )
+
+Returns true if the file mapped to C<NAME> is currently locked.
+
+If true is returned, an attempt to C<temp_acquire()> the same C<NAME>
will
+throw an error.
+
+=cut
+
+sub temp_is_locked {
+ my ($self, $name) = _maybe_self(@_);
+ my $temp_fd = \$TEMP_FILEMAP{$name};
+ defined $$temp_fd && $$temp_fd->opened && $TEMP_FILES{$$temp_fd}
{locked};
+}
+
=item temp_release ( NAME )
=item temp_release ( FILEHANDLE )
--
1.8.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/2] Git.pm: add new temp_is_locked function
2013-07-06 3:42 [PATCH 1/2] Git.pm: add new temp_is_locked function Kyle McKay
@ 2013-07-07 0:11 ` Jonathan Nieder
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Nieder @ 2013-07-07 0:11 UTC (permalink / raw)
To: Kyle McKay; +Cc: git, David Rothenberger, Petr Baudis, Daniel Shahaf
Hi,
Kyle McKay wrote:
> The temp_is_locked function can be used to determine whether
> or not a given name previously passed to temp_acquire is
> currently locked.
[...]
> +=item temp_is_locked ( NAME )
> +
> +Returns true if the file mapped to C<NAME> is currently locked.
> +
> +If true is returned, an attempt to C<temp_acquire()> the same
> C<NAME> will
> +throw an error.
Looks like this was line-wrapped somewhere in transit.
More importantly, it's not obvious from the above description what
this function will do. What is a typical value of NAME? Is it a
filename, an arbitrary string, a reference, or something else? Is
this a way of checking if a file is flocked? What is a typical way to
use this function?
Looking more closely, it looks like this is factoring out the idiom
for checking if a name is already in use from the _temp_cache
function. Would it make sense for _temp_cache to call this helper?
When is a caller expected to call this function? What guarantees can
the caller rely on? After a call to temp_acquire(NAME), will
temp_is_locked(NAME) always return true until temp_release(NAME) is
called? Does this only work within the context of a single process or
can locks persist beyond a process lifetime? Do locks ever need to be
broken?
I didn't spend a lot of time trying to find the answers to these
questions because I want to make sure that people using Git.pm in the
future similarly do not have to spend a lot of time. So hopefully a
documentation change could fix this.
Thanks and hope that helps,
Jonathan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-07-07 0:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-06 3:42 [PATCH 1/2] Git.pm: add new temp_is_locked function Kyle McKay
2013-07-07 0:11 ` Jonathan Nieder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).