From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:42
When `git clone` is asked to dissociate the repository from the
reference repository whose objects were used, it is quite possible that
the pack files need to be repacked. In that case, the pack files need to
be deleted that were originally hard-links to the reference repository's
pack files.
On platforms where a file cannot be deleted if another process still
holds a handle on it, we therefore need to take pains to release all
pack files and indexes before dissociating.
This fixes https://github.com/git-for-windows/git/issues/446
Signed-off-by: Johannes Schindelin <redacted>
---
builtin/clone.c | 9 ++++++++-
t/t5700-clone-reference.sh | 21 +++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
@@ -188,5 +188,26 @@ test_expect_success 'clone and dissociate from reference' 'test_must_failgit-CRfsck&&git-CSfsck'+test_expect_success'clone, dissociate from partial reference and repack''+rm-frPQR&&+gitinitP&&+(+cdP&&+test_commitone&&+gitrepack&&+test_committwo&&+gitrepack+)&&+gitclone--barePQ&&+(+cdP&&+gitcheckout-bsecond&&+test_committhree&&+gitrepack+)&&+gitclone--bare--dissociate--reference=PQR&&+lsR/objects/pack/*.pack>packs.txt&&+test_line_count=1packs.txt+' test_done
From: Max Kirillov <hidden> Date: 2016-06-15 23:06:44
On Mon, Sep 28, 2015 at 09:44:57PM +0200, Johannes Schindelin wrote:
When `git clone` is asked to dissociate the repository from the
reference repository whose objects were used, it is quite possible that
the pack files need to be repacked. In that case, the pack files need to
be deleted that were originally hard-links to the reference repository's
pack files.
Hello. For 1.9.* I used to have some hack for closing files
also. The case was to allow scheduled git gc to remove packs
even if I forgot to quit some less in some console.
quoted hunk
On platforms where a file cannot be deleted if another process still
holds a handle on it, we therefore need to take pains to release all
pack files and indexes before dissociating.
This fixes https://github.com/git-for-windows/git/issues/446
Signed-off-by: Johannes Schindelin <redacted>
---
builtin/clone.c | 9 ++++++++-
t/t5700-clone-reference.sh | 21 +++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
This does not seem to close handles to the pack files
themseves, does Windows still allow removing the files? I
probably did not tried that, because I started from handles,
and discovered mapped files only later.
@@ -188,5 +188,26 @@ test_expect_success 'clone and dissociate from reference' 'test_must_failgit-CRfsck&&git-CSfsck'+test_expect_success'clone, dissociate from partial reference and repack''+rm-frPQR&&+gitinitP&&+(+cdP&&+test_commitone&&+gitrepack&&+test_committwo&&+gitrepack+)&&+gitclone--barePQ&&+(+cdP&&+gitcheckout-bsecond&&+test_committhree&&+gitrepack+)&&+gitclone--bare--dissociate--reference=PQR&&+lsR/objects/pack/*.pack>packs.txt&&+test_line_count=1packs.txt+'
Unless it goes very lowlevel like running lsof of readin
proc testing this should always pass on Linux, even if the
issue is not fixed, maybe should be a conditional for
Windows only?
test_done
--
2.5.3.windows.1.3.gc322723
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Max Kirillov <hidden> Date: 2016-06-15 23:06:44
On Wed, Sep 30, 2015 at 10:28:14PM +0300, Max Kirillov wrote:
On Mon, Sep 28, 2015 at 09:44:57PM +0200, Johannes Schindelin wrote:
quoted
- if (option_dissociate)
+ if (option_dissociate) {
+ struct packed_git *p;
+
+ for (p = packed_git; p; p = p->next) {
+ close_pack_windows(p);
+ close_pack_index(p);
+ }
dissociate_from_references();
+ }
This does not seem to close handles to the pack files
themseves, does Windows still allow removing the files? I
probably did not tried that, because I started from handles,
and discovered mapped files only later.
Apparently, pack file is closed just after mapping if it's
smaller than core.packedGitWindowSize. Could it be the
reason that this patch worked in you test case?
--
Max
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
Hi Max,
On 2015-10-01 06:39, Max Kirillov wrote:
On Wed, Sep 30, 2015 at 10:28:14PM +0300, Max Kirillov wrote:
quoted
On Mon, Sep 28, 2015 at 09:44:57PM +0200, Johannes Schindelin wrote:
quoted
- if (option_dissociate)
+ if (option_dissociate) {
+ struct packed_git *p;
+
+ for (p = packed_git; p; p = p->next) {
+ close_pack_windows(p);
+ close_pack_index(p);
+ }
dissociate_from_references();
+ }
quoted
This does not seem to close handles to the pack files
themseves, does Windows still allow removing the files? I
probably did not tried that, because I started from handles,
and discovered mapped files only later.
Apparently, pack file is closed just after mapping if it's
smaller than core.packedGitWindowSize. Could it be the
reason that this patch worked in you test case?
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
This is version 2, split into multiple commits for easier digestion.
Max, I hope that this helps also your use case!
Johannes Schindelin (4):
Demonstrate a Windows file locking issue with `git clone --dissociate`
Consolidate code to close a pack's file descriptor
Add a function to release all packs
clone --dissociate: avoid locking pack files
builtin/clone.c | 4 +++-
cache.h | 1 +
sha1_file.c | 56 ++++++++++++++++++++++++++++------------------
t/t5700-clone-reference.sh | 21 +++++++++++++++++
4 files changed, 59 insertions(+), 23 deletions(-)
--
2.5.3.windows.1.3.gc322723
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
On Windows, dissociating from a reference can fail very easily due to
pack files that are still in use when they want to be removed.
Signed-off-by: Johannes Schindelin <redacted>
---
t/t5700-clone-reference.sh | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
@@ -188,5 +188,26 @@ test_expect_success 'clone and dissociate from reference' 'test_must_failgit-CRfsck&&git-CSfsck'+test_expect_failureMINGW'clone, dissociate from partial reference and repack''+rm-frPQR&&+gitinitP&&+(+cdP&&+test_commitone&&+gitrepack&&+test_committwo&&+gitrepack+)&&+gitclone--barePQ&&+(+cdP&&+gitcheckout-bsecond&&+test_committhree&&+gitrepack+)&&+gitclone--bare--dissociate--reference=PQR&&+lsR/objects/pack/*.pack>packs.txt&&+test_line_count=1packs.txt+' test_done
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
There was a lot of repeated code to close the file descriptor of
a given pack. Let's just refactor this code into a single function.
Signed-off-by: Johannes Schindelin <redacted>
---
sha1_file.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
On Windows, files that are in use cannot be removed or renamed. That
means that we have to release pack files when we are about to, say,
repack them. Let's introduce a convenient function to close them
pack files.
While at it, we consolidate the close windows/close fd/close index
stanza in `free_pack_by_name()` into the `close_pack()` function that
is used by the new `close_all_packs()` function to avoid repeated code.
Signed-off-by: Johannes Schindelin <redacted>
---
cache.h | 1 +
sha1_file.c | 20 +++++++++++++++++---
2 files changed, 18 insertions(+), 3 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
When `git clone` is asked to dissociate the repository from the
reference repository whose objects were used, it is quite possible that
the pack files need to be repacked. In that case, the pack files need to
be deleted that were originally hard-links to the reference repository's
pack files.
On platforms where a file cannot be deleted if another process still
holds a handle on it, we therefore need to take pains to release all
pack files and indexes before dissociating.
This fixes https://github.com/git-for-windows/git/issues/446
The test case to demonstrate the breakage technically does not need to
be run on Linux or MacOSX. It won't hurt, either, though.
Signed-off-by: Johannes Schindelin <redacted>
---
builtin/clone.c | 4 +++-
t/t5700-clone-reference.sh | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
@@ -188,7 +188,7 @@ test_expect_success 'clone and dissociate from reference' 'test_must_failgit-CRfsck&&git-CSfsck'-test_expect_failureMINGW'clone, dissociate from partial reference and repack''+test_expect_success'clone, dissociate from partial reference and repack''rm-frPQR&&gitinitP&&(
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
This is version 3, adding that BUG! message if do_not_close was set.
Max, I still hope that this patch series helps also your use case!
Interdiff below the diffstat.
Johannes Schindelin (4):
Demonstrate a Windows file locking issue with `git clone --dissociate`
Consolidate code to close a pack's file descriptor
Add a function to release all packs
clone --dissociate: avoid locking pack files
builtin/clone.c | 4 +++-
cache.h | 1 +
sha1_file.c | 59 +++++++++++++++++++++++++++++-----------------
t/t5700-clone-reference.sh | 21 +++++++++++++++++
4 files changed, 62 insertions(+), 23 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
On Windows, dissociating from a reference can fail very easily due to
pack files that are still in use when they want to be removed.
Signed-off-by: Johannes Schindelin <redacted>
---
t/t5700-clone-reference.sh | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
@@ -188,5 +188,26 @@ test_expect_success 'clone and dissociate from reference' 'test_must_failgit-CRfsck&&git-CSfsck'+test_expect_failureMINGW'clone, dissociate from partial reference and repack''+rm-frPQR&&+gitinitP&&+(+cdP&&+test_commitone&&+gitrepack&&+test_committwo&&+gitrepack+)&&+gitclone--barePQ&&+(+cdP&&+gitcheckout-bsecond&&+test_committhree&&+gitrepack+)&&+gitclone--bare--dissociate--reference=PQR&&+lsR/objects/pack/*.pack>packs.txt&&+test_line_count=1packs.txt+' test_done
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
There was a lot of repeated code to close the file descriptor of
a given pack. Let's just refactor this code into a single function.
Signed-off-by: Johannes Schindelin <redacted>
---
sha1_file.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
On Windows, files that are in use cannot be removed or renamed. That
means that we have to release pack files when we are about to, say,
repack them. Let's introduce a convenient function to close them
pack files.
While at it, we consolidate the close windows/close fd/close index
stanza in `free_pack_by_name()` into the `close_pack()` function that
is used by the new `close_all_packs()` function to avoid repeated code.
Signed-off-by: Johannes Schindelin <redacted>
---
cache.h | 1 +
sha1_file.c | 23 ++++++++++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
@@ -798,6 +798,25 @@ static int close_pack_fd(struct packed_git *p)return1;}+staticvoidclose_pack(structpacked_git*p)+{+close_pack_windows(p);+close_pack_fd(p);+close_pack_index(p);+}++voidclose_all_packs(void)+{+structpacked_git*p;++for(p=packed_git;p;p=p->next)+if(p->do_not_close)+die("BUG! Want to close pack marked 'do-not-close'");+else+close_pack(p);+}++/**TheLRUpackistheonewiththeoldestMRUwindow,preferringpacks*withnousedwindows,ortheoldestmtimeifithasnowindowsallocated.
From: Johannes Schindelin <hidden> Date: 2016-06-15 23:06:46
When `git clone` is asked to dissociate the repository from the
reference repository whose objects were used, it is quite possible that
the pack files need to be repacked. In that case, the pack files need to
be deleted that were originally hard-links to the reference repository's
pack files.
On platforms where a file cannot be deleted if another process still
holds a handle on it, we therefore need to take pains to release all
pack files and indexes before dissociating.
This fixes https://github.com/git-for-windows/git/issues/446
The test case to demonstrate the breakage technically does not need to
be run on Linux or MacOSX. It won't hurt, either, though.
Signed-off-by: Johannes Schindelin <redacted>
---
builtin/clone.c | 4 +++-
t/t5700-clone-reference.sh | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
@@ -188,7 +188,7 @@ test_expect_success 'clone and dissociate from reference' 'test_must_failgit-CRfsck&&git-CSfsck'-test_expect_failureMINGW'clone, dissociate from partial reference and repack''+test_expect_success'clone, dissociate from partial reference and repack''rm-frPQR&&gitinitP&&(
From: Max Kirillov <hidden> Date: 2016-06-15 23:06:49
On Tue, Oct 06, 2015 at 03:17:36PM +0200, Johannes Schindelin wrote:
This is version 3, adding that BUG! message if do_not_close was set.
Max, I still hope that this patch series helps also your use case!
Thanks, this mostly makes gone one of my commits. I only
need to invoke the function after builtin is done. And maybe
spend some time to check that dies do not happen.
The other one with cloexec I think I will still need.
It migh take some time before I return to it.
--
Max