mirror of https://github.com/go-gitea/gitea.git
gitlab-like hash naming
This commit is contained in:
parent
be19fe48d7
commit
563e8b4ea9
|
@ -41,6 +41,10 @@ func List(l *list.List) chan interface{} {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Sha1(str string) string {
|
||||||
|
return EncodeSha1(str)
|
||||||
|
}
|
||||||
|
|
||||||
func ShortSha(sha1 string) string {
|
func ShortSha(sha1 string) string {
|
||||||
if len(sha1) == 40 {
|
if len(sha1) == 40 {
|
||||||
return sha1[:10]
|
return sha1[:10]
|
||||||
|
@ -160,6 +164,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
|
||||||
},
|
},
|
||||||
"DiffTypeToStr": DiffTypeToStr,
|
"DiffTypeToStr": DiffTypeToStr,
|
||||||
"DiffLineTypeToStr": DiffLineTypeToStr,
|
"DiffLineTypeToStr": DiffLineTypeToStr,
|
||||||
|
"Sha1": Sha1,
|
||||||
"ShortSha": ShortSha,
|
"ShortSha": ShortSha,
|
||||||
"Md5": EncodeMd5,
|
"Md5": EncodeMd5,
|
||||||
"ActionContent2Commits": ActionContent2Commits,
|
"ActionContent2Commits": ActionContent2Commits,
|
||||||
|
|
|
@ -209,14 +209,14 @@ var Gogs = {};
|
||||||
$list.parents('tr').removeClass('end-selected-line');
|
$list.parents('tr').removeClass('end-selected-line');
|
||||||
$list.parents('tr').find('td').removeClass('selected-line');
|
$list.parents('tr').find('td').removeClass('selected-line');
|
||||||
if ($from) {
|
if ($from) {
|
||||||
var expr = new RegExp(/diff-(\d+)L(\d+)/);
|
var expr = new RegExp(/diff-(\w+)([LR])(\d+)/);
|
||||||
var selectMatches = $select.attr('rel').match(expr)
|
var selectMatches = $select.attr('rel').match(expr)
|
||||||
var fromMatches = $from.attr('rel').match(expr)
|
var fromMatches = $from.attr('rel').match(expr)
|
||||||
var a = parseInt(selectMatches[2]);
|
var a = parseInt(selectMatches[3]);
|
||||||
var b = parseInt(fromMatches[2]);
|
var b = parseInt(fromMatches[3]);
|
||||||
var linesIntToStr = {};
|
var linesIntToStr = {};
|
||||||
linesIntToStr[a] = selectMatches[2];
|
linesIntToStr[a] = selectMatches[3];
|
||||||
linesIntToStr[b] = fromMatches[2];
|
linesIntToStr[b] = fromMatches[3];
|
||||||
|
|
||||||
var c;
|
var c;
|
||||||
if (a != b) {
|
if (a != b) {
|
||||||
|
@ -225,11 +225,11 @@ var Gogs = {};
|
||||||
a = b;
|
a = b;
|
||||||
b = c;
|
b = c;
|
||||||
}
|
}
|
||||||
$('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line');
|
$('[rel=diff-'+fromMatches[1] + fromMatches[2] + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line');
|
||||||
var $selectedLines = $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf();
|
var $selectedLines = $('[rel=diff-'+fromMatches[1]+selectMatches[2] + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf();
|
||||||
$selectedLines.find('td.lines-num > span').addClass('active')
|
$selectedLines.find('td.lines-num > span').addClass('active')
|
||||||
$selectedLines.find('td').addClass('selected-line');
|
$selectedLines.find('td').addClass('selected-line');
|
||||||
$.changeHash('#diff-'+fromMatches[1]+'L' + linesIntToStr[a] + '-L' + linesIntToStr[b]);
|
$.changeHash('#diff-'+fromMatches[1]+fromMatches[2] + linesIntToStr[a] + '-' + selectMatches[2] + + linesIntToStr[b]);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ var Gogs = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
$(window).on('hashchange', function (e) {
|
$(window).on('hashchange', function (e) {
|
||||||
var m = window.location.hash.match(/^#diff-(\d+)(L\d+)\-(L\d+)$/);
|
var m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)\-([LR]\d+)$/);
|
||||||
var $list = $('.code-diff td.lines-num > span');
|
var $list = $('.code-diff td.lines-num > span');
|
||||||
var $first;
|
var $first;
|
||||||
if (m) {
|
if (m) {
|
||||||
|
@ -271,7 +271,7 @@ var Gogs = {};
|
||||||
$("html, body").scrollTop($first.offset().top - 200);
|
$("html, body").scrollTop($first.offset().top - 200);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m = window.location.hash.match(/^#diff-(\d+)(L\d+)$/);
|
m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)$/);
|
||||||
if (m) {
|
if (m) {
|
||||||
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
|
$first = $list.filter('[rel=diff-' + m[1] + m[2] + ']');
|
||||||
selectRange($list, $first);
|
selectRange($list, $first);
|
||||||
|
|
|
@ -109,10 +109,10 @@
|
||||||
{{range $k, $line := $section.Lines}}
|
{{range $k, $line := $section.Lines}}
|
||||||
<tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$i}} ol-{{$i}}">
|
<tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$i}} ol-{{$i}}">
|
||||||
<td class="lines-num lines-num-old">
|
<td class="lines-num lines-num-old">
|
||||||
<span rel="diff-{{Add $i 1}}L{{$j}}{{$k}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
<span rel="{{if $line.LeftIdx}}diff-L{{Sha1 $file.Name}}{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="lines-num lines-num-new">
|
<td class="lines-num lines-num-new">
|
||||||
<span rel="diff-{{Add $i 1}}L{{$j}}{{$k}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="lines-code">
|
<td class="lines-code">
|
||||||
|
|
Loading…
Reference in New Issue