* [PATCH] git-p4: fix fast import when empty commit is first
@ 2023-11-22 7:56 Alisha Kim via GitGitGadget
2023-11-23 1:57 ` Junio C Hamano
2023-11-24 6:14 ` [PATCH v2] " Alisha Kim via GitGitGadget
0 siblings, 2 replies; 4+ messages in thread
From: Alisha Kim via GitGitGadget @ 2023-11-22 7:56 UTC (permalink / raw)
To: git; +Cc: Alisha Kim, Alisha Kim
From: Alisha Kim <pril@pril.cc>
When executing p4 sync by specifying an excluded path, an empty commit
will be created if there is only a change in the excluded path in
revision.
If git-p4.keepEmptyCommits is turned off and an empty commit is the
first, fast-import will fail.
Signed-off-by: Alisha Kim <pril@pril.cc>
---
git-p4: fix fast import when empty commit is first
When executing p4 sync by specifying an excluded path, an empty commit
will be created if there is only a change in the excluded path in
revision. If git-p4.keepEmptyCommits is turned off and an empty commit
is the first, fast-import will fail.
The error log is as follows Ignoring revision 14035 as it would produce
an empty commit. fast-import failed: warning: Not updating
refs/heads/p4/master (new tip new commit hash does not contain parent
commit hash) fast-import statistics: ...
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1609%2Fdaebo01%2Fgit-p4-pr-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1609/daebo01/git-p4-pr-v1
Pull-Request: https://github.com/git/git/pull/1609
git-p4.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 0eb3bb4c47d..a61200e29e4 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3466,7 +3466,7 @@ class P4Sync(Command, P4UserMap):
if not files and not allow_empty:
print('Ignoring revision {0} as it would produce an empty commit.'
.format(details['change']))
- return
+ return False
self.gitStream.write("commit %s\n" % branch)
self.gitStream.write("mark :%s\n" % details["change"])
@@ -3533,6 +3533,8 @@ class P4Sync(Command, P4UserMap):
print("Tag %s does not match with change %s: file count is different."
% (labelDetails["label"], change))
+ return True
+
def getLabels(self):
"""Build a dictionary of changelists and labels, for "detect-labels"
option.
@@ -3876,10 +3878,12 @@ class P4Sync(Command, P4UserMap):
self.commit(description, filesForCommit, branch, parent)
else:
files = self.extractFilesFromCommit(description)
- self.commit(description, files, self.branch,
+ isCommitted = self.commit(description, files, self.branch,
self.initialParent)
# only needed once, to connect to the previous commit
- self.initialParent = ""
+ if isCommitted:
+ self.initialParent = ""
+
except IOError:
print(self.gitError.read())
sys.exit(1)
base-commit: cfb8a6e9a93adbe81efca66e6110c9b4d2e57169
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] git-p4: fix fast import when empty commit is first
2023-11-22 7:56 [PATCH] git-p4: fix fast import when empty commit is first Alisha Kim via GitGitGadget
@ 2023-11-23 1:57 ` Junio C Hamano
2023-11-24 6:55 ` Alisha Kim
2023-11-24 6:14 ` [PATCH v2] " Alisha Kim via GitGitGadget
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2023-11-23 1:57 UTC (permalink / raw)
To: Alisha Kim via GitGitGadget; +Cc: git, Alisha Kim
"Alisha Kim via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Alisha Kim <pril@pril.cc>
>
> When executing p4 sync by specifying an excluded path, an empty commit
> will be created if there is only a change in the excluded path in
> revision.
> If git-p4.keepEmptyCommits is turned off and an empty commit is the
> first, fast-import will fail.
The above describe under what condition a failure gets triggered,
but there is no description on what approach the proposed solution
takes. You could teach "fast-import" to deal with an empty commit
properly, you could ignore empty commits and not produce input for
the fast-import command, you could probably turn these initial empty
commits into non-empty commits by adding dummy contents, etc. We
want to see in our proposed log messages what solution was taken and
how the solution was designed to satisfy what requirements. This is
to help future developers who will have to change the code that is
given by this patch, so that their updates can still adhere to what
ever design criteria you had in working on this change [*].
Side note: Your solution might be to ignore empty commits
despite keepEmptyCommits option is set (as I said, you did not
describe it at all in the above, so this is a hypothetical
example). If the reason behind choosing that design were "I
just do not want it to fail---I do not care if the resulting
history coming out of fast-import is crappy (I lose the p4 CL
descriptions for these commits, even though the user wants to
keep them)", then future developers can safely "fix" your fix
here by turning the initial empty commits into non-empty ones by
adding fake contents.
> @@ -3876,10 +3878,12 @@ class P4Sync(Command, P4UserMap):
> self.commit(description, filesForCommit, branch, parent)
> else:
> files = self.extractFilesFromCommit(description)
> - self.commit(description, files, self.branch,
> + isCommitted = self.commit(description, files, self.branch,
> self.initialParent)
> # only needed once, to connect to the previous commit
> - self.initialParent = ""
> + if isCommitted:
> + self.initialParent = ""
"is" does not sound grammatically correct. "didCommit" (i.e., "we
made a commit"), "haveCommitted" (i.e., "we have made a commit")
might be more understandable.
> except IOError:
> print(self.gitError.read())
> sys.exit(1)
>
> base-commit: cfb8a6e9a93adbe81efca66e6110c9b4d2e57169
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git-p4: fix fast import when empty commit is first
2023-11-23 1:57 ` Junio C Hamano
@ 2023-11-24 6:55 ` Alisha Kim
0 siblings, 0 replies; 4+ messages in thread
From: Alisha Kim @ 2023-11-24 6:55 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Alisha Kim via GitGitGadget, git, Alisha Kim
On Thu, Nov 23, 2023 at 10:57 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Alisha Kim via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Alisha Kim <pril@pril.cc>
> >
> > When executing p4 sync by specifying an excluded path, an empty commit
> > will be created if there is only a change in the excluded path in
> > revision.
> > If git-p4.keepEmptyCommits is turned off and an empty commit is the
> > first, fast-import will fail.
>
> The above describe under what condition a failure gets triggered,
> but there is no description on what approach the proposed solution
> takes. You could teach "fast-import" to deal with an empty commit
> properly, you could ignore empty commits and not produce input for
> the fast-import command, you could probably turn these initial empty
> commits into non-empty commits by adding dummy contents, etc. We
> want to see in our proposed log messages what solution was taken and
> how the solution was designed to satisfy what requirements. This is
> to help future developers who will have to change the code that is
> given by this patch, so that their updates can still adhere to what
> ever design criteria you had in working on this change [*].
>
> Side note: Your solution might be to ignore empty commits
> despite keepEmptyCommits option is set (as I said, you did not
> describe it at all in the above, so this is a hypothetical
> example). If the reason behind choosing that design were "I
> just do not want it to fail---I do not care if the resulting
> history coming out of fast-import is crappy (I lose the p4 CL
> descriptions for these commits, even though the user wants to
> keep them)", then future developers can safely "fix" your fix
> here by turning the initial empty commits into non-empty ones by
> adding fake contents.
I've added explanations for the changes I suggested.
>
>
> > @@ -3876,10 +3878,12 @@ class P4Sync(Command, P4UserMap):
> > self.commit(description, filesForCommit, branch, parent)
> > else:
> > files = self.extractFilesFromCommit(description)
> > - self.commit(description, files, self.branch,
> > + isCommitted = self.commit(description, files, self.branch,
> > self.initialParent)
> > # only needed once, to connect to the previous commit
> > - self.initialParent = ""
> > + if isCommitted:
> > + self.initialParent = ""
>
> "is" does not sound grammatically correct. "didCommit" (i.e., "we
> made a commit"), "haveCommitted" (i.e., "we have made a commit")
> might be more understandable.
The problem with correct grammar that you mentioned has also been
changed. Thank you for your good comments.
>
>
> > except IOError:
> > print(self.gitError.read())
> > sys.exit(1)
> >
> > base-commit: cfb8a6e9a93adbe81efca66e6110c9b4d2e57169
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] git-p4: fix fast import when empty commit is first
2023-11-22 7:56 [PATCH] git-p4: fix fast import when empty commit is first Alisha Kim via GitGitGadget
2023-11-23 1:57 ` Junio C Hamano
@ 2023-11-24 6:14 ` Alisha Kim via GitGitGadget
1 sibling, 0 replies; 4+ messages in thread
From: Alisha Kim via GitGitGadget @ 2023-11-24 6:14 UTC (permalink / raw)
To: git; +Cc: Alisha Kim, Alisha Kim
From: Alisha Kim <pril@pril.cc>
When executing p4 sync by specifying an excluded path, an empty commit
will be created if there is only a change in the excluded path in
revision.
If git-p4.keepEmptyCommits is turned off and an empty commit is the
first, fast-import will fail. Change the return type of the commit
function from void to bool and return whether a commit has been
created. This failure was prevented by modifying initialParent
to be initialized only when a commit was actually created.
Signed-off-by: Alisha Kim <pril@pril.cc>
---
git-p4: fix fast import when empty commit is first
When executing p4 sync by specifying an excluded path, an empty commit
will be created if there is only a change in the excluded path in
revision. If git-p4.keepEmptyCommits is turned off and an empty commit
is the first, fast-import will fail. Change the return type of the
commit function from void to bool and return whether a commit has been
created. This failure was prevented by modifying initialParent to be
initialized only when a commit was actually created.
The error log is as follows Ignoring revision 14035 as it would produce
an empty commit. fast-import failed: warning: Not updating
refs/heads/p4/master (new tip new commit hash does not contain parent
commit hash) fast-import statistics: ...
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1609%2Fdaebo01%2Fgit-p4-pr-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1609/daebo01/git-p4-pr-v2
Pull-Request: https://github.com/git/git/pull/1609
Range-diff vs v1:
1: f7c4fa18c4c ! 1: 1de9ac6dbf8 git-p4: fix fast import when empty commit is first
@@ Commit message
will be created if there is only a change in the excluded path in
revision.
If git-p4.keepEmptyCommits is turned off and an empty commit is the
- first, fast-import will fail.
+ first, fast-import will fail. Change the return type of the commit
+ function from void to bool and return whether a commit has been
+ created. This failure was prevented by modifying initialParent
+ to be initialized only when a commit was actually created.
Signed-off-by: Alisha Kim <pril@pril.cc>
@@ git-p4.py: class P4Sync(Command, P4UserMap):
else:
files = self.extractFilesFromCommit(description)
- self.commit(description, files, self.branch,
-+ isCommitted = self.commit(description, files, self.branch,
++ haveCommitted = self.commit(description, files, self.branch,
self.initialParent)
# only needed once, to connect to the previous commit
- self.initialParent = ""
-+ if isCommitted:
++ if haveCommitted:
+ self.initialParent = ""
+
except IOError:
git-p4.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 0eb3bb4c47d..1e3c0e815f0 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3466,7 +3466,7 @@ class P4Sync(Command, P4UserMap):
if not files and not allow_empty:
print('Ignoring revision {0} as it would produce an empty commit.'
.format(details['change']))
- return
+ return False
self.gitStream.write("commit %s\n" % branch)
self.gitStream.write("mark :%s\n" % details["change"])
@@ -3533,6 +3533,8 @@ class P4Sync(Command, P4UserMap):
print("Tag %s does not match with change %s: file count is different."
% (labelDetails["label"], change))
+ return True
+
def getLabels(self):
"""Build a dictionary of changelists and labels, for "detect-labels"
option.
@@ -3876,10 +3878,12 @@ class P4Sync(Command, P4UserMap):
self.commit(description, filesForCommit, branch, parent)
else:
files = self.extractFilesFromCommit(description)
- self.commit(description, files, self.branch,
+ haveCommitted = self.commit(description, files, self.branch,
self.initialParent)
# only needed once, to connect to the previous commit
- self.initialParent = ""
+ if haveCommitted:
+ self.initialParent = ""
+
except IOError:
print(self.gitError.read())
sys.exit(1)
base-commit: cfb8a6e9a93adbe81efca66e6110c9b4d2e57169
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-24 6:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 7:56 [PATCH] git-p4: fix fast import when empty commit is first Alisha Kim via GitGitGadget
2023-11-23 1:57 ` Junio C Hamano
2023-11-24 6:55 ` Alisha Kim
2023-11-24 6:14 ` [PATCH v2] " Alisha Kim via GitGitGadget
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).