-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrated Repository will show modifications when possible #17191
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,14 @@ | |
package git | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
|
@@ -188,6 +193,8 @@ func GetDiffShortStat(repoPath string, args ...string) (numFiles, totalAdditions | |
var shortStatFormat = regexp.MustCompile( | ||
`\s*(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?`) | ||
|
||
var patchCommits = regexp.MustCompile(`^From\s(\w+)\s`) | ||
|
||
func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int, err error) { | ||
if len(stdout) == 0 || stdout == "\n" { | ||
return 0, 0, 0, nil | ||
|
@@ -267,3 +274,57 @@ func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) err | |
} | ||
return err | ||
} | ||
|
||
// ReadPullHead will fetch a pull ref if possible or return an error | ||
func (repo *Repository) ReadPullHead(prID int64) (commitSHA string, err error) { | ||
headPath := fmt.Sprintf("refs/pull/%d/head", prID) | ||
fullHeadPath := filepath.Join(repo.Path, headPath) | ||
loadHead, err := os.Open(fullHeadPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer loadHead.Close() | ||
// Read only the first line of the patch - usually it contains the first commit made in patch | ||
scanner := bufio.NewScanner(loadHead) | ||
scanner.Scan() | ||
commitHead := scanner.Text() | ||
if len(commitHead) != 40 { | ||
return "", errors.New("head file doesn't contain valid commit ID") | ||
} | ||
return commitHead, nil | ||
} | ||
|
||
// ReadPatchCommit will check if a diff patch exists and return stats | ||
func (repo *Repository) ReadPatchCommit(prID int64) (commitSHA string, err error) { | ||
// Migrated repositories download patches to "pulls" location | ||
patchFile := fmt.Sprintf("pulls/%d.patch", prID) | ||
loadPatch, err := os.Open(filepath.Join(repo.Path, patchFile)) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer loadPatch.Close() | ||
// Read only the first line of the patch - usually it contains the first commit made in patch | ||
scanner := bufio.NewScanner(loadPatch) | ||
scanner.Scan() | ||
// Parse the Patch stats, sometimes Migration returns a 404 for the patch file | ||
commitSHAGroups := patchCommits.FindStringSubmatch(scanner.Text()) | ||
if len(commitSHAGroups) != 0 { | ||
commitSHA = commitSHAGroups[1] | ||
} else { | ||
return "", errors.New("patch file doesn't contain valid commit ID") | ||
} | ||
return commitSHA, nil | ||
} | ||
|
||
// WritePullHead will populate a PR head retrieved from patch file | ||
func (repo *Repository) WritePullHead(prID int64, commitSHA string) error { | ||
headPath := fmt.Sprintf("refs/pull/%d", prID) | ||
fullHeadPath := filepath.Join(repo.Path, headPath) | ||
// Create missing directory just in case | ||
if err := os.MkdirAll(fullHeadPath, os.ModePerm); err != nil { | ||
return err | ||
} | ||
commitBytes := []byte(commitSHA) | ||
pullPath := filepath.Join(fullHeadPath, "head") | ||
return ioutil.WriteFile(pullPath, commitBytes, os.ModePerm) | ||
} | ||
Comment on lines
+319
to
+330
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same again! Don't write to git's references directly yourself! You should have used git update-ref here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have been simply: headRef := fmt.Sprintf(PullPrefix+"%d/head", prID)
_, err := NewCommandContext(repo.Ctx, "update-ref", headRef, commitSHA).RunInDir(repo.Path)
return err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
From 6e8e2a6f9efd71dbe6917816343ed8415ad696c3 Mon Sep 17 00:00:00 2001 | ||
From: 99rgosse <renaud@mycompany.com> | ||
Date: Fri, 26 Mar 2021 12:44:22 +0000 | ||
Subject: [PATCH] Update gitea_import_actions.py | ||
|
||
--- | ||
gitea_import_actions.py | 6 +++--- | ||
1 file changed, 3 insertions(+), 3 deletions(-) | ||
|
||
diff --git a/gitea_import_actions.py b/gitea_import_actions.py | ||
index f0d72cd..7b31963 100644 | ||
--- a/gitea_import_actions.py | ||
+++ b/gitea_import_actions.py | ||
@@ -3,14 +3,14 @@ | ||
# git log --pretty=format:'%H,%at,%s' --date=default > /tmp/commit.log | ||
# to get the commits logfile for a repository | ||
|
||
-import mysql.connector as mariadb | ||
+import psycopg2 | ||
|
||
# set the following variables to fit your need... | ||
USERID = 1 | ||
REPOID = 1 | ||
BRANCH = "master" | ||
|
||
-mydb = mariadb.connect( | ||
+mydb = psycopg2.connect( | ||
host="localhost", | ||
user="user", | ||
passwd="password", | ||
@@ -31,4 +31,4 @@ with open("/tmp/commit.log") as f: | ||
|
||
mydb.commit() | ||
|
||
-print("actions inserted.") | ||
\ No newline at end of file | ||
+print("actions inserted.") | ||
-- | ||
GitLab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO!
This will break as soon as references are packed into files!
We have git.GetRefCommitID, we have (*git.Repository).GetRefCommitID
You should use the functionality that we have already written for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been: